January 2019
Intermediate to advanced
520 pages
14h 32m
English
To handle sign-up requests, we need a POST method handler for the /signup path. We can declare it in the following way:
(POST) (/signup) => { let data = post_input!(request, { email: String, password: String, })?; let user_email = data.email.trim().to_lowercase(); let user_password = pbkdf2_simple(&data.password, 12345)?; { use self::schema::users::dsl::*; let conn = pool.get()?; let user_exists: bool = select(exists(users.filter(email.eq(user_email.clone())))) .get_result(&conn)?; if !user_exists { let uuid = format!("{}", uuid::Uuid::new_v4()); let new_user = models::NewUser { id: &uuid, email: &user_email, password: &user_password, }; diesel::insert_into(schema::users::table).values(&new_user).execute(&conn)?; Response::json(&()) ...Read now
Unlock full access