xxx_active_code_live setting in printed in hours and minutes instead … (#1814)
* xxx_active_code_live setting in printed in hours and minutes instead of just hours * Update app.ini description of xxx_code_lives settings
This commit is contained in:
parent
e0c6ab2d44
commit
b93568cce4
14 changed files with 44 additions and 23 deletions
4
conf/app.ini
vendored
4
conf/app.ini
vendored
|
@ -222,9 +222,9 @@ WHITELISTED_URIS =
|
||||||
BLACKLISTED_URIS =
|
BLACKLISTED_URIS =
|
||||||
|
|
||||||
[service]
|
[service]
|
||||||
; Time limit to confirm account/email registration (in multiples of 60 minutes)
|
; Time limit to confirm account/email registration
|
||||||
ACTIVE_CODE_LIVE_MINUTES = 180
|
ACTIVE_CODE_LIVE_MINUTES = 180
|
||||||
; Time limit to confirm forgot password reset process (in multiples of 60 minutes)
|
; Time limit to confirm forgot password reset process
|
||||||
RESET_PASSWD_CODE_LIVE_MINUTES = 180
|
RESET_PASSWD_CODE_LIVE_MINUTES = 180
|
||||||
; User need to confirm e-mail for registration
|
; User need to confirm e-mail for registration
|
||||||
REGISTER_EMAIL_CONFIRM = false
|
REGISTER_EMAIL_CONFIRM = false
|
||||||
|
|
|
@ -47,8 +47,8 @@ func SendTestMail(email string) error {
|
||||||
func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject, info string) {
|
func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject, info string) {
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"Username": u.DisplayName(),
|
"Username": u.DisplayName(),
|
||||||
"ActiveCodeLives": setting.Service.ActiveCodeLives / 60,
|
"ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives),
|
||||||
"ResetPwdCodeLives": setting.Service.ResetPwdCodeLives / 60,
|
"ResetPwdCodeLives": base.MinutesToFriendly(setting.Service.ResetPwdCodeLives),
|
||||||
"Code": code,
|
"Code": code,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ func SendResetPasswordMail(c *macaron.Context, u *User) {
|
||||||
func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
|
func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"Username": u.DisplayName(),
|
"Username": u.DisplayName(),
|
||||||
"ActiveCodeLives": setting.Service.ActiveCodeLives / 60,
|
"ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives),
|
||||||
"Code": u.GenerateEmailActivateCode(email.Email),
|
"Code": u.GenerateEmailActivateCode(email.Email),
|
||||||
"Email": email.Email,
|
"Email": email.Email,
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,6 +277,13 @@ func computeTimeDiff(diff int64) (int64, string) {
|
||||||
return diff, diffStr
|
return diff, diffStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MinutesToFriendly returns a user friendly string with number of minutes
|
||||||
|
// converted to hours and minutes.
|
||||||
|
func MinutesToFriendly(minutes int) string {
|
||||||
|
duration := time.Duration(minutes) * time.Minute
|
||||||
|
return TimeSincePro(time.Now().Add(-duration))
|
||||||
|
}
|
||||||
|
|
||||||
// TimeSincePro calculates the time interval and generate full user-friendly string.
|
// TimeSincePro calculates the time interval and generate full user-friendly string.
|
||||||
func TimeSincePro(then time.Time) string {
|
func TimeSincePro(then time.Time) string {
|
||||||
return timeSincePro(then, time.Now())
|
return timeSincePro(then, time.Now())
|
||||||
|
|
|
@ -167,6 +167,20 @@ func TestComputeTimeDiff(t *testing.T) {
|
||||||
test(3*Year, "3 years", 0, Year-1)
|
test(3*Year, "3 years", 0, Year-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMinutesToFriendly(t *testing.T) {
|
||||||
|
// test that a number of minutes yields the expected string
|
||||||
|
test := func(expected string, minutes int) {
|
||||||
|
actual := MinutesToFriendly(minutes)
|
||||||
|
assert.Equal(t, expected, actual)
|
||||||
|
}
|
||||||
|
test("1 minute", 1)
|
||||||
|
test("2 minutes", 2)
|
||||||
|
test("1 hour", 60)
|
||||||
|
test("1 hour, 1 minute", 61)
|
||||||
|
test("1 hour, 2 minutes", 62)
|
||||||
|
test("2 hours", 120)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTimeSince(t *testing.T) {
|
func TestTimeSince(t *testing.T) {
|
||||||
assert.Equal(t, "now", timeSince(BaseDate, BaseDate, "en"))
|
assert.Equal(t, "now", timeSince(BaseDate, BaseDate, "en"))
|
||||||
|
|
||||||
|
|
|
@ -170,8 +170,8 @@ remember_me = Remember Me
|
||||||
forgot_password_title= Forgot Password
|
forgot_password_title= Forgot Password
|
||||||
forgot_password = Forgot password?
|
forgot_password = Forgot password?
|
||||||
sign_up_now = Need an account? Sign up now.
|
sign_up_now = Need an account? Sign up now.
|
||||||
confirmation_mail_sent_prompt = A new confirmation email has been sent to <b>%s</b>. Please check your inbox within the next %d hours to complete the registration process.
|
confirmation_mail_sent_prompt = A new confirmation email has been sent to <b>%s</b>. Please check your inbox within the next %s to complete the registration process.
|
||||||
reset_password_mail_sent_prompt = A confirmation email has been sent to <b>%s</b>. Please check your inbox within the next %d hours to complete the password reset process.
|
reset_password_mail_sent_prompt = A confirmation email has been sent to <b>%s</b>. Please check your inbox within the next %s to complete the password reset process.
|
||||||
active_your_account = Activate Your Account
|
active_your_account = Activate Your Account
|
||||||
prohibit_login = Login Prohibited
|
prohibit_login = Login Prohibited
|
||||||
prohibit_login_desc = Your account is prohibited to login, please contact the site administrator.
|
prohibit_login_desc = Your account is prohibited to login, please contact the site administrator.
|
||||||
|
@ -347,7 +347,7 @@ add_new_email = Add new email address
|
||||||
add_new_openid = Add new OpenID URI
|
add_new_openid = Add new OpenID URI
|
||||||
add_email = Add email
|
add_email = Add email
|
||||||
add_openid = Add OpenID URI
|
add_openid = Add OpenID URI
|
||||||
add_email_confirmation_sent = A new confirmation email has been sent to '%s'. Please check your inbox within the next %d hours to confirm your email.
|
add_email_confirmation_sent = A new confirmation email has been sent to '%s'. Please check your inbox within the next %s to confirm your email.
|
||||||
add_email_success = Your new email address was successfully added.
|
add_email_success = Your new email address was successfully added.
|
||||||
add_openid_success = Your new OpenID address was successfully added.
|
add_openid_success = Your new OpenID address was successfully added.
|
||||||
keep_email_private = Keep Email Address Private
|
keep_email_private = Keep Email Address Private
|
||||||
|
|
|
@ -18,8 +18,8 @@ func TemplatePreview(ctx *context.Context) {
|
||||||
ctx.Data["AppVer"] = setting.AppVer
|
ctx.Data["AppVer"] = setting.AppVer
|
||||||
ctx.Data["AppUrl"] = setting.AppURL
|
ctx.Data["AppUrl"] = setting.AppURL
|
||||||
ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374"
|
ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374"
|
||||||
ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
|
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
|
||||||
ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
|
ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives)
|
||||||
ctx.Data["CurDbValue"] = ""
|
ctx.Data["CurDbValue"] = ""
|
||||||
|
|
||||||
ctx.HTML(200, base.TplName(ctx.Params("*")))
|
ctx.HTML(200, base.TplName(ctx.Params("*")))
|
||||||
|
|
|
@ -677,7 +677,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
|
||||||
models.SendActivateAccountMail(ctx.Context, u)
|
models.SendActivateAccountMail(ctx.Context, u)
|
||||||
ctx.Data["IsSendRegisterMail"] = true
|
ctx.Data["IsSendRegisterMail"] = true
|
||||||
ctx.Data["Email"] = u.Email
|
ctx.Data["Email"] = u.Email
|
||||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
|
||||||
ctx.HTML(200, TplActivate)
|
ctx.HTML(200, TplActivate)
|
||||||
|
|
||||||
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
||||||
|
@ -792,7 +792,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
|
||||||
models.SendActivateAccountMail(ctx.Context, u)
|
models.SendActivateAccountMail(ctx.Context, u)
|
||||||
ctx.Data["IsSendRegisterMail"] = true
|
ctx.Data["IsSendRegisterMail"] = true
|
||||||
ctx.Data["Email"] = u.Email
|
ctx.Data["Email"] = u.Email
|
||||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
|
||||||
ctx.HTML(200, TplActivate)
|
ctx.HTML(200, TplActivate)
|
||||||
|
|
||||||
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
||||||
|
@ -818,7 +818,7 @@ func Activate(ctx *context.Context) {
|
||||||
if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
|
if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
|
||||||
ctx.Data["ResendLimited"] = true
|
ctx.Data["ResendLimited"] = true
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
|
||||||
models.SendActivateAccountMail(ctx.Context, ctx.User)
|
models.SendActivateAccountMail(ctx.Context, ctx.User)
|
||||||
|
|
||||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
||||||
|
@ -913,7 +913,7 @@ func ForgotPasswdPost(ctx *context.Context) {
|
||||||
u, err := models.GetUserByEmail(email)
|
u, err := models.GetUserByEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserNotExist(err) {
|
if models.IsErrUserNotExist(err) {
|
||||||
ctx.Data["Hours"] = setting.Service.ResetPwdCodeLives / 60
|
ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives)
|
||||||
ctx.Data["IsResetSent"] = true
|
ctx.Data["IsResetSent"] = true
|
||||||
ctx.HTML(200, tplForgotPassword)
|
ctx.HTML(200, tplForgotPassword)
|
||||||
return
|
return
|
||||||
|
@ -940,7 +940,7 @@ func ForgotPasswdPost(ctx *context.Context) {
|
||||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Hours"] = setting.Service.ResetPwdCodeLives / 60
|
ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives)
|
||||||
ctx.Data["IsResetSent"] = true
|
ctx.Data["IsResetSent"] = true
|
||||||
ctx.HTML(200, tplForgotPassword)
|
ctx.HTML(200, tplForgotPassword)
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,7 +415,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
|
||||||
models.SendActivateAccountMail(ctx.Context, u)
|
models.SendActivateAccountMail(ctx.Context, u)
|
||||||
ctx.Data["IsSendRegisterMail"] = true
|
ctx.Data["IsSendRegisterMail"] = true
|
||||||
ctx.Data["Email"] = u.Email
|
ctx.Data["Email"] = u.Email
|
||||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
|
||||||
ctx.HTML(200, TplActivate)
|
ctx.HTML(200, TplActivate)
|
||||||
|
|
||||||
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
|
||||||
|
|
|
@ -297,7 +297,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
|
||||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
||||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||||
}
|
}
|
||||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, setting.Service.ActiveCodeLives/60))
|
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, base.MinutesToFriendly(setting.Service.ActiveCodeLives)))
|
||||||
} else {
|
} else {
|
||||||
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
|
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<p>Hi <b>{{.Username}}</b>, thanks for registering at {{AppName}}!</p>
|
<p>Hi <b>{{.Username}}</b>, thanks for registering at {{AppName}}!</p>
|
||||||
<p>Please click the following link to verify your e-mail address within <b>{{.ActiveCodeLives}} hours</b>:</p>
|
<p>Please click the following link to verify your e-mail address within <b>{{.ActiveCodeLives}}</b>:</p>
|
||||||
<p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p>
|
<p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p>
|
||||||
<p>Not working? Try copying and pasting it to your browser.</p>
|
<p>Not working? Try copying and pasting it to your browser.</p>
|
||||||
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
|
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<p>Hi <b>{{.Username}}</b>,</p>
|
<p>Hi <b>{{.Username}}</b>,</p>
|
||||||
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}} hours</b>:</p>
|
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}}</b>:</p>
|
||||||
<p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p>
|
<p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p>
|
||||||
<p>Not working? Try copying and pasting it to your browser.</p>
|
<p>Not working? Try copying and pasting it to your browser.</p>
|
||||||
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
|
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<p>Hi <b>{{.Username}}</b>,</p>
|
<p>Hi <b>{{.Username}}</b>,</p>
|
||||||
<p>Please click the following link to verify your email address within <b>{{.ResetPwdCodeLives}} hours</b>:</p>
|
<p>Please click the following link to verify your email address within <b>{{.ResetPwdCodeLives}}</b>:</p>
|
||||||
<p><a href="{{AppUrl}}user/reset_password?code={{.Code}}">{{AppUrl}}user/reset_password?code={{.Code}}</a></p>
|
<p><a href="{{AppUrl}}user/reset_password?code={{.Code}}">{{AppUrl}}user/reset_password?code={{.Code}}</a></p>
|
||||||
<p>Not working? Try copying and pasting it to your browser.</p>
|
<p>Not working? Try copying and pasting it to your browser.</p>
|
||||||
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
|
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
{{else if .ResendLimited}}
|
{{else if .ResendLimited}}
|
||||||
<p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p>
|
<p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .Hours | Str2html}}</p>
|
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .ActiveCodeLives | Str2html}}</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{if .IsSendRegisterMail}}
|
{{if .IsSendRegisterMail}}
|
||||||
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .Hours | Str2html}}</p>
|
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .ActiveCodeLives | Str2html}}</p>
|
||||||
{{else if .IsActivateFailed}}
|
{{else if .IsActivateFailed}}
|
||||||
<p>{{.i18n.Tr "auth.invalid_code"}}</p>
|
<p>{{.i18n.Tr "auth.invalid_code"}}</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="ui attached segment">
|
<div class="ui attached segment">
|
||||||
{{template "base/alert" .}}
|
{{template "base/alert" .}}
|
||||||
{{if .IsResetSent}}
|
{{if .IsResetSent}}
|
||||||
<p>{{.i18n.Tr "auth.reset_password_mail_sent_prompt" .Email .Hours | Str2html}}</p>
|
<p>{{.i18n.Tr "auth.reset_password_mail_sent_prompt" .Email .ResetPwdCodeLives | Str2html}}</p>
|
||||||
{{else if .IsResetRequest}}
|
{{else if .IsResetRequest}}
|
||||||
<div class="required inline field {{if .Err_Email}}error{{end}}">
|
<div class="required inline field {{if .Err_Email}}error{{end}}">
|
||||||
<label for="email">{{.i18n.Tr "email"}}</label>
|
<label for="email">{{.i18n.Tr "email"}}</label>
|
||||||
|
|
Loading…
Add table
Reference in a new issue