aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin
diff options
context:
space:
mode:
authorwinter2025-01-19 00:25:52 +0000
committerwinter2025-01-19 00:28:52 +0000
commit2de5125d750a24d85797c5c7bb15fefdc0206511 (patch)
treebccafe3232f340f6f3e12803ba532aa7dce46f58 /bin
parentb4ca320fe7d082ab2a8d32191aa13c74af5735d6 (diff)
add newuser script
Diffstat (limited to 'bin')
-rwxr-xr-xbin/newuser36
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/newuser b/bin/newuser
new file mode 100755
index 0000000..165a598
--- /dev/null
+++ b/bin/newuser
@@ -0,0 +1,36 @@
+#!/usr/bin/env php
+<?php
+
+require __DIR__ . '/../vendor/autoload.php';
+foreach (glob(__DIR__ . '/../misc/*.php') as $filename) {
+ require $filename;
+}
+
+use Digitigrade\Model\Actor;
+use Digitigrade\Model\UserAccount;
+
+if ($argc != 4) {
+ error_log('usage: bin/newuser <handle> <email> <password>');
+ exit(1);
+}
+
+$handle = $argv[1];
+$email = $argv[2];
+$password = $argv[3];
+$admin = UserAccount::count() <= 0; // make admin if there aren't any other users
+
+if (Actor::findLocalByHandle($handle) != null) {
+ error_log("there is already a local user with handle @$handle!");
+ exit(1);
+}
+if (UserAccount::findByEmail($email) != null) {
+ error_log("there is already a local user with email address $email!");
+ exit(1);
+}
+
+$user = UserAccount::create($email, $password);
+$user->createLinkedActor($handle);
+$user->isAdmin = $admin;
+$user->save();
+
+echo "created user @$handle" . ($admin ? ' with admin permissions' : '') . "\n"; \ No newline at end of file