Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117923686
D4613.1775440497.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D4613.1775440497.diff
View Options
diff --git a/src/app/Console/Commands/User/CreateCommand.php b/src/app/Console/Commands/User/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/CreateCommand.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use Illuminate\Support\Facades\DB;
+use App\Http\Controllers\API\V4\UsersController;
+
+class CreateCommand extends \App\Console\Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:create {email} {--package=*} {--password=?} {--admin}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Create a user.";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $email = $this->argument('email');
+ $packages = $this->option('package');
+ $admin = $this->option('admin');
+ $password = $this->option('password');
+
+ list($local, $domainName) = explode('@', $email, 2);
+
+ $domain = $this->getDomain($domainName);
+
+ if (!$domain) {
+ $this->error("No such domain {$domainName}.");
+ return 1;
+ }
+
+ if ($domain->isPublic()) {
+ $this->error("Domain {$domainName} is public.");
+ return 1;
+ }
+
+ $owner = $domain->wallet()->owner;
+
+ // Validate email address
+ if ($error = UsersController::validateEmail($email, $owner)) {
+ $this->error("{$email}: {$error}");
+ return 1;
+ }
+
+ DB::beginTransaction();
+
+ $role = null;
+ if ($admin) {
+ $role = 'admin';
+ }
+
+ if (!$password) {
+ $password = \App\Utils::generatePassphrase();
+ }
+
+ $user = \App\User::create(
+ [
+ 'email' => $email,
+ 'password' => $password,
+ 'role' => $role
+ ]
+ );
+
+ foreach ($packages as $i => $package) {
+ $userPackage = \App\Package::where(['title' => $package])->first();
+ if (!$userPackage) {
+ $this->error("Invalid package: {$package}");
+ return 1;
+ }
+ $user->assignPackage($userPackage);
+ }
+
+ DB::commit();
+
+ $this->info($user->id);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 1:54 AM (20 h, 15 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18833954
Default Alt Text
D4613.1775440497.diff (2 KB)
Attached To
Mode
D4613: A user create command
Attached
Detach File
Event Timeline