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 crocodicstudio\crudbooster\helpers\CRUDBooster, CB; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class AuthController extends Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var \crocodicstudio\crudbooster\CBCoreModule\CbUsersRepo |
17
|
|
|
*/ |
18
|
|
|
private $usersRepo; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* AuthController constructor. |
22
|
|
|
* |
23
|
|
|
* @param \crocodicstudio\crudbooster\CBCoreModule\CbUsersRepo $usersRepo |
24
|
|
|
*/ |
25
|
|
|
public function __construct(CbUsersRepo $usersRepo) |
26
|
|
|
{ |
27
|
|
|
$this->usersRepo = $usersRepo; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $tableName |
32
|
|
|
* @return mixed |
33
|
|
|
*/ |
34
|
|
|
public function table($tableName = null) |
35
|
|
|
{ |
36
|
|
|
$tableName = $tableName ?: $this->table; |
|
|
|
|
37
|
|
|
return \DB::table($tableName); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getLogin() |
41
|
|
|
{ |
42
|
|
|
if (auth('cbAdmin')->id()) { |
|
|
|
|
43
|
|
|
return redirect(cbAdminPath()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return view('CbAuth::login'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getForgot() |
50
|
|
|
{ |
51
|
|
|
if (auth('cbAdmin')->id()) { |
|
|
|
|
52
|
|
|
return redirect()->route('CbDashboard'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return view('CbAuth::forgot'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function postForgot() |
59
|
|
|
{ |
60
|
|
|
$this->validateForgotPass(); |
61
|
|
|
|
62
|
|
|
$randString = str_random(5); |
63
|
|
|
$this->usersRepo->updateByMail(request('email'), ['password' => \Hash::make($randString)]); |
64
|
|
|
|
65
|
|
|
//$appname = cbGetsetting('appname'); |
66
|
|
|
$user = $this->usersRepo->findByMail(request('email')); |
67
|
|
|
$user->password = $randString; |
68
|
|
|
(new Mailer())->send(['to' => $user->email, 'data' => $user, 'template' => 'forgot_password_backend']); |
69
|
|
|
|
70
|
|
|
CRUDBooster::insertLog(trans('crudbooster_logging.log_forgot', ['email' => request('email'), 'ip' => Request::server('REMOTE_ADDR')])); |
71
|
|
|
|
72
|
|
|
return redirect()->route('getLogin')->with('message', cbTrans('message_forgot_password')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getLogout() |
76
|
|
|
{ |
77
|
|
|
CRUDBooster::insertLog(trans('crudbooster_logging.log_logout', ['email' => auth('cbAdmin')->user()->email])); |
|
|
|
|
78
|
|
|
auth('cbAdmin')->logout(); |
79
|
|
|
|
80
|
|
|
return redirect()->route('getLogin')->with('message', cbTrans('message_after_logout')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function validateForgotPass() |
84
|
|
|
{ |
85
|
|
|
$validator = Validator::make(request()->all(), ['email' => 'required|email|exists:cms_users',]); |
86
|
|
|
|
87
|
|
|
if ($validator->fails()) { |
88
|
|
|
$message = $validator->errors()->all(); |
89
|
|
|
backWithMsg(implode(', ', $message), 'danger'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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