January 2019
Intermediate to advanced
520 pages
14h 32m
English
The handler for creating new comments uses the identity of a user to check that there are credentials to add a new comment:
fn new_comment((req, params): (HttpRequest<State>, Form<AddComment>)) -> FutureResponse<HttpResponse>{ let fut = req.identity() .ok_or(format_err!("not authorized").into()) .into_future() .and_then(move |uid| { let params = NewComment { uid, text: params.into_inner().text, }; post_request::<_, ()>("http://127.0.0.1:8003/new_comment", params) }) .then(move |_| { let res = HttpResponse::build_from(&req) .status(StatusCode::FOUND) .header(header::LOCATION, "/comments.html") .finish(); Ok(res) }); Box::new(fut)}
This handler allows every user who has signed it to leave a comment. Let's look at how this handler ...
Read now
Unlock full access