Compare commits
4 Commits
v0.6.6-mai
...
76f7bbc9e2
| Author | SHA1 | Date | |
|---|---|---|---|
|
76f7bbc9e2
|
|||
|
34687dda7d
|
|||
|
6c83e566bf
|
|||
|
b74c0fc3b0
|
@@ -10,3 +10,4 @@ POSTGRES_AUTH_PASSWORD=password
|
||||
POSTGRES_AUTH_DB=icarus_auth_db
|
||||
POSTGRES_AUTH_HOST=auth_db
|
||||
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
||||
ENABLE_REGISTRATION=TRUE
|
||||
|
||||
@@ -10,3 +10,4 @@ POSTGRES_AUTH_PASSWORD=password
|
||||
POSTGRES_AUTH_DB=icarus_auth_test_db
|
||||
POSTGRES_AUTH_HOST=localhost
|
||||
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
||||
ENABLE_REGISTRATION=TRUE
|
||||
12
README.md
12
README.md
@@ -8,22 +8,26 @@ need to be modified. The `SECRET_KEY` variable should be changed since it will b
|
||||
generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure
|
||||
the respective `passphrase` database table record exists.
|
||||
|
||||
Build image
|
||||
To enable or disable registrations, use `TRUE` or `FALSE` for the `ENABLE_REGISTRATION` variable.
|
||||
By default it is `TRUE`.
|
||||
|
||||
|
||||
### Build image
|
||||
```
|
||||
docker compose build
|
||||
```
|
||||
|
||||
Start images
|
||||
### Start images
|
||||
```
|
||||
docker compose up -d --force-recreate
|
||||
```
|
||||
|
||||
Bring it down
|
||||
### Bring it down
|
||||
```
|
||||
docker compose down -v
|
||||
```
|
||||
|
||||
Pruning
|
||||
### Pruning
|
||||
```
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
@@ -52,67 +52,74 @@ pub async fn register_user(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
Json(payload): Json<request::Request>,
|
||||
) -> (StatusCode, Json<response::Response>) {
|
||||
let mut user = icarus_models::user::User {
|
||||
username: payload.username.clone(),
|
||||
password: payload.password.clone(),
|
||||
email: payload.email.clone(),
|
||||
phone: payload.phone.clone(),
|
||||
firstname: payload.firstname.clone(),
|
||||
lastname: payload.lastname.clone(),
|
||||
status: String::from("Active"),
|
||||
email_verified: true,
|
||||
..Default::default()
|
||||
};
|
||||
if is_registration_enabled() {
|
||||
let mut user = icarus_models::user::User {
|
||||
username: payload.username.clone(),
|
||||
password: payload.password.clone(),
|
||||
email: payload.email.clone(),
|
||||
phone: payload.phone.clone(),
|
||||
firstname: payload.firstname.clone(),
|
||||
lastname: payload.lastname.clone(),
|
||||
status: String::from("Active"),
|
||||
email_verified: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match repo::user::exists(&pool, &user.username).await {
|
||||
Ok(res) => {
|
||||
if res {
|
||||
(
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
message: String::from("Error"),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
let salt_string = hashing::generate_salt().unwrap();
|
||||
let mut salt = icarus_models::user::salt::Salt::default();
|
||||
let generated_salt = salt_string;
|
||||
salt.salt = generated_salt.to_string();
|
||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||
user.salt_id = salt.id;
|
||||
let hashed_password =
|
||||
hashing::hash_password(&user.password, &generated_salt).unwrap();
|
||||
user.password = hashed_password;
|
||||
|
||||
match repo::user::insert(&pool, &user).await {
|
||||
Ok((id, date_created)) => {
|
||||
user.id = id;
|
||||
user.date_created = date_created;
|
||||
(
|
||||
StatusCode::CREATED,
|
||||
Json(response::Response {
|
||||
message: String::from("User created"),
|
||||
data: vec![user],
|
||||
}),
|
||||
)
|
||||
}
|
||||
Err(err) => (
|
||||
match repo::user::exists(&pool, &user.username).await {
|
||||
Ok(res) => {
|
||||
if res {
|
||||
(
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
message: err.to_string(),
|
||||
data: vec![user],
|
||||
message: String::from("Error"),
|
||||
data: Vec::new(),
|
||||
}),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
let salt_string = hashing::generate_salt().unwrap();
|
||||
let mut salt = icarus_models::user::salt::Salt::default();
|
||||
let generated_salt = salt_string;
|
||||
salt.salt = generated_salt.to_string();
|
||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||
user.salt_id = salt.id;
|
||||
let hashed_password =
|
||||
hashing::hash_password(&user.password, &generated_salt).unwrap();
|
||||
user.password = hashed_password;
|
||||
|
||||
match repo::user::insert(&pool, &user).await {
|
||||
Ok((id, date_created)) => {
|
||||
user.id = id;
|
||||
user.date_created = date_created;
|
||||
(
|
||||
StatusCode::CREATED,
|
||||
Json(response::Response {
|
||||
message: String::from("User created"),
|
||||
data: vec![user],
|
||||
}),
|
||||
)
|
||||
}
|
||||
Err(err) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
message: err.to_string(),
|
||||
data: vec![user],
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
message: err.to_string(),
|
||||
data: vec![user],
|
||||
}),
|
||||
),
|
||||
}
|
||||
Err(err) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
message: err.to_string(),
|
||||
data: vec![user],
|
||||
}),
|
||||
),
|
||||
} else {
|
||||
(axum::http::StatusCode::NOT_ACCEPTABLE, Json(response::Response{
|
||||
message: String::from("Registration is not enabled"),
|
||||
data:: Vec::new()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user