mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
Add new user creation stuff.
This commit is contained in:
@@ -6,6 +6,7 @@ class ScalatraBootstrap extends LifeCycle {
|
||||
override def init(context: ServletContext) {
|
||||
context.mount(new IndexController, "/")
|
||||
context.mount(new SignInController, "/*")
|
||||
context.mount(new UsersController, "/*")
|
||||
context.mount(new WikiController, "/*")
|
||||
context.mount(new CreateRepositoryController, "/*")
|
||||
context.mount(new RepositoryViewerController, "/*")
|
||||
|
||||
@@ -1,9 +1,59 @@
|
||||
package app
|
||||
|
||||
class UsersController extends ControllerBase {
|
||||
import model._
|
||||
import service._
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
get("/"){
|
||||
|
||||
class UsersController extends UsersControllerBase with AccountService
|
||||
|
||||
trait UsersControllerBase extends ControllerBase { self: AccountService =>
|
||||
|
||||
case class NewUserForm(userName: String, password: String, mailAddress: String, userType: Int, url: Option[String])
|
||||
|
||||
val newForm = mapping(
|
||||
"userName" -> trim(label("Username" , text(required, maxlength(100), unique))),
|
||||
"password" -> trim(label("Password" , text(required, maxlength(100)))),
|
||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
||||
"userType" -> trim(label("User Type" , number())),
|
||||
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
|
||||
)(NewUserForm.apply)
|
||||
|
||||
|
||||
|
||||
get("/admin/users"){
|
||||
admin.html.userlist(getAllUsers())
|
||||
}
|
||||
|
||||
get("/admin/users/_new"){
|
||||
admin.html.useredit(None)
|
||||
}
|
||||
|
||||
post("/admin/users/_new", newForm){ form =>
|
||||
val currentDate = new java.sql.Date(System.currentTimeMillis)
|
||||
createAccount(Account(
|
||||
userName = form.userName,
|
||||
password = form.password,
|
||||
mailAddress = form.mailAddress,
|
||||
userType = form.userType,
|
||||
url = form.url,
|
||||
registeredDate = currentDate,
|
||||
updatedDate = currentDate,
|
||||
lastLoginDate = None))
|
||||
|
||||
redirect("/admin/users")
|
||||
}
|
||||
|
||||
// get("/admin/users/:name/_edit"){
|
||||
//
|
||||
// }
|
||||
//
|
||||
// post("/admin/users/:name/_edit"){
|
||||
//
|
||||
// }
|
||||
|
||||
def unique: Constraint = new Constraint(){
|
||||
def validate(name: String, value: String): Option[String] =
|
||||
getAccountByUserName(value).map { _ => "User already exists." }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,11 @@ trait AccountService {
|
||||
|
||||
def getAccountByUserName(userName: String): Option[Account] =
|
||||
Query(Accounts) filter(_.userName is userName.bind) firstOption
|
||||
|
||||
def getAllUsers(): List[Account] =
|
||||
Query(Accounts) sortBy(_.userName) list
|
||||
|
||||
def createAccount(account: Account): Unit = Accounts.* insert account
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user