UserController::actions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace api\controllers\v1;
4
5
use yrc\filters\auth\HMACSignatureAuth;
6
use yrc\rest\Controller;
7
8
use yrc\actions\ResetPasswordAction;
9
use yrc\actions\ActivationAction;
10
use yrc\actions\AuthenticationAction;
11
use yrc\actions\ChangeEmailAction;
12
use yrc\actions\OTPAction;
13
use yrc\actions\RefreshAction;
14
use yrc\actions\RegisterAction;
15
use yii\web\HttpException;
16
use Yii;
17
18
class UserController extends Controller
19
{
20
    /**
21
     * Map actions to the appropriate action class
22
     *
23
     * @return array
24
     */
25
    public function actions()
26
    {
27
        return [
28
            'activate'      => ActivationAction::class,
29
            'authenticate'  => AuthenticationAction::class,
30
            'change_email'  => ChangeEmailAction::class,
31
            'otp'           => OTPAction::class,
32
            'refresh'       => RefreshAction::class,
33
            'register'      => RegisterAction::class,
34
            
35
            // If you want verifiable tokenized password resets (for authenticated and unauthenticated)
36
            'reset_password' => ResetPasswordAction::class,
37
38
            // If you want password resets done for authenticated userss only
39
            'reset_password_authenticated' => [
40
                'class' => ResetPasswordAction::class,
41
                'scenario' => ResetPasswordAction::SCENARIO_AUTHENTICATED
42
            ]
43
        ];
44
    }
45
46
    /**
47
     * Yii2 behaviors
48
     *
49
     * @return array
50
     */
51
    public function behaviors()
52
    {
53
        $behaviors = parent::behaviors();
54
55
        $behaviors['authenticator'] = [
56
            'class'     => HMACSignatureAuth::class,
57
            'only'      => ['refresh', 'authenticate', 'otp', 'reset_password', 'change_email', 'reset_password_authenticated'],
58
            'optional'  => ['authenticate', 'reset_password']
59
        ];
60
61
        return $behaviors;
62
    }
63
}
64