|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under The MIT License |
|
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CakeDC\Api\Service; |
|
13
|
|
|
|
|
14
|
|
|
use CakeDC\Api\Service\Action\Auth\LoginAction; |
|
15
|
|
|
use CakeDC\Api\Service\Action\Auth\RegisterAction; |
|
16
|
|
|
use CakeDC\Api\Service\Action\Auth\ResetPasswordAction; |
|
17
|
|
|
use CakeDC\Api\Service\Action\Auth\ResetPasswordRequestAction; |
|
18
|
|
|
use CakeDC\Api\Service\Action\Auth\SocialLoginAction; |
|
19
|
|
|
use CakeDC\Api\Service\Action\Auth\ValidateAccountAction; |
|
20
|
|
|
use CakeDC\Api\Service\Action\Auth\ValidateAccountRequestAction; |
|
21
|
|
|
use Cake\Utility\Hash; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class AuthService |
|
25
|
|
|
* |
|
26
|
|
|
* @package CakeDC\Api\Service |
|
27
|
|
|
*/ |
|
28
|
|
|
class AuthService extends Service |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @inheritdoc |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
8 |
|
public function initialize() |
|
36
|
|
|
{ |
|
37
|
8 |
|
parent::initialize(); |
|
38
|
8 |
|
$methods = ['method' => ['POST'], 'mapCors' => true]; |
|
39
|
8 |
|
$this->mapAction('login', LoginAction::class, $methods); |
|
40
|
8 |
|
$this->mapAction('register', RegisterAction::class, $methods); |
|
41
|
8 |
|
$this->mapAction('reset_password_request', ResetPasswordRequestAction::class, $methods); |
|
42
|
8 |
|
$this->mapAction('reset_password', ResetPasswordAction::class, $methods); |
|
43
|
8 |
|
$this->mapAction('validate_account_request', ValidateAccountRequestAction::class, $methods); |
|
44
|
8 |
|
$this->mapAction('validate_account', ValidateAccountAction::class, $methods); |
|
45
|
8 |
|
$this->mapAction('social_login', SocialLoginAction::class, $methods); |
|
46
|
8 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Action constructor options. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array $route Action route. |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
8 |
|
protected function _actionOptions($route) |
|
55
|
|
|
{ |
|
56
|
8 |
|
$options['Extension'] = ['CakeDC/Api.Auth/UserFormatting']; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
8 |
|
return Hash::merge(parent::_actionOptions($route), $options); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.