-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUserCreateJob.php
More file actions
49 lines (40 loc) · 1.24 KB
/
UserCreateJob.php
File metadata and controls
49 lines (40 loc) · 1.24 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
<?php
namespace App\Jobs;
use App\TermsOfUseVersion;
use App\User;
use App\UserTermsOfUseAcceptance;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
class UserCreateJob extends Job {
private $email;
private $password;
private $verified;
public function __construct($email, $password, $verified = false) {
// TODO maybe pass in an unsaved eloquent model?
// // but that would make CLI job creation hard
$this->email = $email;
$this->password = $password;
$this->verified = false;
}
/**
* @return User
*/
public function handle() {
$user = User::create([
'email' => $this->email,
'password' => Hash::make($this->password),
'verified' => $this->verified,
]);
$latest = TermsOfUseVersion::getActiveVersion();
if ($latest) {
UserTermsOfUseAcceptance::create([
'user_id' => $user->id,
'tou_version' => $latest->version,
'tou_accepted_at' => now(),
]);
} else {
Log::warning("No active Terms of Use version found when creating user {$user->email} (ID {$user->id}).");
}
return $user;
}
}