-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Force user to change password #4489
Merged
lafriks
merged 39 commits into
go-gitea:master
from
adelowo:force_user_to_change_password
Sep 13, 2018
Merged
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
0bef325
redirect to login page after successfully activating account
adelowo 68d57a1
Merge remote-tracking branch 'origin' into force_user_password_change…
adelowo 23acb29
force users to change password if account was created by an admin
adelowo ff42bfd
force users to change password if account was created by an admin
adelowo 26fccdf
fixed build
adelowo 4562460
fixed build
adelowo 5a2ea86
fix pending issues with translation and wrong routes
adelowo 3b87fef
make sure path check is safe
adelowo 7e67ecc
remove unneccessary newline
adelowo 59432fa
make sure users that don't have to view the form get redirected
adelowo 741ef66
move route to use /settings prefix so as to make sure unauthenticated…
adelowo 9b4f70f
update as per @lafriks review
adelowo 845c00b
add necessary comment
adelowo 3b7258e
Merge branch 'master' into force_user_to_change_password
lafriks b6b39d3
remove unrelated changes
adelowo 4ebdfc1
Merge branch 'force_user_to_change_password' of github.com:adelowo/gi…
adelowo e0f8fd8
support redirecting to location the user actually want to go to befor…
adelowo 3e5ed18
Merge branch 'master' into force_user_to_change_password
adelowo 1a75475
Fix merge connflicts
adelowo 4402c56
Merge branch 'master' of https://github.com/go-gitea/gitea into force…
adelowo f7e1e08
run make fmt
adelowo 4d96ba5
added tests
adelowo 95f035d
improve assertions
adelowo 8ea7cdc
add assertion
adelowo 0181ebf
fix copyright year
adelowo d083410
Merge branch 'master' into force_user_to_change_password
adelowo d3febca
Merge branch 'master' of https://github.com/go-gitea/gitea into force…
adelowo dafa9c8
Merge branch 'master' into force_user_to_change_password
adelowo 8c6e9c6
Merge branch 'master' into force_user_to_change_password
adelowo 454cd3a
Merge branch 'master' into force_user_to_change_password
adelowo d7ee5f8
Merge branch 'master' into force_user_to_change_password
adelowo 5441645
Merge branch 'master' into force_user_to_change_password
adelowo 98933c6
Merge branch 'master' into force_user_to_change_password
adelowo d2ddc69
Merge branch 'master' into force_user_to_change_password
adelowo 4c6658a
Merge branch 'master' into force_user_to_change_password
adelowo e2ef29b
Merge branch 'master' into force_user_to_change_password
adelowo 16b5b61
Merge branch 'master' into force_user_to_change_password
techknowlogick a4152f2
Merge branch 'master' into force_user_to_change_password
adelowo a03c9a3
Merge branch 'master' into force_user_to_change_password
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
func addMustChangePassword(x *xorm.Engine) error { | ||
type User struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
MustChangePassword bool `xorm:"NOT NULL DEFAULT false"` | ||
} | ||
|
||
return x.Sync2(new(User)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import ( | |
) | ||
|
||
const ( | ||
tplMustChangePassword = "user/auth/change_passwd" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comment would be recommended here like it is for other constants below |
||
// tplSignIn template for sign in page | ||
tplSignIn base.TplName = "user/auth/signin" | ||
// tplSignUp template path for sign up page | ||
|
@@ -1035,7 +1036,7 @@ func Activate(ctx *context.Context) { | |
|
||
ctx.Session.Set("uid", user.ID) | ||
ctx.Session.Set("uname", user.Name) | ||
ctx.Redirect(setting.AppSubURL + "/") | ||
ctx.Redirect(setting.AppSubURL + "/user/login") | ||
return | ||
} | ||
|
||
|
@@ -1172,7 +1173,8 @@ func ResetPasswdPost(ctx *context.Context) { | |
return | ||
} | ||
u.HashPassword(passwd) | ||
if err := models.UpdateUserCols(u, "passwd", "rands", "salt"); err != nil { | ||
u.MustChangePassword = false | ||
if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
return | ||
} | ||
|
@@ -1185,3 +1187,64 @@ func ResetPasswdPost(ctx *context.Context) { | |
ctx.Data["IsResetFailed"] = true | ||
ctx.HTML(200, tplResetPassword) | ||
} | ||
|
||
// MustChangePassword renders the page to change a user's password | ||
func MustChangePassword(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password") | ||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password" | ||
|
||
ctx.HTML(200, tplMustChangePassword) | ||
} | ||
|
||
// MustChangePasswordPost response for updating a user's password after his/her | ||
// account was created by an admin | ||
func MustChangePasswordPost(ctx *context.Context, cpt *captcha.Captcha, form auth.MustChangePasswordForm) { | ||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password") | ||
|
||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password" | ||
|
||
if ctx.HasError() { | ||
ctx.HTML(200, tplMustChangePassword) | ||
return | ||
} | ||
|
||
u := ctx.User | ||
|
||
// Make sure only requests for users who are eligible to change their password via | ||
// this method passes through | ||
if !u.MustChangePassword { | ||
ctx.ServerError("MustUpdatePassword", errors.New("cannot update password.. Please visit the settings page")) | ||
return | ||
} | ||
|
||
if form.Password != form.Retype { | ||
ctx.Data["Err_Password"] = true | ||
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplMustChangePassword, &form) | ||
return | ||
} | ||
|
||
if len(form.Password) < setting.MinPasswordLength { | ||
ctx.Data["Err_Password"] = true | ||
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplMustChangePassword, &form) | ||
return | ||
} | ||
|
||
var err error | ||
if u.Salt, err = models.GetUserSalt(); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
return | ||
} | ||
|
||
u.HashPassword(form.Password) | ||
u.MustChangePassword = false | ||
|
||
if err := models.UpdateUserCols(u, "must_change_password", "passwd", "salt"); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
return | ||
} | ||
|
||
ctx.Flash.Success(ctx.Tr("settings.change_password_success")) | ||
|
||
log.Trace("User updated password: %s", u.Name) | ||
ctx.Redirect(setting.AppSubURL + "/") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{template "base/head" .}} | ||
<div class="user signin{{if .LinkAccountMode}} icon{{end}}"> | ||
<div class="ui container"> | ||
{{template "user/auth/change_passwd_inner" .}} | ||
</div> | ||
</div> | ||
{{template "base/footer" .}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeSignIn)}} | ||
{{template "base/alert" .}} | ||
{{end}} | ||
<h4 class="ui top attached header center"> | ||
{{.i18n.Tr "settings.change_password"}} | ||
</h4> | ||
<div class="ui attached segment"> | ||
<form class="ui form" action="{{.ChangePasscodeLink}}" method="post"> | ||
{{.CsrfTokenHtml}} | ||
<div class="required inline field {{if and (.Err_Password) (or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeSignIn))}}error{{end}}"> | ||
<label for="password">{{.i18n.Tr "password"}}</label> | ||
<input id="password" name="password" type="password" value="{{.password}}" autocomplete="off" required> | ||
</div> | ||
|
||
|
||
<div class="required inline field {{if and (.Err_Password) (or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister))}}error{{end}}"> | ||
<label for="retype">{{.i18n.Tr "re_type"}}</label> | ||
<input id="retype" name="retype" type="password" autocomplete="off" required> | ||
</div> | ||
|
||
<div class="inline field"> | ||
<label></label> | ||
<button class="ui green button">{{.i18n.Tr "settings.change_password" }}</button> | ||
</div> | ||
</form> | ||
</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same new line as v70 should also go between these two imports.