feat: check invitation code
This commit is contained in:
@@ -367,8 +367,7 @@ async def register(data: RegisterUser) -> JSONResponse:
|
|||||||
if data.email and not is_valid_email_address(data.email):
|
if data.email and not is_valid_email_address(data.email):
|
||||||
raise HTTPException(HTTPStatus.BAD_REQUEST, "Invalid email.")
|
raise HTTPException(HTTPStatus.BAD_REQUEST, "Invalid email.")
|
||||||
|
|
||||||
if not await check_register_activation_settings(data):
|
await check_register_activation_settings(data)
|
||||||
raise HTTPException(HTTPStatus.FORBIDDEN, "User activation failed.")
|
|
||||||
|
|
||||||
account = Account(
|
account = Account(
|
||||||
id=uuid4().hex,
|
id=uuid4().hex,
|
||||||
@@ -380,22 +379,23 @@ async def register(data: RegisterUser) -> JSONResponse:
|
|||||||
return _auth_success_response(account.username, account.id, account.email)
|
return _auth_success_response(account.username, account.id, account.email)
|
||||||
|
|
||||||
|
|
||||||
async def check_register_activation_settings(data: RegisterUser) -> bool:
|
async def check_register_activation_settings(data: RegisterUser):
|
||||||
if not settings.lnbits_require_user_activation:
|
if not settings.lnbits_require_user_activation:
|
||||||
return True
|
return None
|
||||||
if settings.lnbits_user_activation_by_invitation_code and data.invitation_code:
|
if settings.lnbits_user_activation_by_invitation_code and data.invitation_code:
|
||||||
code = data.invitation_code.strip()
|
code = data.invitation_code.strip()
|
||||||
if code == settings.lnbits_register_reusable_activation_code:
|
if code == settings.lnbits_register_reusable_activation_code:
|
||||||
return True
|
return None
|
||||||
if code in settings.lnbits_register_one_time_activation_codes:
|
if code in settings.lnbits_register_one_time_activation_codes:
|
||||||
settings.lnbits_register_one_time_activation_codes.remove(code)
|
settings.lnbits_register_one_time_activation_codes.remove(code)
|
||||||
await set_settings_field(
|
await set_settings_field(
|
||||||
"lnbits_register_one_time_activation_codes",
|
"lnbits_register_one_time_activation_codes",
|
||||||
settings.lnbits_register_one_time_activation_codes,
|
settings.lnbits_register_one_time_activation_codes,
|
||||||
)
|
)
|
||||||
return True
|
return None
|
||||||
|
raise ValueError("Invalid invitation code.")
|
||||||
|
|
||||||
return False
|
raise ValueError("No activation method provided.")
|
||||||
|
|
||||||
|
|
||||||
@auth_router.put("/pubkey")
|
@auth_router.put("/pubkey")
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ window._lnbitsApi = {
|
|||||||
name: name
|
name: name
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
register(username, email, password, password_repeat) {
|
register(username, email, password, password_repeat, invitation_code) {
|
||||||
return axios({
|
return axios({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/api/v1/auth/register',
|
url: '/api/v1/auth/register',
|
||||||
@@ -74,7 +74,8 @@ window._lnbitsApi = {
|
|||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
password_repeat
|
password_repeat,
|
||||||
|
invitation_code
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -432,6 +432,7 @@ window.app.component('username-password', {
|
|||||||
username: String,
|
username: String,
|
||||||
password_1: String,
|
password_1: String,
|
||||||
password_2: String,
|
password_2: String,
|
||||||
|
invitationCode: String,
|
||||||
resetKey: String
|
resetKey: String
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -449,7 +450,7 @@ window.app.component('username-password', {
|
|||||||
reset_key: this.resetKey,
|
reset_key: this.resetKey,
|
||||||
confirmationMethod: 'code',
|
confirmationMethod: 'code',
|
||||||
confirmationEmail: '',
|
confirmationEmail: '',
|
||||||
confirmationCode: '',
|
confirmationCode: this.invitationCode || '',
|
||||||
showConfirmationCode: false,
|
showConfirmationCode: false,
|
||||||
nostrConfirmationIdentifier: ''
|
nostrConfirmationIdentifier: ''
|
||||||
}
|
}
|
||||||
@@ -464,6 +465,7 @@ window.app.component('username-password', {
|
|||||||
this.$emit('update:userName', this.username)
|
this.$emit('update:userName', this.username)
|
||||||
this.$emit('update:password_1', this.password)
|
this.$emit('update:password_1', this.password)
|
||||||
this.$emit('update:password_2', this.passwordRepeat)
|
this.$emit('update:password_2', this.passwordRepeat)
|
||||||
|
this.$emit('update:invitationCode', this.confirmationCode)
|
||||||
this.$emit('register')
|
this.$emit('register')
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
@@ -570,6 +572,13 @@ window.app.component('username-password', {
|
|||||||
this.confirmationMethod !== 'nostr' ||
|
this.confirmationMethod !== 'nostr' ||
|
||||||
this.nostrConfirmationIdentifier.length > 0
|
this.nostrConfirmationIdentifier.length > 0
|
||||||
|
|
||||||
|
console.log('### disableRegister', {
|
||||||
|
usernameOK,
|
||||||
|
passwordOK,
|
||||||
|
passwordsMatch,
|
||||||
|
codeOk,
|
||||||
|
nostrOk
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
!usernameOK || !passwordOK || !passwordsMatch || !codeOk || !nostrOk
|
!usernameOK || !passwordOK || !passwordsMatch || !codeOk || !nostrOk
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ window.PageHome = {
|
|||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
passwordRepeat: '',
|
passwordRepeat: '',
|
||||||
|
invitationCode: '',
|
||||||
walletName: '',
|
walletName: '',
|
||||||
signup: false
|
signup: false
|
||||||
}
|
}
|
||||||
@@ -40,6 +41,7 @@ window.PageHome = {
|
|||||||
this.username = null
|
this.username = null
|
||||||
this.password = null
|
this.password = null
|
||||||
this.passwordRepeat = null
|
this.passwordRepeat = null
|
||||||
|
this.invitationCode = null
|
||||||
|
|
||||||
this.authAction = 'register'
|
this.authAction = 'register'
|
||||||
this.authMethod = authMethod
|
this.authMethod = authMethod
|
||||||
@@ -51,7 +53,8 @@ window.PageHome = {
|
|||||||
this.username,
|
this.username,
|
||||||
this.email,
|
this.email,
|
||||||
this.password,
|
this.password,
|
||||||
this.passwordRepeat
|
this.passwordRepeat,
|
||||||
|
this.invitationCode
|
||||||
)
|
)
|
||||||
this.refreshAuthUser()
|
this.refreshAuthUser()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
v-model:user-name="username"
|
v-model:user-name="username"
|
||||||
v-model:password_1="password"
|
v-model:password_1="password"
|
||||||
v-model:password_2="passwordRepeat"
|
v-model:password_2="passwordRepeat"
|
||||||
|
v-model:invitation-code="invitationCode"
|
||||||
v-model:reset-key="reset_key"
|
v-model:reset-key="reset_key"
|
||||||
@login="login"
|
@login="login"
|
||||||
@register="register"
|
@register="register"
|
||||||
|
|||||||
Reference in New Issue
Block a user