Compare commits
8 Commits
v0.3.2-dev
...
4eeca00637
Author | SHA1 | Date | |
---|---|---|---|
4eeca00637
|
|||
785af4b4a3
|
|||
6b7fa86f59
|
|||
905a06111c
|
|||
90db1a97fb
|
|||
8ddc2f73c4
|
|||
7cac6d5aae
|
|||
e19f71fd1c
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.3.2"
|
version = "0.3.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.86"
|
rust-version = "1.86"
|
||||||
|
|
||||||
|
@@ -51,16 +51,13 @@ pub mod endpoint {
|
|||||||
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
||||||
|
|
||||||
if token_stuff::verify_token(&key, &token_literal) {
|
if token_stuff::verify_token(&key, &token_literal) {
|
||||||
let current_time = time::OffsetDateTime::now_utc();
|
|
||||||
let _ = repo::user::update_last_login(&pool, &user, ¤t_time).await;
|
|
||||||
|
|
||||||
(
|
(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
message: String::from("Successful"),
|
message: String::from("Successful"),
|
||||||
data: vec![icarus_models::login_result::LoginResult {
|
data: vec![icarus_models::login_result::LoginResult {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username.clone(),
|
username: user.username,
|
||||||
token: token_literal,
|
token: token_literal,
|
||||||
token_type: String::from(token_stuff::TOKENTYPE),
|
token_type: String::from(token_stuff::TOKENTYPE),
|
||||||
expiration: duration,
|
expiration: duration,
|
||||||
|
@@ -42,39 +42,6 @@ pub mod user {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_last_login(
|
|
||||||
pool: &sqlx::PgPool,
|
|
||||||
user: &icarus_models::user::User,
|
|
||||||
time: &time::OffsetDateTime,
|
|
||||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
|
||||||
let result = sqlx::query(
|
|
||||||
r#"
|
|
||||||
UPDATE "user" SET last_login = $1 WHERE id = $2 RETURNING last_login
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.bind(time)
|
|
||||||
.bind(user.id)
|
|
||||||
.fetch_optional(pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
eprintln!("Error updating time: {}", e);
|
|
||||||
e
|
|
||||||
});
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(row) => match row {
|
|
||||||
Some(r) => {
|
|
||||||
let last_login: time::OffsetDateTime = r
|
|
||||||
.try_get("last_login")
|
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)?;
|
|
||||||
Ok(last_login)
|
|
||||||
}
|
|
||||||
None => Err(sqlx::Error::RowNotFound),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn exists(pool: &sqlx::PgPool, username: &String) -> Result<bool, sqlx::Error> {
|
pub async fn exists(pool: &sqlx::PgPool, username: &String) -> Result<bool, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
|
Reference in New Issue
Block a user