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