diff --git a/conf/app.ini b/conf/app.ini index 106e0ea2c2..b3b306ccc3 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -222,9 +222,9 @@ WHITELISTED_URIS = BLACKLISTED_URIS = [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 -; 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 ; User need to confirm e-mail for registration REGISTER_EMAIL_CONFIRM = false diff --git a/models/mail.go b/models/mail.go index 211f2b5786..7ef73fc11d 100644 --- a/models/mail.go +++ b/models/mail.go @@ -47,8 +47,8 @@ func SendTestMail(email string) error { func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject, info string) { data := map[string]interface{}{ "Username": u.DisplayName(), - "ActiveCodeLives": setting.Service.ActiveCodeLives / 60, - "ResetPwdCodeLives": setting.Service.ResetPwdCodeLives / 60, + "ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives), + "ResetPwdCodeLives": base.MinutesToFriendly(setting.Service.ResetPwdCodeLives), "Code": code, } @@ -79,7 +79,7 @@ func SendResetPasswordMail(c *macaron.Context, u *User) { func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) { data := map[string]interface{}{ "Username": u.DisplayName(), - "ActiveCodeLives": setting.Service.ActiveCodeLives / 60, + "ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives), "Code": u.GenerateEmailActivateCode(email.Email), "Email": email.Email, } diff --git a/modules/base/tool.go b/modules/base/tool.go index 32987a0b8b..3fe5a3d84f 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -277,6 +277,13 @@ func computeTimeDiff(diff int64) (int64, string) { 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. func TimeSincePro(then time.Time) string { return timeSincePro(then, time.Now()) diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go index 43d4df32f7..bd9c6e276e 100644 --- a/modules/base/tool_test.go +++ b/modules/base/tool_test.go @@ -167,6 +167,20 @@ func TestComputeTimeDiff(t *testing.T) { 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) { assert.Equal(t, "now", timeSince(BaseDate, BaseDate, "en")) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8354ebd12c..f699ce5543 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -170,8 +170,8 @@ remember_me = Remember Me forgot_password_title= Forgot Password forgot_password = Forgot password? sign_up_now = Need an account? Sign up now. -confirmation_mail_sent_prompt = A new confirmation email has been sent to %s. Please check your inbox within the next %d hours to complete the registration process. -reset_password_mail_sent_prompt = A confirmation email has been sent to %s. Please check your inbox within the next %d hours to complete the password reset process. +confirmation_mail_sent_prompt = A new confirmation email has been sent to %s. 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 %s. Please check your inbox within the next %s to complete the password reset process. active_your_account = Activate Your Account prohibit_login = Login Prohibited 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_email = Add email 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_openid_success = Your new OpenID address was successfully added. keep_email_private = Keep Email Address Private diff --git a/routers/dev/template.go b/routers/dev/template.go index fae85a3968..fc3ef9942e 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -18,8 +18,8 @@ func TemplatePreview(ctx *context.Context) { ctx.Data["AppVer"] = setting.AppVer ctx.Data["AppUrl"] = setting.AppURL ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374" - ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60 - ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60 + ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives) + ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives) ctx.Data["CurDbValue"] = "" ctx.HTML(200, base.TplName(ctx.Params("*"))) diff --git a/routers/user/auth.go b/routers/user/auth.go index 856b47bdd1..d1a6fc8a97 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -677,7 +677,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au models.SendActivateAccountMail(ctx.Context, u) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email - ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 + ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives) ctx.HTML(200, TplActivate) 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) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email - ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 + ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives) ctx.HTML(200, TplActivate) 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) { ctx.Data["ResendLimited"] = true } else { - ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 + ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives) models.SendActivateAccountMail(ctx.Context, ctx.User) 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) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Data["Hours"] = setting.Service.ResetPwdCodeLives / 60 + ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives) ctx.Data["IsResetSent"] = true ctx.HTML(200, tplForgotPassword) return @@ -940,7 +940,7 @@ func ForgotPasswdPost(ctx *context.Context) { 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.HTML(200, tplForgotPassword) } diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index 7d4df342e9..15bbe41c14 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -415,7 +415,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si models.SendActivateAccountMail(ctx.Context, u) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email - ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 + ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives) ctx.HTML(200, TplActivate) if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { diff --git a/routers/user/setting.go b/routers/user/setting.go index 4fff19ef63..8fa9834167 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -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 { 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 { ctx.Flash.Success(ctx.Tr("settings.add_email_success")) } diff --git a/templates/mail/auth/activate.tmpl b/templates/mail/auth/activate.tmpl index 4a2e7eeb84..5721199a2e 100644 --- a/templates/mail/auth/activate.tmpl +++ b/templates/mail/auth/activate.tmpl @@ -7,7 +7,7 @@

Hi {{.Username}}, thanks for registering at {{AppName}}!

-

Please click the following link to verify your e-mail address within {{.ActiveCodeLives}} hours:

+

Please click the following link to verify your e-mail address within {{.ActiveCodeLives}}:

{{AppUrl}}user/activate?code={{.Code}}

Not working? Try copying and pasting it to your browser.

© {{AppName}}

diff --git a/templates/mail/auth/activate_email.tmpl b/templates/mail/auth/activate_email.tmpl index c1031b2831..5111de06c5 100644 --- a/templates/mail/auth/activate_email.tmpl +++ b/templates/mail/auth/activate_email.tmpl @@ -7,7 +7,7 @@

Hi {{.Username}},

-

Please click the following link to verify your email address within {{.ActiveCodeLives}} hours:

+

Please click the following link to verify your email address within {{.ActiveCodeLives}}:

{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}

Not working? Try copying and pasting it to your browser.

© {{AppName}}

diff --git a/templates/mail/auth/reset_passwd.tmpl b/templates/mail/auth/reset_passwd.tmpl index 69719bce4b..ed51896b03 100644 --- a/templates/mail/auth/reset_passwd.tmpl +++ b/templates/mail/auth/reset_passwd.tmpl @@ -7,7 +7,7 @@

Hi {{.Username}},

-

Please click the following link to verify your email address within {{.ResetPwdCodeLives}} hours:

+

Please click the following link to verify your email address within {{.ResetPwdCodeLives}}:

{{AppUrl}}user/reset_password?code={{.Code}}

Not working? Try copying and pasting it to your browser.

© {{AppName}}

diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index 8bff54aaf4..9805067ae1 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -15,11 +15,11 @@ {{else if .ResendLimited}}

{{.i18n.Tr "auth.resent_limit_prompt"}}

{{else}} -

{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .Hours | Str2html}}

+

{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .ActiveCodeLives | Str2html}}

{{end}} {{else}} {{if .IsSendRegisterMail}} -

{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .Hours | Str2html}}

+

{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .ActiveCodeLives | Str2html}}

{{else if .IsActivateFailed}}

{{.i18n.Tr "auth.invalid_code"}}

{{else}} diff --git a/templates/user/auth/forgot_passwd.tmpl b/templates/user/auth/forgot_passwd.tmpl index 412b5b8847..2aeee300f0 100644 --- a/templates/user/auth/forgot_passwd.tmpl +++ b/templates/user/auth/forgot_passwd.tmpl @@ -10,7 +10,7 @@
{{template "base/alert" .}} {{if .IsResetSent}} -

{{.i18n.Tr "auth.reset_password_mail_sent_prompt" .Email .Hours | Str2html}}

+

{{.i18n.Tr "auth.reset_password_mail_sent_prompt" .Email .ResetPwdCodeLives | Str2html}}

{{else if .IsResetRequest}}