1 | <?php |
||
2 | |||
3 | namespace Thinkstudeo\Rakshak; |
||
4 | |||
5 | use Illuminate\Support\Facades\Cache; |
||
6 | use Illuminate\Support\Facades\Route; |
||
7 | use Illuminate\Support\Facades\Schema; |
||
8 | use Thinkstudeo\Rakshak\Tests\Fixtures\Notifications\TemporaryPasswordMail; |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | class Rakshak |
||
11 | { |
||
12 | /** |
||
13 | * Register all routes for the package. |
||
14 | * |
||
15 | * @return void |
||
16 | */ |
||
17 | public static function routes() |
||
18 | { |
||
19 | $instance = new static; |
||
20 | |||
21 | $instance->apiRoutes(); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Load the Rakshak Settings values in Cache. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | public static function loadCache() |
||
30 | { |
||
31 | $settings = Schema::hasTable('rakshak_settings') ? RakshakSetting::first() : (object) [ |
||
32 | 'enable_2fa' => config('rakshak.enable_2fa'), |
||
33 | 'channel_2fa' => 'email', |
||
34 | 'control_level_2fa' => 'admin', |
||
35 | ]; |
||
36 | |||
37 | Cache::forever('rakshak.enable_2fa', $settings->enable_2fa); |
||
38 | Cache::forever('rakshak.channel_2fa', $settings->channel_2fa); |
||
39 | Cache::forever('rakshak.control_level_2fa', $settings->control_level_2fa); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Retister the api routes. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | public function apiRoutes() |
||
48 | { |
||
49 | Route::namespace('\Thinkstudeo\Rakshak\Http\Controllers') |
||
50 | ->middleware(['web', 'auth']) |
||
51 | ->prefix(config('rakshak.route_prefix')) |
||
52 | ->group(function () { |
||
53 | Route::get('login/2fa', 'TwoFactorController@showOtpForm')->name('rakshak.2fa.show'); |
||
54 | Route::post('login/2fa/verify', 'TwoFactorController@verifyOtp')->name('rakshak.2fa.verify'); |
||
55 | |||
56 | Route::resource('roles', 'RolesController', ['as' => 'rakshak']); |
||
57 | |||
58 | Route::resource('abilities', 'AbilitiesController', ['as' => 'rakshak']); |
||
59 | |||
60 | Route::get('settings', 'RakshakSettingsController@edit')->name('rakshak.settings.edit'); |
||
61 | Route::put('settings', 'RakshakSettingsController@update')->name('rakshak.settings.update'); |
||
62 | }); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Generate a 6 digit random number to be sent as OTP. |
||
67 | * |
||
68 | * @return number |
||
69 | */ |
||
70 | public static function generateOtp() |
||
71 | { |
||
72 | return mt_rand(100000, 999999); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Send the generated OTP to the user via the configured channel. |
||
77 | * |
||
78 | * @param User $user |
||
0 ignored issues
–
show
The type
Thinkstudeo\Rakshak\User was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
79 | * @return void |
||
80 | */ |
||
81 | public static function sendOtp($user) |
||
82 | { |
||
83 | $channel = Cache::get('rakshak.channel_2fa'); |
||
84 | |||
85 | $notifications = config('rakshak.login.'.$channel); |
||
86 | |||
87 | foreach ($notifications as $notification) { |
||
88 | return $user->notify(new $notification); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Send an email with instructions for temporary password |
||
94 | * when a user is created by the admin. |
||
95 | * |
||
96 | * @param \Illuminate\Database\Eloquent\Model $user |
||
97 | * @return void |
||
98 | */ |
||
99 | public static function sendTemporaryPassword($user) |
||
100 | { |
||
101 | return $user->notify(new TemporaryPasswordMail); |
||
0 ignored issues
–
show
|
|||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get the path to the showVerifyOtpForm. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public static function verifyOtpPath() |
||
110 | { |
||
111 | return 'login/2fa'; |
||
112 | } |
||
113 | } |
||
114 |
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