Passed
Push — master ( e5a117...444e05 )
by Paweł
09:40
created

UserController::actionIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 21
rs 9.7
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 05.02.2018
6
 */
7
8
namespace app\commands;
9
10
11
use app\models\User;
12
use yii\console\Controller;
13
use yii\console\ExitCode;
14
use yii\console\widgets\Table;
15
use yii\helpers\Console;
16
17
class UserController extends Controller
18
{
19
    /**
20
     *
21
     * @param mixed $ident ID or Email
22
     * @return int
23
     * @throws \Throwable
24
     * @throws \yii\db\StaleObjectException
25
     */
26
    public function actionActivate($ident)
27
    {
28
        $user = User::findOne(is_numeric($ident) ? $ident : ['email' => $ident]);
29
        if ($user === null) {
30
            $this->stdout("User not found!\n", Console::FG_RED);
31
32
            return ExitCode::UNSPECIFIED_ERROR;
33
        }
34
        $user->active = 1;
35
        $user->update(false);
36
        $this->stdout("OK!\n");
37
38
        return ExitCode::OK;
39
    }
40
41
    public function actionIndex()
42
    {
43
        echo Table::widget([
44
            'headers' => [
45
                'ID',
46
                'Username',
47
                'Email',
48
                'Active',
49
                'Access Token',
50
            ],
51
            'rows' => User::find()
52
                ->select([
53
                    'id',
54
                    'username',
55
                    'email',
56
                    'active',
57
                    'access_token',
58
                ])
59
                ->orderBy('id DESC')
60
                ->asArray()
61
                ->all(),
62
        ]);
63
    }
64
}