1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Authentication: logging users in and out, and checking what they may do.
//!
//! Most applications let users log in and keep some pages for them alone. This module logs users
//! in with the session, protects routes, resets passwords, verifies email addresses, and checks
//! [policies](crate::auth::policy) before a user acts on a record. The
//! [authentication guide](https://github.com/laravel/rust-framework/blob/0.x/docs/authentication.md)
//! and the [authorization guide](https://github.com/laravel/rust-framework/blob/0.x/docs/authorization.md)
//! walk through each part.
//!
//! Your application tells Laravel how to find its users with a [`UserProvider`], and derives
//! [`Authenticatable`] for its user type. For a [model](crate::model) user, the provider is
//! [`model::Users`](crate::model::Users). Otherwise, implement the trait for a service, such as a
//! `Users` repository. Register the session guard for them in `src/app.rs`:
//!
//! ```no_run
//! # mod app {
//! # use laravel::auth::{Authenticatable, UserProvider};
//! # use laravel::hash::PasswordHash;
//! # #[derive(Clone)] pub struct User;
//! # impl Authenticatable for User {
//! # type Id = u64;
//! # fn auth_id(&self) -> u64 { 1 }
//! # fn auth_password(&self) -> Option<&PasswordHash> { None }
//! # fn remember_token(&self) -> Option<&str> { None }
//! # }
//! # pub struct Users;
//! # impl UserProvider for Users {
//! # type User = User;
//! # async fn find(&self, _: &u64) -> laravel::Result<Option<User>> { Ok(None) }
//! # async fn find_for_login(&self, _: &str) -> laravel::Result<Option<User>> { Ok(None) }
//! # async fn update_password(&self, _: &User, _: &PasswordHash) -> laravel::Result<()> { Ok(()) }
//! # async fn update_remember_token(&self, _: &User, _: &str) -> laravel::Result<()> { Ok(()) }
//! # }
//! # }
//! # use app::*;
//! laravel::Application::configure().with_auth(|auth, _| {
//! auth.session::<Users>();
//! });
//! ```
//!
//! Mark the handlers of the login page, the password reset page, and the home page of logged-in
//! users with [`#[laravel::auth::page(..)]`](macro@page), so authentication knows where to send
//! users.
//!
//! Then take [`Auth`] as a handler argument to log users in and out, and protect routes with the
//! [`Authenticate`] middleware. [`Passwords`] sends password reset links and resets passwords.
//! [`EmailVerification`] sends email verification links and verifies emails, and
//! [`RequireVerifiedEmail`] keeps users who haven't verified their email out of routes.
//!
//! To authenticate requests by something other than the session, such as an API key, implement
//! [`RequestGuard`] and protect routes with [`Authenticate::via`].
pub use *;
pub use ;
pub use ;
pub use ;
pub use ;