-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb358c0
commit 547793e
Showing
8 changed files
with
97 additions
and
41 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
type AuthContext = axum_login::extractors::AuthContext<i64, User, SqliteStore<User>>; | ||
|
||
use crate::user::{BareUser, PublicUser, User}; | ||
use crate::database::{BareUser, PublicUser, User}; | ||
|
||
use axum_login::SqliteStore; | ||
use axum::response::IntoResponse; | ||
use axum::http::StatusCode; | ||
use axum::Json; | ||
|
||
pub async fn sign_in(mut auth: AuthContext, Json(payload): Json<BareUser>) -> impl IntoResponse | ||
{ | ||
let user = match database::get_user(&payload.name).await | ||
{ | ||
Ok(user) => user, | ||
Err(_) => return (StatusCode::NOT_FOUND, "name does not exist").into_response(), | ||
}; | ||
|
||
if !hasher::verify(&user.password_hash, &payload.password) | ||
{ | ||
return (StatusCode::UNAUTHORIZED, "password doesn't match").into_response(); | ||
} | ||
|
||
auth.login(&user).await.unwrap(); | ||
(StatusCode::OK, Json(user)).into_response() | ||
} | ||
|
||
pub async fn sign_out(mut auth: AuthContext) -> impl IntoResponse | ||
{ | ||
auth.logout().await; | ||
(StatusCode::OK).into_response() | ||
} | ||
|
||
pub async fn ping() -> impl IntoResponse | ||
{ | ||
(StatusCode::OK).into_response() | ||
} |
Empty file.
This file contains 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
This file contains 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