Merge pull request #1709 from kounoike/PR-keep-hash-at-signin

Keep hash when sign in.
This commit is contained in:
Naoki Takezoe
2017-09-15 00:11:22 +09:00
committed by GitHub
2 changed files with 8 additions and 6 deletions

View File

@@ -19,11 +19,12 @@ trait IndexControllerBase extends ControllerBase {
self: RepositoryService with ActivityService with AccountService with RepositorySearchService
with UsersAuthenticator with ReferrerAuthenticator =>
case class SignInForm(userName: String, password: String)
case class SignInForm(userName: String, password: String, hash: Option[String])
val signinForm = mapping(
"userName" -> trim(label("Username", text(required))),
"password" -> trim(label("Password", text(required)))
"password" -> trim(label("Password", text(required))),
"hash" -> trim(optional(text()))
)(SignInForm.apply)
// val searchForm = mapping(
@@ -54,7 +55,7 @@ trait IndexControllerBase extends ControllerBase {
post("/signin", signinForm){ form =>
authenticate(context.settings, form.userName, form.password) match {
case Some(account) => signin(account)
case Some(account) => signin(account, form.hash)
case None => {
flash += "userName" -> form.userName
flash += "password" -> form.password
@@ -86,7 +87,7 @@ trait IndexControllerBase extends ControllerBase {
/**
* Set account information into HttpSession and redirect.
*/
private def signin(account: Account) = {
private def signin(account: Account, hash: Option[String]) = {
session.setAttribute(Keys.Session.LoginAccount, account)
updateLastLoginDate(account.userName)
@@ -98,7 +99,7 @@ trait IndexControllerBase extends ControllerBase {
if(redirectUrl.stripSuffix("/") == request.getContextPath){
redirect("/")
} else {
redirect(redirectUrl)
redirect(redirectUrl + hash.getOrElse(""))
}
}.getOrElse {
redirect("/")

View File

@@ -16,7 +16,8 @@
<span id="error-password" class="error"></span>
<input type="password" name="password" id="password" class="form-control" value="@password"/>
</div>
<input type="submit" class="btn btn-success" value="Sign in"/>
<input type="hidden" name="hash"/>
<input type="submit" class="btn btn-success" value="Sign in" onClick="this.form.hash.value = window.location.hash;"/>
@if(systemSettings.allowAccountRegistration){
or <a href="@context.path/register">Create new account</a>
}