Advertisement
Guest User

Untitled

a guest
Apr 12th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.62 KB | None | 0 0
  1.  implicit val rds  = (
  2.       (__ \ 'email).read[String] and
  3.      (__ \ 'password).read[String] and
  4.       (__ \ 'password2).read[String] and
  5.      (__ \ 'firstName).read[String] and
  6.       (__ \ 'lastName).read[String]
  7.    ) tupled
  8.  
  9.  
  10.  def signUp(builderId: String) = Action(parse.json) { request =>
  11.  
  12.        request.body.validate[(String, String, String, String, String)].map {
  13.            case (email, password, password2, firstName, lastName) => {
  14.              env.userService.findByEmailAndProvider(email, UsernamePasswordProvider.UsernamePassword).map {
  15.                maybeUser => {
  16.                  maybeUser match {
  17.                    case Some(user) => BadRequest("provided email already exists")
  18.                    case None =>
  19.                      val basicProfile = BasicProfile(
  20.                        UsernamePasswordProvider.UsernamePassword,
  21.                        email,
  22.                        Some(firstName),
  23.                        Some(lastName),
  24.                        Some("%s %s".format(firstName, lastName)),
  25.                        Some(email),
  26.                        None,
  27.                        AuthenticationMethod.UserPassword,
  28.                        passwordInfo = Some(env.currentHasher.hash(password)))
  29.  
  30.                      env.userService.save(basicProfile, SaveMode.SignUp);
  31.                      Ok("Your profile was successfully saved")
  32.                  }
  33.                }
  34.              }
  35.              Ok("Your profile was successfully saved")
  36.            }
  37.        }.recoverTotal {
  38.          e => BadRequest("Detected error:"+ JsError.toFlatJson(e))
  39.        }
  40.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement