Created
March 7, 2019 04:55
-
-
Save DoumanAsh/6a746bb7379d8640eb1aa607fcbcd322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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