Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xxx_active_code_live setting in printed in hours and minutes instead … #1814

Merged
merged 2 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions models/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}
Expand Down
7 changes: 7 additions & 0 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
14 changes: 14 additions & 0 deletions modules/base/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
6 changes: 3 additions & 3 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>%s</b>. 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 <b>%s</b>. 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 <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 %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.
Expand Down Expand Up @@ -345,7 +345,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
Expand Down
4 changes: 2 additions & 2 deletions routers/dev/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("*")))
Expand Down
10 changes: 5 additions & 5 deletions routers/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion routers/user/auth_openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion routers/user/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
2 changes: 1 addition & 1 deletion templates/mail/auth/activate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<body>
<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>Not working? Try copying and pasting it to your browser.</p>
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
Expand Down
2 changes: 1 addition & 1 deletion templates/mail/auth/activate_email.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<body>
<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>Not working? Try copying and pasting it to your browser.</p>
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
Expand Down
2 changes: 1 addition & 1 deletion templates/mail/auth/reset_passwd.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<body>
<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>Not working? Try copying and pasting it to your browser.</p>
<p>© <a target="_blank" rel="noopener" href="{{AppUrl}}">{{AppName}}</a></p>
Expand Down
4 changes: 2 additions & 2 deletions templates/user/auth/activate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
{{else if .ResendLimited}}
<p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p>
{{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}}
{{else}}
{{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}}
<p>{{.i18n.Tr "auth.invalid_code"}}</p>
{{else}}
Expand Down
2 changes: 1 addition & 1 deletion templates/user/auth/forgot_passwd.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="ui attached segment">
{{template "base/alert" .}}
{{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}}
<div class="required inline field {{if .Err_Email}}error{{end}}">
<label for="email">{{.i18n.Tr "email"}}</label>
Expand Down