Skip to content

Instantly share code, notes, and snippets.

@DoumanAsh
Created March 7, 2019 04:55
Show Gist options
  • Select an option

  • Save DoumanAsh/6a746bb7379d8640eb1aa607fcbcd322 to your computer and use it in GitHub Desktop.

Select an option

Save DoumanAsh/6a746bb7379d8640eb1aa607fcbcd322 to your computer and use it in GitHub Desktop.
pub fn sign_up((form, state): (Json<In<SignupUser>>, State<AppState>)) -> impl Future<Item = HttpResponse, Error = Error> {
let signup_user = form.into_inner().user;
let password = hasher().hash(&signup_user.password).unwrap();
let new_user = NewUser {
username: signup_user.username.clone(),
email: signup_user.email.clone(),
password,
bio: None,
image: None,
};
let db = state.db.clone();
futures::future::result(signup_user.validate())
.map_error(|error| map to your error type?)
.and_then(|_| db.send(new_user).from_err())
.and_then(|res| match res {
Ok(user) => Ok(HttpResponse::Ok().json(UserResponse::from(user))),
Err(e) => Ok(e.error_response()),
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment