-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve first time setup experience
- Loading branch information
1 parent
36fc048
commit 2d86dc0
Showing
9 changed files
with
135 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
#![allow(non_snake_case)] | ||
|
||
use std::sync::atomic::{AtomicI64, AtomicU64, Ordering}; | ||
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering}; | ||
use std::sync::Arc; | ||
|
||
use crate::db::ApiAuthed; | ||
|
@@ -111,6 +111,7 @@ pub fn global_service() -> Router { | |
.route("/leave_instance", post(leave_instance)) | ||
.route("/export", get(export_global_users)) | ||
.route("/overwrite", post(overwrite_global_users)) | ||
|
||
// .route("/list_invite_codes", get(list_invite_codes)) | ||
// .route("/create_invite_code", post(create_invite_code)) | ||
// .route("/signup", post(signup)) | ||
|
@@ -121,8 +122,8 @@ pub fn global_service() -> Router { | |
pub fn make_unauthed_service() -> Router { | ||
Router::new() | ||
.route("/login", post(login)) | ||
.route("/logout", post(logout)) | ||
.route("/logout", get(logout)) | ||
.route("/logout", post(logout).get(logout)) | ||
.route("/is_first_time_setup", get(is_first_time_setup)) | ||
} | ||
|
||
fn username_override_from_label(label: Option<String>) -> Option<String> { | ||
|
@@ -826,6 +827,48 @@ pub struct Login { | |
pub password: String, | ||
} | ||
|
||
lazy_static::lazy_static! { | ||
static ref FIRST_TIME_SETUP: Arc<AtomicBool> = Arc::new(AtomicBool::new(true)); | ||
} | ||
|
||
pub async fn is_first_time_setup(Extension(db): Extension<DB>) -> JsonResult<bool> { | ||
if !FIRST_TIME_SETUP.load(std::sync::atomic::Ordering::Relaxed) { | ||
return Ok(Json(false)); | ||
} | ||
let single_user = sqlx::query_scalar!("SELECT 1 FROM password LIMIT 2") | ||
.fetch_all(&db) | ||
.await | ||
.ok() | ||
.unwrap_or_default() | ||
.len() | ||
== 1; | ||
if single_user { | ||
let user_is_admin_and_password_changeme = sqlx::query_scalar!( | ||
"SELECT 1 FROM password WHERE email = '[email protected]' AND password_hash = '$argon2id$v=19$m=4096,t=3,p=1$oLJo/lPn/gezXCuFOEyaNw$i0T2tCkw3xUFsrBIKZwr8jVNHlIfoxQe+HfDnLtd12I'" | ||
).fetch_all(&db) | ||
.await | ||
.ok() | ||
.unwrap_or_default() | ||
.len() == 1; | ||
if user_is_admin_and_password_changeme { | ||
let base_url_is_not_set = | ||
sqlx::query_scalar!("SELECT COUNT(*) FROM global_settings WHERE name = 'base_url'") | ||
.fetch_optional(&db) | ||
.await | ||
.ok() | ||
.flatten() | ||
.flatten() | ||
.unwrap_or(0) | ||
== 0; | ||
if base_url_is_not_set { | ||
return Ok(Json(true)); | ||
} | ||
} | ||
} | ||
FIRST_TIME_SETUP.store(false, std::sync::atomic::Ordering::Relaxed); | ||
Ok(Json(false)) | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct WorkspaceUsername { | ||
pub username: String, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
export let password: string | undefined = undefined | ||
export let error: string | undefined = undefined | ||
export let popup: boolean = false | ||
export let firstTime: boolean = false | ||
const providers = [ | ||
{ | ||
|
@@ -75,6 +76,11 @@ | |
return | ||
} | ||
if (firstTime) { | ||
goto('/user/first-time') | ||
return | ||
} | ||
// Once logged in, we can fetch the workspaces | ||
$usersWorkspaceStore = await WorkspaceService.listUserWorkspaces() | ||
// trigger a reload of the user | ||
|
@@ -88,13 +94,6 @@ | |
} | ||
async function redirectUser() { | ||
const firstTimeCookie = | ||
document.cookie.match('(^|;)\\s*first_time\\s*=\\s*([^;]+)')?.pop() || '0' | ||
if (Number(firstTimeCookie) > 0 && email === '[email protected]') { | ||
goto('/user/first-time') | ||
return | ||
} | ||
if (rd?.startsWith('http')) { | ||
window.location.href = rd | ||
return | ||
|
@@ -177,6 +176,7 @@ | |
dispatch('login') | ||
} | ||
} | ||
function storeRedirect(provider: string) { | ||
if (rd) { | ||
try { | ||
|
@@ -263,6 +263,11 @@ | |
|
||
{#if showPassword} | ||
<div> | ||
{#if firstTime} | ||
<div class="text-lg text-center w-full pb-6" | ||
>First time login: [email protected] / changeme</div | ||
> | ||
{/if} | ||
<div class="space-y-6"> | ||
{#if isCloudHosted()} | ||
<p class="text-xs text-tertiary italic pb-6"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.