Skip to content

Commit b93568c

Browse files
cez81appleboy
authored andcommitted
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
1 parent e0c6ab2 commit b93568c

File tree

14 files changed

+44
-23
lines changed

14 files changed

+44
-23
lines changed

conf/app.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ WHITELISTED_URIS =
222222
BLACKLISTED_URIS =
223223

224224
[service]
225-
; Time limit to confirm account/email registration (in multiples of 60 minutes)
225+
; Time limit to confirm account/email registration
226226
ACTIVE_CODE_LIVE_MINUTES = 180
227-
; Time limit to confirm forgot password reset process (in multiples of 60 minutes)
227+
; Time limit to confirm forgot password reset process
228228
RESET_PASSWD_CODE_LIVE_MINUTES = 180
229229
; User need to confirm e-mail for registration
230230
REGISTER_EMAIL_CONFIRM = false

models/mail.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func SendTestMail(email string) error {
4747
func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject, info string) {
4848
data := map[string]interface{}{
4949
"Username": u.DisplayName(),
50-
"ActiveCodeLives": setting.Service.ActiveCodeLives / 60,
51-
"ResetPwdCodeLives": setting.Service.ResetPwdCodeLives / 60,
50+
"ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives),
51+
"ResetPwdCodeLives": base.MinutesToFriendly(setting.Service.ResetPwdCodeLives),
5252
"Code": code,
5353
}
5454

@@ -79,7 +79,7 @@ func SendResetPasswordMail(c *macaron.Context, u *User) {
7979
func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
8080
data := map[string]interface{}{
8181
"Username": u.DisplayName(),
82-
"ActiveCodeLives": setting.Service.ActiveCodeLives / 60,
82+
"ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives),
8383
"Code": u.GenerateEmailActivateCode(email.Email),
8484
"Email": email.Email,
8585
}

modules/base/tool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ func computeTimeDiff(diff int64) (int64, string) {
277277
return diff, diffStr
278278
}
279279

280+
// MinutesToFriendly returns a user friendly string with number of minutes
281+
// converted to hours and minutes.
282+
func MinutesToFriendly(minutes int) string {
283+
duration := time.Duration(minutes) * time.Minute
284+
return TimeSincePro(time.Now().Add(-duration))
285+
}
286+
280287
// TimeSincePro calculates the time interval and generate full user-friendly string.
281288
func TimeSincePro(then time.Time) string {
282289
return timeSincePro(then, time.Now())

modules/base/tool_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ func TestComputeTimeDiff(t *testing.T) {
167167
test(3*Year, "3 years", 0, Year-1)
168168
}
169169

170+
func TestMinutesToFriendly(t *testing.T) {
171+
// test that a number of minutes yields the expected string
172+
test := func(expected string, minutes int) {
173+
actual := MinutesToFriendly(minutes)
174+
assert.Equal(t, expected, actual)
175+
}
176+
test("1 minute", 1)
177+
test("2 minutes", 2)
178+
test("1 hour", 60)
179+
test("1 hour, 1 minute", 61)
180+
test("1 hour, 2 minutes", 62)
181+
test("2 hours", 120)
182+
}
183+
170184
func TestTimeSince(t *testing.T) {
171185
assert.Equal(t, "now", timeSince(BaseDate, BaseDate, "en"))
172186

options/locale/locale_en-US.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ remember_me = Remember Me
170170
forgot_password_title= Forgot Password
171171
forgot_password = Forgot password?
172172
sign_up_now = Need an account? Sign up now.
173-
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.
174-
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.
173+
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.
174+
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.
175175
active_your_account = Activate Your Account
176176
prohibit_login = Login Prohibited
177177
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
347347
add_new_openid = Add new OpenID URI
348348
add_email = Add email
349349
add_openid = Add OpenID URI
350-
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.
350+
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.
351351
add_email_success = Your new email address was successfully added.
352352
add_openid_success = Your new OpenID address was successfully added.
353353
keep_email_private = Keep Email Address Private

routers/dev/template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func TemplatePreview(ctx *context.Context) {
1818
ctx.Data["AppVer"] = setting.AppVer
1919
ctx.Data["AppUrl"] = setting.AppURL
2020
ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374"
21-
ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
22-
ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
21+
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
22+
ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives)
2323
ctx.Data["CurDbValue"] = ""
2424

2525
ctx.HTML(200, base.TplName(ctx.Params("*")))

routers/user/auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
677677
models.SendActivateAccountMail(ctx.Context, u)
678678
ctx.Data["IsSendRegisterMail"] = true
679679
ctx.Data["Email"] = u.Email
680-
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
680+
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
681681
ctx.HTML(200, TplActivate)
682682

683683
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
792792
models.SendActivateAccountMail(ctx.Context, u)
793793
ctx.Data["IsSendRegisterMail"] = true
794794
ctx.Data["Email"] = u.Email
795-
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
795+
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
796796
ctx.HTML(200, TplActivate)
797797

798798
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
@@ -818,7 +818,7 @@ func Activate(ctx *context.Context) {
818818
if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
819819
ctx.Data["ResendLimited"] = true
820820
} else {
821-
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
821+
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
822822
models.SendActivateAccountMail(ctx.Context, ctx.User)
823823

824824
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
@@ -913,7 +913,7 @@ func ForgotPasswdPost(ctx *context.Context) {
913913
u, err := models.GetUserByEmail(email)
914914
if err != nil {
915915
if models.IsErrUserNotExist(err) {
916-
ctx.Data["Hours"] = setting.Service.ResetPwdCodeLives / 60
916+
ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives)
917917
ctx.Data["IsResetSent"] = true
918918
ctx.HTML(200, tplForgotPassword)
919919
return
@@ -940,7 +940,7 @@ func ForgotPasswdPost(ctx *context.Context) {
940940
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
941941
}
942942

943-
ctx.Data["Hours"] = setting.Service.ResetPwdCodeLives / 60
943+
ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives)
944944
ctx.Data["IsResetSent"] = true
945945
ctx.HTML(200, tplForgotPassword)
946946
}

routers/user/auth_openid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
415415
models.SendActivateAccountMail(ctx.Context, u)
416416
ctx.Data["IsSendRegisterMail"] = true
417417
ctx.Data["Email"] = u.Email
418-
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
418+
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives)
419419
ctx.HTML(200, TplActivate)
420420

421421
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {

routers/user/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
297297
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
298298
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
299299
}
300-
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, setting.Service.ActiveCodeLives/60))
300+
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, base.MinutesToFriendly(setting.Service.ActiveCodeLives)))
301301
} else {
302302
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
303303
}

templates/mail/auth/activate.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<body>
99
<p>Hi <b>{{.Username}}</b>, thanks for registering at {{AppName}}!</p>
10-
<p>Please click the following link to verify your e-mail address within <b>{{.ActiveCodeLives}} hours</b>:</p>
10+
<p>Please click the following link to verify your e-mail address within <b>{{.ActiveCodeLives}}</b>:</p>
1111
<p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p>
1212
<p>Not working? Try copying and pasting it to your browser.</p>
1313
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>

templates/mail/auth/activate_email.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<body>
99
<p>Hi <b>{{.Username}}</b>,</p>
10-
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}} hours</b>:</p>
10+
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}}</b>:</p>
1111
<p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p>
1212
<p>Not working? Try copying and pasting it to your browser.</p>
1313
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>

templates/mail/auth/reset_passwd.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<body>
99
<p>Hi <b>{{.Username}}</b>,</p>
10-
<p>Please click the following link to verify your email address within <b>{{.ResetPwdCodeLives}} hours</b>:</p>
10+
<p>Please click the following link to verify your email address within <b>{{.ResetPwdCodeLives}}</b>:</p>
1111
<p><a href="{{AppUrl}}user/reset_password?code={{.Code}}">{{AppUrl}}user/reset_password?code={{.Code}}</a></p>
1212
<p>Not working? Try copying and pasting it to your browser.</p>
1313
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>

templates/user/auth/activate.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
{{else if .ResendLimited}}
1616
<p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p>
1717
{{else}}
18-
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .Hours | Str2html}}</p>
18+
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .ActiveCodeLives | Str2html}}</p>
1919
{{end}}
2020
{{else}}
2121
{{if .IsSendRegisterMail}}
22-
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .Hours | Str2html}}</p>
22+
<p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .ActiveCodeLives | Str2html}}</p>
2323
{{else if .IsActivateFailed}}
2424
<p>{{.i18n.Tr "auth.invalid_code"}}</p>
2525
{{else}}

templates/user/auth/forgot_passwd.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="ui attached segment">
1111
{{template "base/alert" .}}
1212
{{if .IsResetSent}}
13-
<p>{{.i18n.Tr "auth.reset_password_mail_sent_prompt" .Email .Hours | Str2html}}</p>
13+
<p>{{.i18n.Tr "auth.reset_password_mail_sent_prompt" .Email .ResetPwdCodeLives | Str2html}}</p>
1414
{{else if .IsResetRequest}}
1515
<div class="required inline field {{if .Err_Email}}error{{end}}">
1616
<label for="email">{{.i18n.Tr "email"}}</label>

0 commit comments

Comments
 (0)