Can disable local login
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -35,6 +35,7 @@ services:
|
||||
network_mode: host
|
||||
environment:
|
||||
- STORAGE_PATH=/storage
|
||||
- DISABLE_LOCAL_LOGIN=true
|
||||
#- RUST_LOG=debug
|
||||
volumes:
|
||||
- ../:/app
|
||||
|
||||
@@ -49,6 +49,7 @@ impl Default for BaseLoginPage {
|
||||
struct LoginTemplate {
|
||||
p: BaseLoginPage,
|
||||
login: String,
|
||||
show_local_login: bool,
|
||||
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(),
|
||||
);
|
||||
}
|
||||
// Try to authenticate user
|
||||
else if let Some(req) = &req {
|
||||
// Try to authenticate user (local login)
|
||||
else if let Some(req) = &req
|
||||
&& !AppConfig::get().disable_local_login
|
||||
{
|
||||
login.clone_from(&req.login);
|
||||
let response: LoginResult = users
|
||||
.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(
|
||||
LoginTemplate {
|
||||
@@ -235,6 +242,7 @@ pub async fn login_route(
|
||||
..Default::default()
|
||||
},
|
||||
login,
|
||||
show_local_login: !AppConfig::get().disable_local_login,
|
||||
providers: providers.cloned(),
|
||||
}
|
||||
.render()
|
||||
|
||||
@@ -18,6 +18,7 @@ pub(crate) struct BaseSettingsPage<'a> {
|
||||
pub success_message: Option<String>,
|
||||
pub page_title: &'static str,
|
||||
pub app_name: &'static str,
|
||||
pub local_login_enabled: bool,
|
||||
pub user: &'a User,
|
||||
pub version: &'static str,
|
||||
pub ip_location_api: Option<&'static str>,
|
||||
@@ -37,6 +38,7 @@ impl<'a> BaseSettingsPage<'a> {
|
||||
app_name: APP_NAME,
|
||||
user,
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
local_login_enabled: !AppConfig::get().disable_local_login,
|
||||
ip_location_api: AppConfig::get().ip_location_service.as_deref(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ pub struct AppConfig {
|
||||
/// Login background image
|
||||
#[arg(long, env, default_value = "/assets/img/forest.jpg")]
|
||||
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! {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
</style>
|
||||
|
||||
<!-- Local login -->
|
||||
{% if show_local_login %}
|
||||
<form action="/login?redirect={{ p.redirect_uri.get_encoded() }}" method="post">
|
||||
<div>
|
||||
<div class="form-floating">
|
||||
@@ -36,6 +38,7 @@
|
||||
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
|
||||
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<!-- Upstream providers -->
|
||||
{% if !providers.is_empty() %}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
Account details
|
||||
</a>
|
||||
</li>
|
||||
{% if p.user.allow_local_login %}
|
||||
{% if p.user.allow_local_login && p.local_login_enabled %}
|
||||
<li>
|
||||
<a href="/settings/change_password" class="nav-link link-dark">
|
||||
Change password
|
||||
|
||||
Reference in New Issue
Block a user