mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
Fix validation.
This commit is contained in:
@@ -87,6 +87,8 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
|||||||
def validate(name: String, value: String): Option[String] = {
|
def validate(name: String, value: String): Option[String] = {
|
||||||
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
|
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
|
||||||
Some("Repository name contains invalid character.")
|
Some("Repository name contains invalid character.")
|
||||||
|
} else if(value.startsWith("_") || value.startsWith("-")){
|
||||||
|
Some("Repository name starts with invalid character.")
|
||||||
} else if(getRepositoryNamesOfUser(context.loginAccount.get.userName).contains(value)){
|
} else if(getRepositoryNamesOfUser(context.loginAccount.get.userName).contains(value)){
|
||||||
Some("Repository already exists.")
|
Some("Repository already exists.")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ class UsersController extends UsersControllerBase with AccountService with Admin
|
|||||||
|
|
||||||
trait UsersControllerBase extends ControllerBase { self: AccountService with AdminOnlyAuthenticator =>
|
trait UsersControllerBase extends ControllerBase { self: AccountService with AdminOnlyAuthenticator =>
|
||||||
|
|
||||||
// TODO ユーザ名の先頭に_は使えないようにする&利用可能文字チェック
|
|
||||||
case class UserForm(userName: String, password: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
case class UserForm(userName: String, password: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
||||||
|
|
||||||
val newForm = mapping(
|
val newForm = mapping(
|
||||||
"userName" -> trim(label("Username" , text(required, maxlength(100), unique))),
|
"userName" -> trim(label("Username" , text(required, maxlength(100), username, unique))),
|
||||||
"password" -> trim(label("Password" , text(required, maxlength(100)))),
|
"password" -> trim(label("Password" , text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
||||||
"isAdmin" -> trim(label("User Type" , boolean())),
|
"isAdmin" -> trim(label("User Type" , boolean())),
|
||||||
@@ -21,7 +20,7 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with Adm
|
|||||||
)(UserForm.apply)
|
)(UserForm.apply)
|
||||||
|
|
||||||
val editForm = mapping(
|
val editForm = mapping(
|
||||||
"userName" -> trim(label("Username" , text())),
|
"userName" -> trim(label("Username" , text(required, maxlength(100), username))),
|
||||||
"password" -> trim(label("Password" , text(required, maxlength(100)))),
|
"password" -> trim(label("Password" , text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
||||||
"isAdmin" -> trim(label("User Type" , boolean())),
|
"isAdmin" -> trim(label("User Type" , boolean())),
|
||||||
@@ -69,7 +68,18 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with Adm
|
|||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
})
|
})
|
||||||
|
|
||||||
def unique: Constraint = new Constraint(){
|
private def username: Constraint = new Constraint(){
|
||||||
|
def validate(name: String, value: String): Option[String] =
|
||||||
|
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
|
||||||
|
Some("Username contains invalid character.")
|
||||||
|
} else if(value.startsWith("_") || value.startsWith("-")){
|
||||||
|
Some("Username starts with invalid character.")
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private def unique: Constraint = new Constraint(){
|
||||||
def validate(name: String, value: String): Option[String] =
|
def validate(name: String, value: String): Option[String] =
|
||||||
getAccountByUserName(value).map { _ => "User already exists." }
|
getAccountByUserName(value).map { _ => "User already exists." }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,8 +183,8 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
def validate(name: String, value: String): Option[String] = {
|
def validate(name: String, value: String): Option[String] = {
|
||||||
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
|
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
|
||||||
Some("Page name contains invalid character.")
|
Some("Page name contains invalid character.")
|
||||||
} else if(value.startsWith("_")){
|
} else if(value.startsWith("_") || value.startsWith("-")){
|
||||||
Some("Page name can not start with '_'.")
|
Some("Page name starts with invalid character.")
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user