Skip to content

Commit

Permalink
fix(docker): REON account creation script and minor documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ylambda committed Jun 14, 2024
1 parent 002e064 commit 18aff0b
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 20 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Web Service
FROM php:8.3.2-fpm as web

RUN apt-get update \
&& apt-get install -y libzip-dev sendmail \
&& docker-php-ext-install zip \
Expand All @@ -15,8 +15,11 @@ RUN sed -i '/#!\/bin\/sh/aecho "$(hostname -i)\t$(hostname) $(hostname).localhos

COPY --from=composer/composer:latest-bin /composer /usr/local/bin/composer
COPY web /var/www/reon/web
RUN cd /var/www/reon/web && composer install && chown -R www-data:www-data /var/www/reon;
WORKDIR /var/www/reon/web
RUN composer install && chown -R www-data:www-data /var/www/reon;


# Mail Service
FROM node:22.2.0 as mail
COPY mail /home/node/app
RUN cd /home/node/app && npm install
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

run:
@docker compose up --detach --build
@echo "Web server available at http://localhost:7400"
all:
@docker compose up --detach

clean:
@docker compose down

account: run
@docker compose exec web php <
account: all
@docker compose exec -w /var/www/reon/web/scripts web php add_user.php
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ This repository holds various folders for the service, and each has its own READ
3. Run tables.sql in MySQL
4. Continue these steps later once the production server is setup.

# Running Locally

A `docker-compose.yml` is provided which will run all the required services. To get started, be sure to have docker available on your system.

1. Copy `config.example.json` to `config.json`
2. Run `make` to start the services
3. Run `make account` to create an account without having to configure email delivery

### `make all` - Run all the services
Checkout http://localhost/ to see if it worked.

### `make clean` - Tear down all services

### `make account` - Create a REON user acccount
Avoids having to setup email properly

# License

This code is licenced under MIT.
6 changes: 3 additions & 3 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"hostname": "example.net",
"email_domain": "example.net",
"email_domain_dion": "xxxx.dion.ne.jp",
"mysql_host": "localhost",
"mysql_user": "USER",
"mysql_password": "PASS",
"mysql_host": "db",
"mysql_user": "reon",
"mysql_password": "password",
"mysql_database": "db",
"amoj_regist": "h200"
}
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ services:
- ./examples/nginx/default.conf.template:/etc/nginx/templates/default.conf.template
- ./web/:/var/www/reon/web
ports:
- 7400:80
- 80:80
environment:
- NGINX_PORT=80
- NGINX_HOST="localhost gameboy.datacenter.ne.jp mgb.dion.ne.jp"
- NGINX_HOST="localhost gameboy.datacenter.ne.jp"
# Hostname and port for fastcgi_pass directive
- WEB_URL=web:9000

Expand All @@ -37,10 +37,11 @@ services:
ports:
- 3306:3306
volumes:
# Run tables.sql on startup
- ./tables.sql:/docker-entrypoint-initdb.d/tables.sql:ro
- type: volume
source: reon_db
target: /var/lib/postgresql/data
target: /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=reon
Expand Down
22 changes: 16 additions & 6 deletions web/classes/UserUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ public function verifySignupRequest($id, $key) {

public function completeSignupAction($id, $key, $reonEmail, $password, $passwordConfirm) {
$email = self::$instance->verifySignupRequest($id, $key);

$result = self::$instance->createUser($email, $reonEmail, $password, $passwodConfirm);
if ($result > 0) {
return $result;
}

$stmt = $db->prepare("delete from sys_signup where email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();

return 0;
}

public function createUser($email, $reonEmail, $password, $passwordConfirm) {
if (!isset($email)) return 1;
if (!self::$instance->isDionEmailValidAndFree($reonEmail)) return 2;
if ($password != $passwordConfirm) return 3;
Expand All @@ -273,14 +287,10 @@ public function completeSignupAction($id, $key, $reonEmail, $password, $password
$dion_ppp_id = self::$instance->generatePPPId();
$log_in_password = self::$instance->generateLogInPassword();
$db = DBUtil::getInstance()->getDB();
$stmt = $db->prepare("insert into sys_users (email, password, dion_ppp_id, dion_email_local, log_in_password) values (?)");
$stmt = $db->prepare("insert into sys_users (email, password, dion_ppp_id, dion_email_local, log_in_password, money_spent) values (?, ?, ?, ?, ?, 0)");
$stmt->bind_param("sssss", $email, $password_hash, $dion_ppp_id, $reonEmail, $log_in_password);
$stmt->execute();

$stmt = $db->prepare("delete from sys_signup where email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();


return 0;
}

Expand Down
46 changes: 46 additions & 0 deletions web/scripts/add_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
include("../classes/DBUtil.php");
include("../classes/UserUtil.php");

function main() {
$db = DBUtil::getInstance()->getDB();
$user = UserUtil::getInstance();

$email = prompt("Email: ");
$password = prompt("Password: ");
$passwordConfirm = prompt("Confirm Password: ");
$reonEmail = prompt("DION Account (8 chars): ");

if (!isEmailAvailable($db, $email)) {
exit("Email is unavailable");
}

$result = $user->createUser($email, $reonEmail, $password, $passwordConfirm);

$detail = match ($result) {
0 => "Account created!",
1 => "Invalid email",
2 => "DION Email is invalid or unavailable",
3 => "Passwords do not match",
4 => "Password does not minimum requirements",
};

echo $detail."\n";
exit($result);
}

function prompt($s) {
echo $s;
return rtrim(fgets(STDIN));
}

function isEmailAvailable($db, $email) {
$stmt = $db->prepare("select id from sys_users where email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$row = $stmt->get_result()->fetch_assoc();
if (isset($row)) return false;
return true;
}

main();

0 comments on commit 18aff0b

Please sign in to comment.