diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-04-27 09:52:34 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-04-27 09:52:34 -0400 |
commit | e5a2850b6bb9887b241316be24b3f7047cef6ea3 (patch) | |
tree | b4b2f8b73200d24d1247a44fe522f832e6be103e | |
parent | 6cf8d2b298b0770b46753a902b4c5622b5b1ddd2 (diff) | |
download | levitating-e5a2850b6bb9887b241316be24b3f7047cef6ea3.tar.gz levitating-e5a2850b6bb9887b241316be24b3f7047cef6ea3.zip |
Added command line args to create an admin user. Fixed a few db bugs.
-rw-r--r-- | captain/captain.f90 | 28 | ||||
-rw-r--r-- | captain/db.f90 | 11 | ||||
-rw-r--r-- | captain/levitating-captain.prj | 2 | ||||
-rw-r--r-- | captain/sql/create.sql | 2 |
4 files changed, 39 insertions, 4 deletions
diff --git a/captain/captain.f90 b/captain/captain.f90 index 94b2f96..6713a9e 100644 --- a/captain/captain.f90 +++ b/captain/captain.f90 @@ -70,6 +70,8 @@ contains Print *, " -c <configfile> Use the specified config file" Print *, " -g Operate in Gemini mode" Print *, " -w Operate in CGI mode (default)" + Print *, " --new-admin <username> <password>" + Print *, " Add a new administrator to the system" Print *, " " Print *, "Config file can also be specified via the environment variables:" Print *, " LEVITATING_CONFIG_CGI Path to config for CGI mode" @@ -80,9 +82,11 @@ contains subroutine parse_options use config use m_crypt + use captain_db, only: new_admin_db implicit none - character(len=1024)::option, tmp + character(len=1024)::option, username, password + character(len=:), pointer::tmp logical::config_loaded integer::i @@ -112,12 +116,32 @@ contains else if(trim(option) == "--hash") then i = i + 1 call get_command_argument(i, option) - tmp = hash(option) + tmp => hash(option) Print *, "Hash: "//trim(tmp) Print *, "Verify: "//trim(option), verify_hash(trim(option), tmp) Print *, "Unverify: "//trim(option)//"X", verify_hash(trim(option)//"X", tmp) stop + else if(trim(option) == "--new-admin") then + + ! Config better be loaded by now... + if(config_loaded) then + call initialize_db(database_filename) + + i = i + 1 + call get_command_argument(i, username) + i = i + 1 + call get_command_argument(i, password) + if(new_admin_db(trim(username), trim(password))) then + Print *, "Admin '"//trim(username)//"' added successfully!" + else + Print *, "Operation failed." + end if + else + Print *, "Please specify the configuration file first" + end if + stop + end if i = i + 1 diff --git a/captain/db.f90 b/captain/db.f90 index 00ec00e..77e12ed 100644 --- a/captain/db.f90 +++ b/captain/db.f90 @@ -1438,6 +1438,17 @@ contains end function new_user_db + function new_admin_db(username, password) + use AUTH_LEVELS, only: AUTH_ADMIN_USER + implicit none + + character(len=*), intent(in)::username, password + logical::new_admin_db + + new_admin_db = new_user_db(username, password, trim(username)//"@localhost", AUTH_ADMIN_USER) + + end function new_admin_db + function get_password_hash_pointer_db(username) result(password) implicit none diff --git a/captain/levitating-captain.prj b/captain/levitating-captain.prj index e55447f..33003dd 100644 --- a/captain/levitating-captain.prj +++ b/captain/levitating-captain.prj @@ -184,7 +184,7 @@ "Launch Using MPI":"false", "Keep Console":"true", "External Console":"false", - "Command Line Arguments":"", + "Command Line Arguments":"-c example/levitating.conf --new-admin jeff password", "Build Before Launch":"true" }, "Build Options":{ diff --git a/captain/sql/create.sql b/captain/sql/create.sql index 9e4d204..7517e07 100644 --- a/captain/sql/create.sql +++ b/captain/sql/create.sql @@ -17,7 +17,7 @@ CREATE TABLE checkin(player INTEGER PRIMARY KEY, year INTEGER, month INTEGER, da CREATE TABLE schedule(instruction INTEGER NOT NULL, player INTEGER NOT NULL, day INTEGER DEFAULT 0, hour INTEGER DEFAULT 0, FOREIGN KEY(instruction) REFERENCES instructions(id) ON DELETE CASCADE, FOREIGN KEY(player) REFERENCES players(id) ON DELETE CASCADE ); -CREATE TABLE users(id INTEGER PRIMARY KEY, username TEXT UNIQUE NOT NULL, email TEXT NOT NULL, password TEXT NOT NULL, level INTEGER DEFAULT 1); +CREATE TABLE users(id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT UNIQUE NOT NULL, email TEXT NOT NULL, password TEXT NOT NULL, level INTEGER DEFAULT 1); CREATE TABLE sessions(user INTEGER, session TEXT NOT NULL, expiration TEXT NOT NULL, FOREIGN KEY(user) REFERENCES users(id) ON DELETE CASCADE); |