8 import play.api.data.Forms._
10 import models.services._
12 import org.squeryl.PrimitiveTypeMode._
13 object UserController extends Controller{
14 val Home = Redirect(routes.UserController.list(0, ""))
17 "name" -> nonEmptyText,
18 "email" -> nonEmptyText
19 )(User.apply)(User.unapply)
22 def createUser = AuthAction {
23 Action { implicit request =>
25 Ok(views.html.errors.errorNotAuthentication())
27 Ok(views.html.createUserForm(userForm))
32 def userRegistration() = Action { implicit request =>
33 userForm.bindFromRequest.fold(
34 formWithErrors => BadRequest(views.html.createUserForm(formWithErrors)),
37 UserManager().insert(user)
38 Home.flashing("success" -> "User %s has been created".format(user.name))
44 def updateUser(id: Long) = AuthAction {
45 Action{ implicit request =>
47 Ok(views.html.errors.errorNotAuthentication())
50 val user = UserManager().getById(id)
51 val updUser = User(user.name, user.email)
52 Ok(views.html.updateUserForm(userForm.fill(updUser), id))
58 def userModification(id: Long) = Action{ implicit request =>
59 userForm.bindFromRequest.fold(
60 formWithErrors => BadRequest(views.html.updateUserForm(formWithErrors, id)),
63 UserManager().update(user, id)
64 Home.flashing("success" -> "User %s has been updated".format(user.name))
70 def list(page: Int, key: String) = AuthAction {
71 Action{ implicit request =>
73 Ok(views.html.errors.errorNotAuthentication())
76 val row = Integer.decode(Messages("list.row"))
77 val buff = UserManager().list(key)
78 Ok(views.html.userlist(buff.page(page*row, row), buff.size, key, page))