Skip to content

Commit

Permalink
Merge pull request #83 from refactor-group/add_default_user
Browse files Browse the repository at this point in the history
Add an initial Admin platform user
  • Loading branch information
jhodapp authored Dec 9, 2024
2 parents 3f446be + 2fac6b1 commit 36b4948
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ FROM debian:stable-slim AS runtime
RUN apt-get update && apt-get install -y \
libssl3 \
libpq5 \
postgresql-client-15 \
bash \
&& rm -rf /var/lib/apt/lists/*

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- postgres_data:/var/lib/postgresql/data # Persist PostgreSQL data
- ./migration/src/setup.sql:/docker-entrypoint-initdb.d/0-setup.sql # Initialize database with setup.sql
- ./migration/src/refactor_platform_rs.sql:/docker-entrypoint-initdb.d/1-refactor_plaform_rs.sql # Initialize with refactor_platform_rs.sql
- ./migration/src/setup_default_user.sql:/docker-entrypoint-initdb.d/2-setup_default_user.sql # Initialize with setup_default_user.sql
networks:
- backend_network # Connect to backend_network

Expand Down
16 changes: 16 additions & 0 deletions entity_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ pub(crate) fn naive_date_parse_str(date_str: &str) -> Result<chrono::NaiveDate,
pub async fn seed_database(db: &DatabaseConnection) {
let now = Utc::now();

let _admin_user: users::ActiveModel = users::ActiveModel {
email: Set("[email protected]".to_owned()),
first_name: Set(Some("Admin".to_owned())),
last_name: Set(Some("User".to_owned())),
display_name: Set(Some("Admin User".to_owned())),
password: Set(generate_hash("dLxNxnjn&b!2sqkwFbb4s8jX")),
github_username: Set(None),
github_profile_url: Set(None),
created_at: Set(now.into()),
updated_at: Set(now.into()),
..Default::default()
}
.save(db)
.await
.unwrap();

let jim_hodapp: users::ActiveModel = users::ActiveModel {
email: Set("[email protected]".to_owned()),
first_name: Set(Some("Jim".to_owned())),
Expand Down
2 changes: 1 addition & 1 deletion migration/src/refactor_platform_rs.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- SQL dump generated using DBML (dbml-lang.org)
-- Database: PostgreSQL
-- Generated at: 2024-10-31T16:04:10.825Z
-- Generated at: 2024-12-09T16:59:54.815Z


CREATE TYPE "status" AS ENUM (
Expand Down
21 changes: 21 additions & 0 deletions migration/src/setup_default_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- IMPORTANT: to prevent a security issue, the following initial platform user's password
-- needs to be changed after the postgres service container is created.
-- The password hash params are password and a random salt value.
INSERT INTO refactor_platform.users (
display_name,
email,
first_name,
last_name,
github_profile_url,
github_username,
password
)
VALUES (
'Admin',
'[email protected]',
'Admin',
'User',
'#',
'',
'$argon2id$v=19$m=19456,t=2,p=1$x4aqeh1xRaYsgeo0I5kB3A$gQz+ARyx7e6WjCNyNkOXNYFnLnc1eWqHXY+ASmJ7PDM'
);
3 changes: 2 additions & 1 deletion web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ pub async fn init_server(app_state: AppState) -> Result<()> {
CONTENT_TYPE,
])
.expose_headers([ApiVersion::field_name().parse::<HeaderName>().unwrap()])
.allow_origin("http://localhost:3000".parse::<HeaderValue>().unwrap());
.allow_origin("http://localhost:3000".parse::<HeaderValue>().unwrap())
.allow_origin("http://localhost:3001".parse::<HeaderValue>().unwrap());

axum::serve(
listener,
Expand Down

0 comments on commit 36b4948

Please sign in to comment.