diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/newuser | 36 |
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 |
