|
1 | 1 | <?php |
| 2 | + |
2 | 3 | namespace App\Controllers; |
3 | 4 |
|
4 | 5 | // Leaf Auth is a package which makes user authentication simple |
5 | 6 | use Leaf\Auth; |
6 | | -use Leaf\Helpers\Password; |
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * This is the base controller for your Leaf API Project. |
10 | 10 | * You can initialize packages or define methods here to use |
11 | 11 | * them across all your other controllers which extend this one. |
12 | 12 | */ |
13 | | -class Controller extends \Leaf\ApiController { |
14 | | - public $auth; |
15 | | - |
16 | | - public function __construct() { |
| 13 | +class Controller extends \Leaf\ApiController |
| 14 | +{ |
| 15 | + public function __construct() |
| 16 | + { |
17 | 17 | parent::__construct(); |
18 | 18 |
|
19 | 19 | // In this version, request isn't initialised for you. You can use |
20 | 20 | // requestData() or request() to get request data or initialise it yourself |
21 | | - $this->auth = new Auth; |
22 | 21 |
|
23 | 22 | // autoConnect uses the .env variables to quickly connect to db |
24 | | - $this->auth->autoConnect(); |
25 | | - |
| 23 | + Auth::autoConnect(); |
| 24 | + |
26 | 25 | // set default token expiry time |
27 | | - $this->auth->tokenLifetime(60 * 60 * 24 * 365); |
| 26 | + Auth::tokenLifetime(60 * 60 * 24 * 365); |
28 | 27 |
|
29 | 28 | // You can configure auth to get additional customizations |
30 | | - $this->auth->config("LOGIN_PARAMS_ERROR", "Username not registered!"); |
31 | | - |
32 | | - // Password encode is run when leaf wants to encode passwords on register |
33 | | - // This exact method is used by default in Leaf, so you can delete it if |
34 | | - // you want to. |
35 | | - $this->auth->config("PASSWORD_ENCODE", function ($password) { |
36 | | - return Password::hash($password); |
37 | | - }); |
38 | | - |
39 | | - // this function is run to verify the password. It's done by default, |
40 | | - // so you can remove this line and the above line if you wish to. |
41 | | - $this->auth->config("PASSWORD_VERIFY", function ($password, $hashedPassword) { |
42 | | - // Inside the password_verify method, you have access to the password and the hashed password |
43 | | - return Password::verify($password, $hashedPassword); |
44 | | - }); |
45 | | - |
46 | | - // You can refer to https://leafphp.netlify.app/#/leaf/v/2.4/core/auth for auth docs |
47 | | - } |
| 29 | + // This can be done here with the Auth::config method or |
| 30 | + // simply in the Config/auth.php file |
| 31 | + Auth::config(AuthConfig()); |
| 32 | + |
| 33 | + // You can refer to https://leafphp.netlify.app/#/leaf/v/2.5/core/auth for auth docs |
| 34 | + } |
48 | 35 | } |
0 commit comments