-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDisable.php
More file actions
69 lines (49 loc) · 1.85 KB
/
Disable.php
File metadata and controls
69 lines (49 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace App\Console\Commands\User;
/**
* Disables a user account, deletes information about their email address and their password hash.
* Requires the user to manage zero wikis.
*/
use App\User;
use App\WikiManager;
use Illuminate\Console\Command;
class Disable extends Command {
protected $signature = 'wbs-user:disable {--email=}';
protected $description = 'Disable user account';
public function handle(): int {
$email = $this->option('email');
$user = User::whereEmail($email)->first();
if (empty($email)) {
$this->error("Error: no email address provided. usage: wbs-user:disable --email='mail@address.com'");
return 1;
}
if (!$user) {
$this->error("Error: Could not find a user for '$email'.");
return 2;
}
$userWikiManagers = WikiManager::whereUserId($user->id)->with('wiki')->get();
$undeletedWikis = [];
foreach ($userWikiManagers as $userWikiManager) {
$userWiki = $userWikiManager->wiki;
if ($userWiki !== null) {
$undeletedWikis[] = $userWiki->domain;
}
}
if (!empty($undeletedWikis)) {
$this->error('Error: User still has wikis: ' . print_r($undeletedWikis, true));
return 3;
}
$userId = $user->id;
$user->email = uniqid() . '@disabled-user.wikibase.cloud';
$user->password = random_bytes(10);
$user->verified = false;
if ($user->save()) {
$this->info("Successfully disabled user account with email '$email' (id: '$userId')");
$this->info('Information about email and password hash was deleted.');
return 0;
} else {
$this->error('Error: Failed to save changes to the database.');
return 4;
}
}
}