Skip to content

Commit f66afb8

Browse files
committed
Proper error when the account is deactivated or locked on upstream SSO login
1 parent 62a4aba commit f66afb8

File tree

1 file changed

+22
-6
lines changed
  • crates/handlers/src/upstream_oauth2

1 file changed

+22
-6
lines changed

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use mas_axum_utils::{
1919
csrf::{CsrfExt, ProtectedForm},
2020
sentry::SentryEventID,
2121
};
22-
use mas_data_model::{User, UserAgent};
22+
use mas_data_model::UserAgent;
2323
use mas_jose::jwt::Jwt;
2424
use mas_matrix::HomeserverConnection;
2525
use mas_policy::Policy;
@@ -31,8 +31,8 @@ use mas_storage::{
3131
user::{BrowserSessionRepository, UserEmailRepository, UserRepository},
3232
};
3333
use mas_templates::{
34-
ErrorContext, FieldError, FormError, TemplateContext, Templates, ToFormState,
35-
UpstreamExistingLinkContext, UpstreamRegister, UpstreamSuggestLink,
34+
AccountInactiveContext, ErrorContext, FieldError, FormError, TemplateContext, Templates,
35+
ToFormState, UpstreamExistingLinkContext, UpstreamRegister, UpstreamSuggestLink,
3636
};
3737
use minijinja::Environment;
3838
use serde::{Deserialize, Serialize};
@@ -272,8 +272,6 @@ pub(crate) async fn get(
272272
.user()
273273
.lookup(user_id)
274274
.await?
275-
// XXX: is that right?
276-
.filter(User::is_valid)
277275
.ok_or(RouteError::UserNotFound)?;
278276

279277
let ctx = UpstreamExistingLinkContext::new(user)
@@ -300,9 +298,27 @@ pub(crate) async fn get(
300298
.user()
301299
.lookup(user_id)
302300
.await?
303-
.filter(mas_data_model::User::is_valid)
304301
.ok_or(RouteError::UserNotFound)?;
305302

303+
// Check that the user is not locked or deactivated
304+
if user.deactivated_at.is_some() {
305+
// The account is deactivated, show the 'account deactivated' fallback
306+
let ctx = AccountInactiveContext::new(user)
307+
.with_csrf(csrf_token.form_value())
308+
.with_language(locale);
309+
let fallback = templates.render_account_deactivated(&ctx)?;
310+
return Ok((cookie_jar, Html(fallback).into_response()));
311+
}
312+
313+
if user.locked_at.is_some() {
314+
// The account is locked, show the 'account locked' fallback
315+
let ctx = AccountInactiveContext::new(user)
316+
.with_csrf(csrf_token.form_value())
317+
.with_language(locale);
318+
let fallback = templates.render_account_locked(&ctx)?;
319+
return Ok((cookie_jar, Html(fallback).into_response()));
320+
}
321+
306322
let session = repo
307323
.browser_session()
308324
.add(&mut rng, &clock, &user, user_agent)

0 commit comments

Comments
 (0)