1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace crocodicstudio\crudbooster\Modules\AuthModule; |
4
|
|
|
|
5
|
|
|
use crocodicstudio\crudbooster\CBCoreModule\CbUsersRepo; |
6
|
|
|
use crocodicstudio\crudbooster\controllers\Controller; |
7
|
|
|
use crocodicstudio\crudbooster\helpers\Mailer; |
8
|
|
|
use Illuminate\Support\Facades\Request; |
9
|
|
|
use Illuminate\Support\Facades\Session; |
10
|
|
|
use Illuminate\Support\Facades\Validator; |
11
|
|
|
use CRUDBooster; |
|
|
|
|
12
|
|
|
use CB; |
13
|
|
|
|
14
|
|
|
class AuthController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param null $tableName |
|
|
|
|
18
|
|
|
* @return mixed |
19
|
|
|
*/ |
20
|
|
|
public function table($tableName = null) |
21
|
|
|
{ |
22
|
|
|
$tableName = $tableName ?: $this->table; |
|
|
|
|
23
|
|
|
return \DB::table($tableName); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function getIndex() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
return view('CbAuth::home', ['page_title' => '<strong>Dashboard</strong>']); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getLockscreen() |
32
|
|
|
{ |
33
|
|
|
if (! CRUDBooster::myId()) { |
34
|
|
|
Session::flush(); |
35
|
|
|
return redirect()->route('getLogin')->with('message', cbTrans('alert_session_expired')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
Session::put('admin_lock', 1); |
39
|
|
|
return view('CbAuth::lockscreen'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function postUnlockScreen() |
43
|
|
|
{ |
44
|
|
|
$user = CbUsersRepo::find(CRUDBooster::myId()); |
45
|
|
|
|
46
|
|
|
if (\Hash::check(request('password'), $user->password)) { |
|
|
|
|
47
|
|
|
Session::put('admin_lock', 0); |
48
|
|
|
|
49
|
|
|
return redirect()->route('AuthControllerGetIndex'); |
50
|
|
|
} |
51
|
|
|
echo "<script>alert('".cbTrans('alert_password_wrong')."');history.go(-1);</script>"; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getLogin() |
55
|
|
|
{ |
56
|
|
|
if (CRUDBooster::myId()) { |
57
|
|
|
return redirect(cbAdminPath()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return view('CbAuth::login'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getForgot() |
64
|
|
|
{ |
65
|
|
|
if (CRUDBooster::myId()) { |
66
|
|
|
return redirect()->action('\\'.AuthController::class.'@getIndex'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return view('CbAuth::forgot'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function postForgot() |
73
|
|
|
{ |
74
|
|
|
$this->validateForgotPass(); |
75
|
|
|
|
76
|
|
|
$randString = str_random(5); |
77
|
|
|
CbUsersRepo::updateByMail(request('email'), ['password' => \Hash::make($randString)]); |
78
|
|
|
|
79
|
|
|
//$appname = cbGetsetting('appname'); |
80
|
|
|
$user = CbUsersRepo::findByMail(request('email')); |
81
|
|
|
$user->password = $randString; |
82
|
|
|
(new Mailer())->send(['to' => $user->email, 'data' => $user, 'template' => 'forgot_password_backend']); |
83
|
|
|
|
84
|
|
|
CRUDBooster::insertLog(cbTrans('log_forgot', ['email' => request('email'), 'ip' => Request::server('REMOTE_ADDR')])); |
85
|
|
|
|
86
|
|
|
return redirect()->route('getLogin')->with('message', cbTrans('message_forgot_password')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getLogout() |
90
|
|
|
{ |
91
|
|
|
CRUDBooster::insertLog(cbTrans('log_logout', ['email' => CRUDBooster::me()->email])); |
92
|
|
|
Session::flush(); |
93
|
|
|
|
94
|
|
|
return redirect()->route('getLogin')->with('message', cbTrans('message_after_logout')); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function validateForgotPass() |
98
|
|
|
{ |
99
|
|
|
$validator = Validator::make(request()->all(), ['email' => 'required|email|exists:cms_users',]); |
100
|
|
|
|
101
|
|
|
if ($validator->fails()) { |
102
|
|
|
$message = $validator->errors()->all(); |
103
|
|
|
backWithMsg(implode(', ', $message), 'danger'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths