-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
328d908
commit 8c82911
Showing
4 changed files
with
140 additions
and
90 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
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,15 @@ | ||
{{template "base/head" .}} | ||
<div role="main" aria-label="{{.Title}}" class="page-content user activate"> | ||
<div class="ui middle very relaxed page grid"> | ||
<div class="column"> | ||
<h2 class="ui top attached header"> | ||
{{ctx.Locale.Tr "auth.active_your_account"}} | ||
</h2> | ||
<div class="ui attached segment"> | ||
{{template "base/alert" .}} | ||
<p>{{.ActivationPromptMessage}}</p> | ||
</div> | ||
</div> | ||
</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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"code.gitea.io/gitea/models/unittest" | ||
user_model "code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/test" | ||
"code.gitea.io/gitea/modules/translation" | ||
"code.gitea.io/gitea/tests" | ||
|
||
|
@@ -58,7 +59,7 @@ func TestSignupAsRestricted(t *testing.T) { | |
assert.True(t, user2.IsRestricted) | ||
} | ||
|
||
func TestSignupEmail(t *testing.T) { | ||
func TestSignupEmailValidation(t *testing.T) { | ||
defer tests.PrepareTestEnv(t)() | ||
|
||
setting.Service.EnableCaptcha = false | ||
|
@@ -91,3 +92,50 @@ func TestSignupEmail(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestSignupEmailActive(t *testing.T) { | ||
defer tests.PrepareTestEnv(t)() | ||
defer test.MockVariableValue(&setting.Service.RegisterEmailConfirm, true)() | ||
|
||
// try to sign up and send the activation email | ||
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{ | ||
"user_name": "test-user-1", | ||
"email": "[email protected]", | ||
"password": "password1", | ||
"retype": "password1", | ||
}) | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), `A new confirmation email has been sent to <b>[email protected]</b>.`) | ||
|
||
// access "user/active" means trying to re-send the activation email | ||
session := loginUserWithPassword(t, "test-user-1", "password1") | ||
resp = session.MakeRequest(t, NewRequest(t, "GET", "/user/activate"), http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), "You have already requested an activation email recently") | ||
|
||
// access "user/active" with a valid activation code, then get the "verify password" page | ||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "test-user-1"}) | ||
activationCode := user.GenerateEmailActivateCode(user.Email) | ||
resp = session.MakeRequest(t, NewRequest(t, "GET", "/user/activate?code="+activationCode), http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), `<input id="verify-password"`) | ||
|
||
// try to use a wrong password, it should fail | ||
req = NewRequestWithValues(t, "POST", "/user/activate", map[string]string{ | ||
"code": activationCode, | ||
"password": "password-wrong", | ||
}) | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), `Your password does not match`) | ||
assert.Contains(t, resp.Body.String(), `<input id="verify-password"`) | ||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "test-user-1"}) | ||
assert.False(t, user.IsActive) | ||
|
||
// then use a correct password, the user should be activated | ||
req = NewRequestWithValues(t, "POST", "/user/activate", map[string]string{ | ||
"code": activationCode, | ||
"password": "password1", | ||
}) | ||
resp = session.MakeRequest(t, req, http.StatusSeeOther) | ||
assert.Equal(t, "/", test.RedirectURL(resp)) | ||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "test-user-1"}) | ||
assert.True(t, user.IsActive) | ||
} |