|
|
|
@ -10,7 +10,7 @@ use oauth2::{AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, Redi
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use sqlx::SqlitePool;
|
|
|
|
use sqlx::SqlitePool;
|
|
|
|
use tower_sessions::Session;
|
|
|
|
use tower_sessions::Session;
|
|
|
|
|
|
|
|
use tracing::error;
|
|
|
|
use crate::error::{AppError, AppForbiddenResponse};
|
|
|
|
use crate::error::{AppError, AppForbiddenResponse};
|
|
|
|
use crate::error::QueryExtractor;
|
|
|
|
use crate::error::QueryExtractor;
|
|
|
|
use crate::app::routes::AppState;
|
|
|
|
use crate::app::routes::AppState;
|
|
|
|
@ -76,6 +76,26 @@ pub async fn auth_login(
|
|
|
|
if user.is_some() {
|
|
|
|
if user.is_some() {
|
|
|
|
return Ok(Redirect::to("/"));
|
|
|
|
return Ok(Redirect::to("/"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bypass security
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
error!("Bypassing security altogether. Hope this isn't on prod");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let session_user = SessionUser {
|
|
|
|
|
|
|
|
id: 1,
|
|
|
|
|
|
|
|
role: 1,
|
|
|
|
|
|
|
|
oauth_id: "guest".to_owned(),
|
|
|
|
|
|
|
|
email: "guest@guest.net".to_owned(),
|
|
|
|
|
|
|
|
name: "Guest".to_owned(),
|
|
|
|
|
|
|
|
verified_email: true,
|
|
|
|
|
|
|
|
picture: "".to_owned(),
|
|
|
|
|
|
|
|
tz_offset: -21600, /* Central US Time */
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 10 - Save user session data
|
|
|
|
|
|
|
|
session.insert(USER_SESSION, session_user).await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(Redirect::to("/"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// STEP 1 - Get the OAUTH Redirect Info with a random state token
|
|
|
|
// STEP 1 - Get the OAUTH Redirect Info with a random state token
|
|
|
|
let (auth_url, csrf_token) = oauth_client
|
|
|
|
let (auth_url, csrf_token) = oauth_client
|
|
|
|
|