Can disable local login
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-29 12:20:05 +01:00
parent 9a599fdde2
commit d4de81f1fb
6 changed files with 22 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ services:
network_mode: host network_mode: host
environment: environment:
- STORAGE_PATH=/storage - STORAGE_PATH=/storage
- DISABLE_LOCAL_LOGIN=true
#- RUST_LOG=debug #- RUST_LOG=debug
volumes: volumes:
- ../:/app - ../:/app

View File

@@ -49,6 +49,7 @@ impl Default for BaseLoginPage {
struct LoginTemplate { struct LoginTemplate {
p: BaseLoginPage, p: BaseLoginPage,
login: String, login: String,
show_local_login: bool,
providers: Vec<Provider>, providers: Vec<Provider>,
} }
@@ -156,8 +157,10 @@ pub async fn login_route(
"Given login could not be processed, because it has an invalid format!".to_string(), "Given login could not be processed, because it has an invalid format!".to_string(),
); );
} }
// Try to authenticate user // Try to authenticate user (local login)
else if let Some(req) = &req { else if let Some(req) = &req
&& !AppConfig::get().disable_local_login
{
login.clone_from(&req.login); login.clone_from(&req.login);
let response: LoginResult = users let response: LoginResult = users
.send(users_actor::LocalLoginRequest { .send(users_actor::LocalLoginRequest {
@@ -224,6 +227,10 @@ pub async fn login_route(
} }
} }
} }
// If there is only a single provider, trigger auto-login
else if AppConfig::get().disable_local_login && providers.len() == 1 {
return redirect_user(&providers.cloned()[0].login_url(&query.redirect));
}
HttpResponse::Ok().content_type("text/html").body( HttpResponse::Ok().content_type("text/html").body(
LoginTemplate { LoginTemplate {
@@ -235,6 +242,7 @@ pub async fn login_route(
..Default::default() ..Default::default()
}, },
login, login,
show_local_login: !AppConfig::get().disable_local_login,
providers: providers.cloned(), providers: providers.cloned(),
} }
.render() .render()

View File

@@ -18,6 +18,7 @@ pub(crate) struct BaseSettingsPage<'a> {
pub success_message: Option<String>, pub success_message: Option<String>,
pub page_title: &'static str, pub page_title: &'static str,
pub app_name: &'static str, pub app_name: &'static str,
pub local_login_enabled: bool,
pub user: &'a User, pub user: &'a User,
pub version: &'static str, pub version: &'static str,
pub ip_location_api: Option<&'static str>, pub ip_location_api: Option<&'static str>,
@@ -37,6 +38,7 @@ impl<'a> BaseSettingsPage<'a> {
app_name: APP_NAME, app_name: APP_NAME,
user, user,
version: env!("CARGO_PKG_VERSION"), version: env!("CARGO_PKG_VERSION"),
local_login_enabled: !AppConfig::get().disable_local_login,
ip_location_api: AppConfig::get().ip_location_service.as_deref(), ip_location_api: AppConfig::get().ip_location_service.as_deref(),
} }
} }

View File

@@ -62,6 +62,11 @@ pub struct AppConfig {
/// Login background image /// Login background image
#[arg(long, env, default_value = "/assets/img/forest.jpg")] #[arg(long, env, default_value = "/assets/img/forest.jpg")]
pub login_background_image: String, pub login_background_image: String,
/// Disable local login. If this option is set without any upstream providers set, it will be impossible
/// to authenticate
#[arg(long, env)]
pub disable_local_login: bool,
} }
lazy_static::lazy_static! { lazy_static::lazy_static! {

View File

@@ -18,6 +18,8 @@
</style> </style>
<!-- Local login -->
{% if show_local_login %}
<form action="/login?redirect={{ p.redirect_uri.get_encoded() }}" method="post"> <form action="/login?redirect={{ p.redirect_uri.get_encoded() }}" method="post">
<div> <div>
<div class="form-floating"> <div class="form-floating">
@@ -36,6 +38,7 @@
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button> <button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
</form> </form>
{% endif %}
<!-- Upstream providers --> <!-- Upstream providers -->
{% if !providers.is_empty() %} {% if !providers.is_empty() %}

View File

@@ -24,7 +24,7 @@
Account details Account details
</a> </a>
</li> </li>
{% if p.user.allow_local_login %} {% if p.user.allow_local_login && p.local_login_enabled %}
<li> <li>
<a href="/settings/change_password" class="nav-link link-dark"> <a href="/settings/change_password" class="nav-link link-dark">
Change password Change password