From 7af7584d25f48309a70083c30805ebb8454611f0 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 9 Aug 2014 21:02:00 -0700 Subject: [PATCH] Finish new reset password, etc. --- .gitignore | 1 + conf/locale/locale_en-US.ini | 14 + conf/locale/locale_zh-CN.ini | 14 + modules/middleware/auth.go | 4 +- public/ng/css/ui.css | 1 + public/ng/less/gogs/repository.less | 778 ++++++++++++++-------------- public/ng/less/ui/form.less | 1 + routers/home.go | 7 +- routers/user/auth.go | 211 ++++---- templates/.brackets.json | 5 - templates/home.tmpl | 3 +- templates/user/activate.tmpl | 43 +- templates/user/forgot_passwd.tmpl | 52 +- templates/user/reset_passwd.tmpl | 39 +- templates/user/signin.tmpl | 22 +- templates/user/signup.tmpl | 32 +- 16 files changed, 625 insertions(+), 602 deletions(-) delete mode 100644 templates/.brackets.json diff --git a/.gitignore b/.gitignore index e8b5ee1f93..57d1493b06 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ __pycache__ *.pem output* config.codekit +.brackets.json diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 9e2302195d..d5adde92b0 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -52,9 +52,23 @@ create_new_account = Create New Account register_hepler_msg = Already have an account? Sign in now! social_register_hepler_msg = Already have an account? Bind now! disable_register_prompt = Sorry, registration has been disabled. Please contact the site administrator. +disable_register_mail = Sorry, Register Mail Confirmation has been disabled. remember_me = Remember Me +forgot_password= Fotgot Password forget_password = Fotget password? sign_up_now = Need an account? Sign up now. +confirmation_mail_sent_prompt = A new confirmation e-mail has been sent to %s, please check your inbox within the next %d hours to complete your registration. +sign_in_email = Sign in to your e-mail +active_your_account = Activate Your Account +resent_limit_prompt = Sorry, you are sending an activation e-mail too frequently. Please wait 3 minutes. +has_unconfirmed_mail = Hi %s, you have an unconfirmed email address(%s). If you haven't received a confirmation e-mail or need to resend a new one, please click on the button below. +resend_mail = Click here to resend your activation e-mail +email_not_associate = This e-mail address does not associate to any account. +send_reset_mail = Click here to (re)send your passowrd reset e-mail +reset_password = Reset Your Password +invalid_code = Sorry, your confirmation code has exipired or not valid. +reset_password_helper = Click here to reset your password +password_too_short = Password length cannot be less then 6. [form] UserName = Username diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 8aec50092c..c847f76345 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -52,9 +52,23 @@ create_new_account = 创建帐户 register_hepler_msg = 已经注册?立即登录! social_register_hepler_msg = 已经注册?立即绑定! disable_register_prompt = 对不起,注册功能已被关闭。请联系网站管理员。 +disable_register_mail = 对不起,注册邮箱确认功能已被关闭。 remember_me = 记住登录 +forgot_password = 忘记密码 forget_password = 忘记密码? sign_up_now = 还没帐户?马上注册。 +confirmation_mail_sent_prompt = 一封新的确认邮件已经被发送至 %s,请检查您的收件箱并在 %d 小时内完成确认注册操作。 +sign_in_email = 登录到您的邮箱 +active_your_account = 激活您的帐户 +resent_limit_prompt = 对不起,您请求发送激活邮件过于频繁,请等待 3 分钟后再试! +has_unconfirmed_mail = %s 您好,系统检测到您有一封发送至 %s 但未被确认的邮件。如果您未收到激活邮件,或需要重新发送,请单击下方的按钮。 +resend_mail = 单击此处重新发送确认邮件 +email_not_associate = 您输入的邮箱地址未被关联到任何帐号! +send_reset_mail = 单击此处(重新)发送您的密码重置邮件 +reset_password = 重置密码 +invalid_code = 对不起,您的确认代码已过期或已失效。 +reset_password_helper = 单击此处重置密码 +password_too_short = 密码长度不能少于 6 位! [form] UserName = 用户名 diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 29a2d68110..5862787b34 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -5,6 +5,7 @@ package middleware import ( + "fmt" "net/url" "strings" @@ -43,6 +44,7 @@ func Toggle(options *ToggleOptions) macaron.Handler { } if options.SignInRequire { + fmt.Println(ctx.User.IsActive, setting.Service.RegisterEmailConfirm) if !ctx.IsSigned { // Ignore watch repository operation. if strings.HasSuffix(ctx.Req.RequestURI, "watch") { @@ -52,7 +54,7 @@ func Toggle(options *ToggleOptions) macaron.Handler { ctx.Redirect("/user/login") return } else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { - // ctx.Data["Title"] = "Activate Your Account" + ctx.Data["Title"] = ctx.Tr("auth.active_your_account") ctx.HTML(200, "user/activate") return } diff --git a/public/ng/css/ui.css b/public/ng/css/ui.css index e5b0de3304..e9e3d3ff86 100644 --- a/public/ng/css/ui.css +++ b/public/ng/css/ui.css @@ -435,6 +435,7 @@ dt { } .btn-link { overflow: visible; + color: white; padding: .6em 1.2em; } .btn-radius { diff --git a/public/ng/less/gogs/repository.less b/public/ng/less/gogs/repository.less index abc2f93874..2843fac2d9 100644 --- a/public/ng/less/gogs/repository.less +++ b/public/ng/less/gogs/repository.less @@ -1,476 +1,458 @@ @import "../ui/var"; - @repoHeaderBorderColor: #D6D6D6; @repoHeaderBgColor: #FFF; @repoHeaderNameColor: #888; /* repository main */ + #repo-wrapper { - padding-bottom: 100px; + padding-bottom: 100px; } #repo-header { - height: 69px; - border-bottom: 1px solid @repoHeaderBorderColor; - background-color: @repoHeaderBgColor; + height: 69px; + border-bottom: 1px solid@repoHeaderBorderColor; + +background-color: @repoHeaderBgColor; + } #repo-header-name { - line-height: 66px; - color: @repoHeaderNameColor; - font-size: 1.6em; - font-weight: normal; - margin-bottom: 0; - i { - margin-right: 12px; - vertical-align: middle; - } - .divider { - margin: 0 4px; - } -} + line-height: 66px; + color: @repoHeaderNameColor; +font-size: 1.6em; + font-weight: normal; + margin-bottom: 0; + i { + margin-right: 12px; + vertical-align: middle; + } + .divider { + margin: 0 4px; + } +} #repo-header-meta { - line-height: 66px; - li { - > a { - padding: 0; - &:hover { - background-color: transparent; - } - } - } - a > .btn { - font-size: 1.05em; - margin-left: 16px; - i { - margin-right: 6px; - } - line-height: 16px; - .num { - margin-left: 6px; - } - } + line-height: 66px; + li { + > a { + padding: 0; + &:hover { + background-color: transparent; + } + } + } + a > .btn { + font-size: 1.05em; + margin-left: 16px; + i { + margin-right: 6px; + } + line-height:16px; + .num { + margin-left: 6px; + } + } } - #repo-header-download-btn { - > .btn > i { - margin-right: 0 !important; - } - &:hover { - &:after, - .btn { - background-color: @btnHoverBlackColor; - color: #FFF; - } - } - &:after { - background-color: @btnBlackColor; - padding: 9px 16px 8px 0; - margin-left: -8px !important; - color: #FFF; - border-top: 1px solid @btnBlackColor; - border-bottom: 1px solid @btnBlackColor; - border-top-right-radius: .25em; - border-bottom-right-radius: .25em; - } -} + > .btn > i { + margin-right: 0 !important; + } + &:hover { + &:after, .btn { + background-color: @btnHoverBlackColor; +color: #FFF; + } + } + &:after { + background-color: @btnBlackColor; + +padding: 9px 16px 8px 0; + margin-left: -8px !important; + color: #FFF; + border-top: 1px solid@btnBlackColor; + +border-bottom: 1px solid@btnBlackColor; + +border-top-right-radius: .25em; + border-bottom-right-radius: .25em; + } +} #repo-header-download-drop { - line-height: 24px; - width: 440px; - top: 50px; - left: -354px; - padding: 20px; - box-sizing: border-box; - .btn > i { - margin-right: 6px; - } + line-height: 24px; + width: 440px; + top: 50px; + left: -354px; + padding: 20px; + box-sizing: border-box; + .btn > i { + margin-right: 6px; + } } - #repo-content { - padding: 18px 0; + padding: 18px 0; } - #repo-clone-url { - border-right: none; - width: 196px; - border-left: none; + border-right: none; + width: 196px; + border-left: none; } - #repo-clone-help { - line-height: 48px; + line-height: 48px; } - #repo-clone-zip { - line-height: 48px; - a { - cursor: pointer; - color: white; - overflow: visible; - padding: .6em 1.2em; - } - .btn { - margin: 0 6px; - } + line-height: 48px; + a { + cursor: pointer; + color: white; + overflow: visible; + padding: .6em 1.2em; + } + .btn { + margin: 0 6px; + } } - #repo-desc { - font-size: 1.2em; + font-size: 1.2em; } - #repo-sidebar-nav { - .label { - font-size: 12px; - line-height: 1.4em; - margin-top: 2px; - } - i { - margin-right: 6px; - } + .label { + font-size: 12px; + line-height: 1.4em; + margin-top: 2px; + } + i { + margin-right: 6px; + } } - #repo-file-nav { - padding: .6em 0 1em 0; - > li > a { - padding-left: 0; - &:hover { - background-color: transparent; - } - } - li.repo-jump > a { - padding-right: 0; - .btn { - margin-left: -1px; - } - } + padding: .6em 0 1em 0; + > li > a { + padding-left: 0; + &:hover { + background-color: transparent; + } + } + li.repo-jump > a { + padding-right: 0; + .btn { + margin-left: -1px; + } + } } - #repo-branch-switch { - > a { - .btn { - padding-right: 30px; - } - &:after { - position: absolute; - top: 12px; - right: 30px; - margin-left: 0; - color: @baseFontColor; - } - } - > .drop-down { - top: 40px; - left: 0; - } -} + > a { + .btn { + padding-right: 30px; + } + &:after { + position: absolute; + top: 12px; + right: 30px; + margin-left: 0; + color: @baseFontColor; + } + } + > .drop-down { + top: 40px; + left: 0; + } +} #repo-branch-filter-ipt { - width: 100%; - border-left: none; - border-right: none; - box-sizing: border-box; + width: 100%; + border-left: none; + border-right: none; + box-sizing: border-box; } - #repo-branch-tag { - .tab-nav { - border-bottom: 1px solid #EAEAEA; - a { - padding: .3em .8em; - } - .js-tab-nav-show { - background-color: #EEE; - font-weight: bold; - } - } + .tab-nav { + border-bottom: 1px solid #EAEAEA; + a { + padding: .3em .8em; + } + .js-tab-nav-show { + background-color: #EEE; + font-weight: bold; + } + } } - #repo-branch-list, #repo-tag-list { - li { - i { - margin-right: 12px; - opacity: 0; - } - } - li.checked { - i { - opacity: 1; - } - } + li { + i { + margin-right: 12px; + opacity: 0; + } + } + li.checked { + i { + opacity: 1; + } + } } - #repo-tag-list { - display: none; + display: none; } - #repo-bread { - .bread { - padding-right: 0; - font-size: 16px; - font-weight: bold; - } + .bread { + padding-right: 0; + font-size: 16px; + font-weight: bold; + } } - #repo-main { - padding-right: 40px; - box-sizing: border-box; + padding-right: 40px; + box-sizing: border-box; } - #repo-files-table { - margin-bottom: 20px; - th, - td { - text-align: left; - line-height: 32px; - } - td.icon { - width: 16px; - padding-right: .1em; - padding-left: 1em; - } - td.name { - max-width: 120px; - .text-truncate { - max-width: 100%; - } - } - td.age { - max-width: 120px; - text-align: right; - } - td.msg { - max-width: 440px; - .text-truncate { - max-width: 100%; - } - } - td.age, - td.size, - td.msg a { - color: #888; - } - td.msg a:hover { - color: #428BCA; - text-decoration: underline; - } - tbody { - background-color: #FFF; - tr:hover { - background-color: #ffffEE; - } - } - thead { - background-color: #F0F0F0; - .author { - a { - margin: 0 .4em; - } - } - .last-commit { - strong { - color: #444; - } - .text-truncate { - margin-left: .4em; - } - } - .last-commit .text-truncate, - .age { - font-weight: normal; - color: #888; - } - } + margin-bottom: 20px; + th, td { + text-align: left; + line-height: 32px; + } + td.icon { + width: 16px; + padding-right: .1em; + padding-left: 1em; + } + td.name { + max-width: 120px; + .text-truncate { + max-width: 100%; + } + } + td.age { + max-width: 120px; + text-align: right; + } + td.msg { + max-width: 440px; + .text-truncate { + max-width: 100%; + } + } + td.age, + td.size, + td.msg a { + color: #888; + } + td.msg a:hover { + color: #428BCA; + text-decoration: underline; + } + tbody { + background-color: #FFF; + tr:hover { + background-color: #ffffEE; + } + } + thead { + background-color: #F0F0F0; + .author { + a { + margin: 0 .4em; + } + } + .last-commit { + strong { + color: #444; + } + .text-truncate { + margin-left: .4em; + } + } + .last-commit .text-truncate, + .age { + font-weight: normal; + color: #888; + } + } } - #repo-readme { - margin-bottom: 80px; + margin-bottom: 80px; } - #repo-bare-start { - margin-bottom: 100px; - .panel-content { - background-color: #FFF; - } - pre { - margin: 0 40px; - padding: 6px 10px; - border: 1px solid #ddd; - background: #f8f8f8; - } + margin-bottom: 100px; + .panel-content { + background-color: #FFF; + } + pre { + margin: 0 40px; + padding: 6px 10px; + border: 1px solid #ddd; + background: #f8f8f8; + } } - .repo-bare { - #repo-bare-start { - h2 { - margin-top: 30px; - margin-bottom: 24px; - } - } - #repo-header-meta { - display: none; - } - #repo-clone-ssh { - margin-left: 200px; - } - #repo-clone-copy { - margin-right: 200px; - } - #repo-clone-help { - clear: both; - width: 100%; - } - #repo-clone-url { - width: 520px; - } + #repo-bare-start { + h2 { + margin-top: 30px; + margin-bottom: 24px; + } + } + #repo-header-meta { + display: none; + } + #repo-clone-ssh { + margin-left: 200px; + } + #repo-clone-copy { + margin-right: 200px; + } + #repo-clone-help { + clear: both; + width: 100%; + } + #repo-clone-url { + width: 520px; + } } - /* repository create */ #repo-migrate-form, #repo-create-form { - width: 800px; - margin: 60px auto auto auto; - background: white; - h2 { - margin: .5em 1em; - } - .field { - margin: 1.2em 0 2em 0; - } - .ipt { - width: 540px; - } - textarea { - height: 120px; - } - .avatar { - vertical-align: middle; - margin-right: .6em; - width: 28px; - height: 28px; - } - &:hover { - box-shadow: 0px 0px 6px #CCC; - } + width: 800px; + margin: 60px auto auto auto; + background: white; + h2 { + margin: .5em 1em; + } + .field { + margin: 1.2em 0 2em 0; + } + .ipt { + width: 540px; + } + textarea { + height: 120px; + } + .avatar { + vertical-align: middle; + margin-right: .6em; + width: 28px; + height: 28px; + } + &:hover { + box-shadow: 0px 0px 6px #CCC; + } } - #repo-create-cancel { - margin-left: 4em; + margin-left: 4em; } - #repo-create-owner-list { - top: 30px; - left: 0; - width: auto; - max-width: 300px; - .octicon { - margin-right: 12px; - opacity: 0; - } - .avatar { - width: 20px; - height: 20px; - } - li { - white-space: nowrap; - &.checked { - .octicon { - opacity: 1; - } - } - a { - text-overflow: ellipsis; - -o-text-overflow: ellipsis; - overflow: hidden; - } - } + top: 30px; + left: 0; + width: auto; + max-width: 300px; + .octicon { + margin-right: 12px; + opacity: 0; + } + .avatar { + width: 20px; + height: 20px; + } + li { + white-space: nowrap; + &.checked { + .octicon { + opacity: 1; + } + } + a { + text-overflow: ellipsis; + -o-text-overflow: ellipsis; + overflow: hidden; + } + } } .file-name { - margin-left: 1em; + margin-left: 1em; } .file-size { - font-size: 13px; - color: #888; - margin-left: 1em; + font-size: 13px; + color: #888; + margin-left: 1em; } .code-view { - overflow: auto; - overflow-x: auto; - overflow-y: hidden; - background: white; - .view-raw { - min-height: 40px; - text-align: center; - padding-top: 20px; - .btn { - font-size: 1.05em; - line-height: 16px; - padding: 6px 8px; - } - } - table { - width: 100%; - td { - padding: 0; - } - } - .lines-num { - text-align: right; - color: #999; - background: #f5f5f5; - width: 1%; - span { - font-family: Monaco, Menlo, Consolas, "Courier New", monospace; - line-height: 18px; - padding: 0 8px 0 10px; - cursor: pointer; - display: block; - margin-top: 2px; - font-size: 12px; - } - } - .lines-code > pre { - border: none; - border-left: 1px solid #ddd; - > ol.linenums > li { - padding: 0 10px; - &.active { - background: #ffffdd; - } - } - } + overflow: auto; + overflow-x: auto; + overflow-y: hidden; + background: white; + .view-raw { + min-height: 40px; + text-align: center; + padding-top: 20px; + .btn { + font-size: 1.05em; + line-height: 16px; + padding: 6px 8px; + } + } + table { + width: 100%; + td { + padding: 0; + } + } + .lines-num { + text-align: right; + color: #999; + background: #f5f5f5; + width: 1%; + span { + font-family: Monaco, Menlo, Consolas, "Courier New", monospace; + line-height: 18px; + padding: 0 8px 0 10px; + cursor: pointer; + display: block; + margin-top: 2px; + font-size: 12px; + } + } + .lines-code > pre { + border: none; + border-left: 1px solid #ddd; + > ol.linenums > li { + padding: 0 10px; + &.active { + background: #ffffdd; + } + } + } } .repo-setting-zone { - padding: 30px; + padding: 30px; } #repo-collab-list { - list-style: none; - padding: 10px 0 5px 0; - li.collab { - clear: both; - height: 50px; - padding: 0 15px 0 15px; - } - a.member { - color: #444; - height: 50px; - line-height: 50px; - &:hover { - color: #4183C4; - } - } - .avatar { - margin-right: 1em; - width: 40px; - } - .remove-collab { - color: #DD4B39; - } + list-style: none; + padding: 10px 0 5px 0; + li.collab { + clear: both; + height: 50px; + padding: 0 15px 0 15px; + } + a.member { + color: #444; + height: 50px; + line-height: 50px; + &:hover { + color: #4183C4; + } + } + .avatar { + margin-right: 1em; + width: 40px; + } + .remove-collab { + color: #DD4B39; + } } .repo-user-list-block { - position: relative; - top: 5px; + position: relative; + top: 5px; } .setting-list { - width: 100%; - list-style: none; + width: 100%; + list-style: none; } \ No newline at end of file diff --git a/public/ng/less/ui/form.less b/public/ng/less/ui/form.less index fa36b5dc13..3f530dc390 100644 --- a/public/ng/less/ui/form.less +++ b/public/ng/less/ui/form.less @@ -81,6 +81,7 @@ } .btn-link { overflow: visible; + color: white; padding: .6em 1.2em; } .btn-radius { diff --git a/routers/home.go b/routers/home.go index 4f7abea7a3..5ea3e2a027 100644 --- a/routers/home.go +++ b/routers/home.go @@ -17,7 +17,12 @@ const ( func Home(ctx *middleware.Context) { if ctx.IsSigned { - user.Dashboard(ctx) + if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm { + ctx.Data["Title"] = ctx.Tr("auth.active_your_account") + ctx.HTML(200, user.ACTIVATE) + } else { + user.Dashboard(ctx) + } return } diff --git a/routers/user/auth.go b/routers/user/auth.go index 191da0a219..404b22f24d 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -106,10 +106,9 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) { if err != nil { if err == models.ErrUserNotExist { ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), SIGNIN, &form) - return + } else { + ctx.Handle(500, "UserSignIn", err) } - - ctx.Handle(500, "UserSignIn", err) return } @@ -294,55 +293,59 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe } func Activate(ctx *middleware.Context) { - // code := ctx.Query("code") - // if len(code) == 0 { - // ctx.Data["IsActivatePage"] = true - // if ctx.User.IsActive { - // ctx.Handle(404, "user.Activate", nil) - // return - // } - // // Resend confirmation e-mail. - // if setting.Service.RegisterEmailConfirm { - // if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) { - // ctx.Data["ResendLimited"] = true - // } else { - // ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 - // mailer.SendActiveMail(ctx.Render, ctx.User) + code := ctx.Query("code") + if len(code) == 0 { + ctx.Data["IsActivatePage"] = true + if ctx.User.IsActive { + ctx.Error(404) + return + } + // Resend confirmation e-mail. + if setting.Service.RegisterEmailConfirm { + if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) { + ctx.Data["ResendLimited"] = true + } else { + ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 + mailer.SendActiveMail(ctx.Render, ctx.User) - // if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { - // log.Error("Set cache(MailResendLimit) fail: %v", err) - // } - // } - // } else { - // ctx.Data["ServiceNotEnabled"] = true - // } - // ctx.HTML(200, ACTIVATE) - // return - // } + if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { + log.Error(4, "Set cache(MailResendLimit) fail: %v", err) + } + } + } else { + ctx.Data["ServiceNotEnabled"] = true + } + ctx.HTML(200, ACTIVATE) + return + } - // // Verify code. - // if user := models.VerifyUserActiveCode(code); user != nil { - // user.IsActive = true - // user.Rands = models.GetUserSalt() - // if err := models.UpdateUser(user); err != nil { - // ctx.Handle(404, "user.Activate", err) - // return - // } + // Verify code. + if user := models.VerifyUserActiveCode(code); user != nil { + user.IsActive = true + user.Rands = models.GetUserSalt() + if err := models.UpdateUser(user); err != nil { + if err == models.ErrUserNotExist { + ctx.Error(404) + } else { + ctx.Handle(500, "UpdateUser", err) + } + return + } - // log.Trace("%s User activated: %s", ctx.Req.RequestURI, user.Name) + log.Trace("User activated: %s", user.Name) - // ctx.Session.Set("userId", user.Id) - // ctx.Session.Set("userName", user.Name) - // ctx.Redirect("/") - // return - // } + ctx.Session.Set("uid", user.Id) + ctx.Session.Set("uname", user.Name) + ctx.Redirect("/") + return + } - // ctx.Data["IsActivateFailed"] = true - // ctx.HTML(200, ACTIVATE) + ctx.Data["IsActivateFailed"] = true + ctx.HTML(200, ACTIVATE) } func ForgotPasswd(ctx *middleware.Context) { - ctx.Data["Title"] = "Forgot Password" + ctx.Data["Title"] = ctx.Tr("auth.forgot_password") if setting.MailService == nil { ctx.Data["IsResetDisable"] = true @@ -355,44 +358,45 @@ func ForgotPasswd(ctx *middleware.Context) { } func ForgotPasswdPost(ctx *middleware.Context) { - // ctx.Data["Title"] = "Forgot Password" + ctx.Data["Title"] = ctx.Tr("auth.forgot_password") - // if setting.MailService == nil { - // ctx.Handle(403, "user.ForgotPasswdPost", nil) - // return - // } - // ctx.Data["IsResetRequest"] = true + if setting.MailService == nil { + ctx.Handle(403, "user.ForgotPasswdPost", nil) + return + } + ctx.Data["IsResetRequest"] = true - // email := ctx.Query("email") - // u, err := models.GetUserByEmail(email) - // if err != nil { - // if err == models.ErrUserNotExist { - // ctx.RenderWithErr("This e-mail address does not associate to any account.", "user/forgot_passwd", nil) - // } else { - // ctx.Handle(500, "user.ResetPasswd(check existence)", err) - // } - // return - // } + email := ctx.Query("email") + u, err := models.GetUserByEmail(email) + if err != nil { + if err == models.ErrUserNotExist { + ctx.Data["Err_Email"] = true + ctx.RenderWithErr(ctx.Tr("auth.email_not_associate"), FORGOT_PASSWORD, nil) + } else { + ctx.Handle(500, "user.ResetPasswd(check existence)", err) + } + return + } - // if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) { - // ctx.Data["ResendLimited"] = true - // ctx.HTML(200, FORGOT_PASSWORD) - // return - // } + if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) { + ctx.Data["ResendLimited"] = true + ctx.HTML(200, FORGOT_PASSWORD) + return + } - // mailer.SendResetPasswdMail(ctx.Render, u) - // if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { - // log.Error("Set cache(MailResendLimit) fail: %v", err) - // } + mailer.SendResetPasswdMail(ctx.Render, u) + if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { + log.Error(4, "Set cache(MailResendLimit) fail: %v", err) + } - // ctx.Data["Email"] = email - // ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 - // ctx.Data["IsResetSent"] = true - // ctx.HTML(200, FORGOT_PASSWORD) + ctx.Data["Email"] = email + ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 + ctx.Data["IsResetSent"] = true + ctx.HTML(200, FORGOT_PASSWORD) } func ResetPasswd(ctx *middleware.Context) { - ctx.Data["Title"] = "Reset Password" + ctx.Data["Title"] = ctx.Tr("auth.reset_password") code := ctx.Query("code") if len(code) == 0 { @@ -405,38 +409,39 @@ func ResetPasswd(ctx *middleware.Context) { } func ResetPasswdPost(ctx *middleware.Context) { - // ctx.Data["Title"] = "Reset Password" + ctx.Data["Title"] = ctx.Tr("auth.reset_password") - // code := ctx.Query("code") - // if len(code) == 0 { - // ctx.Error(404) - // return - // } - // ctx.Data["Code"] = code + code := ctx.Query("code") + if len(code) == 0 { + ctx.Error(404) + return + } + ctx.Data["Code"] = code - // if u := models.VerifyUserActiveCode(code); u != nil { - // // Validate password length. - // passwd := ctx.Query("passwd") - // if len(passwd) < 6 || len(passwd) > 30 { - // ctx.Data["IsResetForm"] = true - // ctx.RenderWithErr("Password length should be in 6 and 30.", "user/reset_passwd", nil) - // return - // } + if u := models.VerifyUserActiveCode(code); u != nil { + // Validate password length. + passwd := ctx.Query("password") + if len(passwd) < 6 { + ctx.Data["IsResetForm"] = true + ctx.Data["Err_Password"] = true + ctx.RenderWithErr(ctx.Tr("auth.password_too_short"), RESET_PASSWORD, nil) + return + } - // u.Passwd = passwd - // u.Rands = models.GetUserSalt() - // u.Salt = models.GetUserSalt() - // u.EncodePasswd() - // if err := models.UpdateUser(u); err != nil { - // ctx.Handle(500, "user.ResetPasswd(UpdateUser)", err) - // return - // } + u.Passwd = passwd + u.Rands = models.GetUserSalt() + u.Salt = models.GetUserSalt() + u.EncodePasswd() + if err := models.UpdateUser(u); err != nil { + ctx.Handle(500, "UpdateUser", err) + return + } - // log.Trace("%s User password reset: %s", ctx.Req.RequestURI, u.Name) - // ctx.Redirect("/user/login") - // return - // } + log.Trace("User password reset: %s", u.Name) + ctx.Redirect("/user/login") + return + } - // ctx.Data["IsResetFailed"] = true - // ctx.HTML(200, RESET_PASSWORD) + ctx.Data["IsResetFailed"] = true + ctx.HTML(200, RESET_PASSWORD) } diff --git a/templates/.brackets.json b/templates/.brackets.json deleted file mode 100644 index f358faa62e..0000000000 --- a/templates/.brackets.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "language.fileExtensions": { - "tmpl": "html" - } -} \ No newline at end of file diff --git a/templates/home.tmpl b/templates/home.tmpl index 47d1e69017..a0dd408f7c 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -1,4 +1,5 @@ -{{template "ng/base/head" .}} {{template "ng/base/header" .}} +{{template "ng/base/head" .}} +{{template "ng/base/header" .}}