Compare commits
4 Commits
v0.6.3-mai
...
4d9e199c13
| Author | SHA1 | Date | |
|---|---|---|---|
|
4d9e199c13
|
|||
|
334c0bfc4a
|
|||
|
44f9655ac7
|
|||
|
0cf082996d
|
@@ -10,4 +10,3 @@ POSTGRES_AUTH_PASSWORD=password
|
|||||||
POSTGRES_AUTH_DB=icarus_auth_db
|
POSTGRES_AUTH_DB=icarus_auth_db
|
||||||
POSTGRES_AUTH_HOST=auth_db
|
POSTGRES_AUTH_HOST=auth_db
|
||||||
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
||||||
ENABLE_REGISTRATION=TRUE
|
|
||||||
|
|||||||
@@ -10,4 +10,3 @@ POSTGRES_AUTH_PASSWORD=password
|
|||||||
POSTGRES_AUTH_DB=icarus_auth_test_db
|
POSTGRES_AUTH_DB=icarus_auth_test_db
|
||||||
POSTGRES_AUTH_HOST=localhost
|
POSTGRES_AUTH_HOST=localhost
|
||||||
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
||||||
ENABLE_REGISTRATION=TRUE
|
|
||||||
@@ -3,7 +3,7 @@ name: Release Tagging
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- devel
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
@@ -27,10 +27,8 @@ jobs:
|
|||||||
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
||||||
BRANCH_REF="${GITHUB_REF}"
|
BRANCH_REF="${GITHUB_REF}"
|
||||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||||
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-950"
|
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH"
|
||||||
|
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-950"
|
||||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
|
|
||||||
|
|
||||||
echo "Version: $VERSION"
|
echo "Version: $VERSION"
|
||||||
echo "Hash: $PROJECT_COMMIT_HASH"
|
echo "Hash: $PROJECT_COMMIT_HASH"
|
||||||
echo "Branch: $BRANCH_NAME"
|
echo "Branch: $BRANCH_NAME"
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ jobs:
|
|||||||
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||||
# Make SSH agent available if tests fetch private dependencies
|
# Make SSH agent available if tests fetch private dependencies
|
||||||
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
||||||
ENABLE_REGISTRATION: 'TRUE'
|
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -748,7 +748,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.6.3"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"axum",
|
"axum",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.6.3"
|
version = "0.6.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -8,26 +8,22 @@ 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
|
generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure
|
||||||
the respective `passphrase` database table record exists.
|
the respective `passphrase` database table record exists.
|
||||||
|
|
||||||
To enable or disable registrations, use `TRUE` or `FALSE` for the `ENABLE_REGISTRATION` variable.
|
Build image
|
||||||
By default it is `TRUE`.
|
|
||||||
|
|
||||||
|
|
||||||
### Build image
|
|
||||||
```
|
```
|
||||||
docker compose build
|
docker compose build
|
||||||
```
|
```
|
||||||
|
|
||||||
### Start images
|
Start images
|
||||||
```
|
```
|
||||||
docker compose up -d --force-recreate
|
docker compose up -d --force-recreate
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bring it down
|
Bring it down
|
||||||
```
|
```
|
||||||
docker compose down -v
|
docker compose down -v
|
||||||
```
|
```
|
||||||
|
|
||||||
### Pruning
|
Pruning
|
||||||
```
|
```
|
||||||
docker system prune -a
|
docker system prune -a
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -52,22 +52,8 @@ pub async fn register_user(
|
|||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
Json(payload): Json<request::Request>,
|
Json(payload): Json<request::Request>,
|
||||||
) -> (StatusCode, Json<response::Response>) {
|
) -> (StatusCode, Json<response::Response>) {
|
||||||
let registration_enabled = match is_registration_enabled().await {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Error: {err:?}");
|
|
||||||
return (
|
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
Json(response::Response {
|
|
||||||
message: String::from("Registration check failed"),
|
|
||||||
data: Vec::new(),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if registration_enabled {
|
|
||||||
let mut user = icarus_models::user::User {
|
let mut user = icarus_models::user::User {
|
||||||
|
id: uuid::Uuid::nil(),
|
||||||
username: payload.username.clone(),
|
username: payload.username.clone(),
|
||||||
password: payload.password.clone(),
|
password: payload.password.clone(),
|
||||||
email: payload.email.clone(),
|
email: payload.email.clone(),
|
||||||
@@ -76,17 +62,19 @@ pub async fn register_user(
|
|||||||
lastname: payload.lastname.clone(),
|
lastname: payload.lastname.clone(),
|
||||||
status: String::from("Active"),
|
status: String::from("Active"),
|
||||||
email_verified: true,
|
email_verified: true,
|
||||||
..Default::default()
|
date_created: Some(time::OffsetDateTime::now_utc()),
|
||||||
|
last_login: None,
|
||||||
|
salt_id: uuid::Uuid::nil(),
|
||||||
};
|
};
|
||||||
|
|
||||||
match repo::user::exists(&pool, &user.username).await {
|
match repo::user::exists(&pool, &user.username).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if res {
|
if res {
|
||||||
(
|
(
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::NOT_FOUND,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
message: String::from("Error"),
|
message: String::from("Error"),
|
||||||
data: Vec::new(),
|
data: vec![user],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -101,9 +89,8 @@ pub async fn register_user(
|
|||||||
user.password = hashed_password;
|
user.password = hashed_password;
|
||||||
|
|
||||||
match repo::user::insert(&pool, &user).await {
|
match repo::user::insert(&pool, &user).await {
|
||||||
Ok((id, date_created)) => {
|
Ok(id) => {
|
||||||
user.id = id;
|
user.id = id;
|
||||||
user.date_created = date_created;
|
|
||||||
(
|
(
|
||||||
StatusCode::CREATED,
|
StatusCode::CREATED,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
@@ -130,30 +117,4 @@ pub async fn register_user(
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
(
|
|
||||||
axum::http::StatusCode::NOT_ACCEPTABLE,
|
|
||||||
Json(response::Response {
|
|
||||||
message: String::from("Registration is not enabled"),
|
|
||||||
data: Vec::new(),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks to see if registration is enabled
|
|
||||||
async fn is_registration_enabled() -> Result<bool, std::io::Error> {
|
|
||||||
let key = String::from("ENABLE_REGISTRATION");
|
|
||||||
let var = icarus_envy::environment::get_env(&key).await;
|
|
||||||
let parsed_value = var.value.to_uppercase();
|
|
||||||
|
|
||||||
if parsed_value == "TRUE" {
|
|
||||||
Ok(true)
|
|
||||||
} else if parsed_value == "FALSE" {
|
|
||||||
Ok(false)
|
|
||||||
} else {
|
|
||||||
Err(std::io::Error::other(
|
|
||||||
"Could not determine value of ENABLE_REGISTRATION",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ pub mod user {
|
|||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
user: &icarus_models::user::User,
|
user: &icarus_models::user::User,
|
||||||
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
let row = sqlx::query(
|
let row = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, salt_id)
|
INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, salt_id)
|
||||||
@@ -124,10 +124,10 @@ pub mod user {
|
|||||||
.map_err(|_e| sqlx::Error::RowNotFound)?,
|
.map_err(|_e| sqlx::Error::RowNotFound)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
if result.id.is_nil() && result.date_created.is_none() {
|
if !result.id.is_nil() {
|
||||||
Err(sqlx::Error::RowNotFound)
|
Ok(result.id)
|
||||||
} else {
|
} else {
|
||||||
Ok((result.id, result.date_created))
|
Err(sqlx::Error::RowNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user