January 2019
Intermediate to advanced
520 pages
14h 32m
English
The following code represents a handler for the /signin request path and parses a query with the data from the HTML form using post_input!:
(POST) (/signin) => { let data = post_input!(request, { email: String, password: String, })?; let user_email = data.email; let user_password = data.password; { use self::schema::users::dsl::*; let conn = pool.get()?; let user = users.filter(email.eq(user_email)) .first::<models::User>(&conn)?; let valid = pbkdf2_check(&user_password, &user.password) .map_err(|err| format_err!("pass check error: {}", err))?; if valid { let user_id = UserId { id: user.id, }; Response::json(&user_id) .with_status_code(200) } else { Response::text("access denied") .with_status_code(403) } }}
When the data ...
Read now
Unlock full access