1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\User; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use Illuminate\Support\Facades\Log; |
7
|
|
|
|
8
|
|
|
use Carbon\Carbon; |
9
|
|
|
|
10
|
|
|
use App\User; |
11
|
|
|
use App\UserSettings; |
12
|
|
|
|
13
|
|
|
class SetUserDetails |
14
|
|
|
{ |
15
|
|
|
// Update a users primary details (name and email address) |
16
|
4 |
|
public function updateUser($request, $userID) |
17
|
|
|
{ |
18
|
4 |
|
User::find($userID)->update($request->toArray()); |
19
|
4 |
|
Log::notice('User ID '.$userID.' has been updated by '.Auth::user()->full_name.'. Details - ', $request->toArray()); |
20
|
|
|
|
21
|
4 |
|
return true; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// Update the notification settings for when the user gets an email or dashboard notification |
25
|
4 |
|
public function updateSettings($request, $userID) |
26
|
|
|
{ |
27
|
4 |
|
UserSettings::where('user_id', $userID)->update($request->toArray()); |
28
|
4 |
|
Log::notice('Settings for User ID '.$userID.' have been updated by '.Auth::user()->full_name.'. Details - ', $request->toArray()); |
29
|
|
|
|
30
|
4 |
|
return true; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Update the users password |
34
|
6 |
|
public function updatePassword($password, $userID, $forceChange = false) |
35
|
|
|
{ |
36
|
|
|
// Determine if there is a new password expire's date (only triggered by an administrator) |
37
|
6 |
|
if(!$forceChange) |
38
|
|
|
{ |
39
|
4 |
|
$newExpire = config('auth.passwords.settings.expire') != null ? |
40
|
4 |
|
Carbon::now()->addDays(config('auth.passwords.settings.expire')) : null; |
41
|
|
|
} |
42
|
|
|
else |
43
|
|
|
{ |
44
|
2 |
|
$newExpire = Carbon::now()->subDay(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Update the users password |
48
|
6 |
|
User::find($userID)->update([ |
49
|
6 |
|
'password' => bcrypt($password), |
50
|
6 |
|
'password_expires' => $newExpire, |
51
|
|
|
]); |
52
|
|
|
|
53
|
6 |
|
Log::notice('Password has been changed for User ID '.$userID.' by '.Auth::user()->full_name); |
54
|
6 |
|
return true; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|