don't show verify email has sent to when there are no valid verify tokens

This commit is contained in:
MaysWind
2023-09-17 18:01:10 +08:00
parent 92273d2fc6
commit 4cecc78a74
7 changed files with 34 additions and 8 deletions
+11 -2
View File
@@ -50,9 +50,18 @@ func (a *AuthorizationsApi) AuthorizeHandler(c *core.Context) (interface{}, *err
}
if settings.Container.Current.EnableUserForceVerifyEmail && !user.EmailVerified {
hasValidEmailVerifyToken, err := a.tokens.ExistsValidTokenByType(c, user.Uid, core.USER_TOKEN_TYPE_EMAIL_VERIFY)
if err != nil {
log.WarnfWithRequestId(c, "[authorizations.AuthorizeHandler] failed check whether user \"uid:%d\" has valid verify email token, because %s", user.Uid, err.Error())
hasValidEmailVerifyToken = false
}
log.WarnfWithRequestId(c, "[authorizations.AuthorizeHandler] login failed for user \"%s\", because user has not verified email", credential.LoginName)
return nil, errs.NewErrorWithContext(errs.ErrEmailIsNotVerified, map[string]string{
"email": user.Email,
return nil, errs.NewErrorWithContext(errs.ErrEmailIsNotVerified, map[string]any{
"email": user.Email,
"hasValidEmailVerifyToken": hasValidEmailVerifyToken,
})
}
+11
View File
@@ -182,6 +182,17 @@ func (s *TokenService) DeleteTokensByType(c *core.Context, uid int64, tokenType
})
}
// ExistsValidTokenByType returns whether the given token type exists
func (s *TokenService) ExistsValidTokenByType(c *core.Context, uid int64, tokenType core.TokenType) (bool, error) {
if uid <= 0 {
return false, errs.ErrUserIdInvalid
}
now := time.Now().Unix()
return s.TokenDB(uid).NewSession(c).Cols("uid", "user_token_id", "expired_unix_time").Where("uid=? AND token_type=? AND expired_unix_time>?", uid, tokenType, now).Exist(&models.TokenRecord{})
}
// ParseFromTokenId returns token model according to token id
func (s *TokenService) ParseFromTokenId(tokenId string) (*models.TokenRecord, error) {
pairs := strings.Split(tokenId, ":")
+1
View File
@@ -856,6 +856,7 @@ export default {
'Verifying...': 'Verifying...',
'Account activation link has been sent to your email address:': 'Account activation link has been sent to your email address:',
', If you don\'t receive the mail, fill password and click the button below to resend the verify mail.': ', If you don\'t receive the mail, fill password and click the button below to resend the verify mail.',
'If you don\'t receive the mail, fill password and click the button below to resend the verify mail to:': 'If you don\'t receive the mail, fill password and click the button below to resend the verify mail to:',
'Resend Validation Email': 'Resend Validation Email',
'Validation email has been sent': 'Validation email has been sent',
'Unable to verify email': 'Unable to verify email',
+1
View File
@@ -856,6 +856,7 @@ export default {
'Verifying...': '正在验证...',
'Account activation link has been sent to your email address:': '账号激活链接已经发送到您的邮箱地址:',
', If you don\'t receive the mail, fill password and click the button below to resend the verify mail.': ',如果您没有收到邮件,输入密码并点击下方的按钮重新发送验证邮件。',
'If you don\'t receive the mail, fill password and click the button below to resend the verify mail to:': '如果您没有收到邮件,输入密码并点击下方的按钮重新发送验证邮件到:',
'Resend Validation Email': '重发验证邮件',
'Validation email has been sent': '验证邮件已发送',
'Unable to verify email': '无法验证邮箱',
+2 -1
View File
@@ -165,7 +165,8 @@ const router = createRouter({
component: VerifyEmailPage,
props: route => ({
email: route.query.email,
token: route.query.token
token: route.query.token,
hasValidEmailVerifyToken: route.query.emailSent === 'true'
})
},
{
+1 -1
View File
@@ -320,7 +320,7 @@ export default {
self.logining = false;
if (self.isUserVerifyEmailEnabled && error.error && error.error.errorCode === 201020 && error.error.context && error.error.context.email) {
self.$router.push('/verify_email?email=' + encodeURIComponent(error.error.context.email));
self.$router.push(`/verify_email?email=${encodeURIComponent(error.error.context.email)}&emailSent=${error.error.context.hasValidEmailVerifyToken || false}`);
return;
}
+7 -4
View File
@@ -28,9 +28,11 @@
<p class="mb-0" v-if="token && !verified && errorMessage">{{ errorMessage }}</p>
<p class="mb-0" v-if="!token && !email">{{ $t('Parameter Invalid') }}</p>
<p class="mb-0" v-if="!token && email">
<span>{{ $t('Account activation link has been sent to your email address:') }}</span>
<span class="ml-1">{{ email }}</span>
<span class="ml-1">{{ $t(', If you don\'t receive the mail, fill password and click the button below to resend the verify mail.') }}</span>
<span v-if="hasValidEmailVerifyToken">{{ $t('Account activation link has been sent to your email address:') }}</span>
<span class="ml-1" v-if="hasValidEmailVerifyToken">{{ email }}</span>
<span class="ml-1" v-if="hasValidEmailVerifyToken">{{ $t(', If you don\'t receive the mail, fill password and click the button below to resend the verify mail.') }}</span>
<span v-if="!hasValidEmailVerifyToken">{{ $t('If you don\'t receive the mail, fill password and click the button below to resend the verify mail to:') }}</span>
<span class="ml-1" v-if="!hasValidEmailVerifyToken">{{ email }}</span>
</p>
</v-card-text>
@@ -135,7 +137,8 @@ import {
export default {
props: [
'email',
'token'
'token',
'hasValidEmailVerifyToken'
],
data() {
return {