-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force user to change password (#4489)
* redirect to login page after successfully activating account * force users to change password if account was created by an admin * force users to change password if account was created by an admin * fixed build * fixed build * fix pending issues with translation and wrong routes * make sure path check is safe * remove unneccessary newline * make sure users that don't have to view the form get redirected * move route to use /settings prefix so as to make sure unauthenticated users can't view the page * update as per @lafriks review * add necessary comment * remove unrelated changes * support redirecting to location the user actually want to go to before being forced to change his/her password * run make fmt * added tests * improve assertions * add assertion * fix copyright year Signed-off-by: Lanre Adelowo <[email protected]>
- Loading branch information
Showing
13 changed files
with
255 additions
and
22 deletions.
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
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,19 @@ | ||
// 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 { | ||
// User see models/user.go | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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 admin | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
models.MainTest(m, filepath.Join("..", "..")) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2017 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 admin | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/auth" | ||
"code.gitea.io/gitea/modules/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewUserPost_MustChangePassword(t *testing.T) { | ||
|
||
models.PrepareTestEnv(t) | ||
ctx := test.MockContext(t, "admin/users/new") | ||
|
||
u := models.AssertExistsAndLoadBean(t, &models.User{ | ||
IsAdmin: true, | ||
ID: 2, | ||
}).(*models.User) | ||
|
||
ctx.User = u | ||
|
||
username := "gitea" | ||
email := "[email protected]" | ||
|
||
form := auth.AdminCreateUserForm{ | ||
LoginType: "local", | ||
LoginName: "local", | ||
UserName: username, | ||
Email: email, | ||
Password: "xxxxxxxx", | ||
SendNotify: false, | ||
} | ||
|
||
NewUserPost(ctx, form) | ||
|
||
assert.NotEmpty(t, ctx.Flash.SuccessMsg) | ||
|
||
u, err := models.GetUserByName(username) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, username, u.Name) | ||
assert.Equal(t, email, u.Email) | ||
assert.True(t, u.MustChangePassword) | ||
} |
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 |
---|---|---|
@@ -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> |