Auth::play()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
dl 0
loc 44
rs 8.439
cc 5
eloc 28
nc 4
nop 0
1
<?php
2
/**
3
 * Auth
4
 *
5
 * 認証処理を実現するためのクラス
6
 *
7
 * @package           risoluto
8
 * @author            Risoluto Developers
9
 * @license           http://opensource.org/licenses/bsd-license.php new BSD license
10
 * @copyright     (C) 2008-2015 Risoluto Developers / All Rights Reserved.
11
 */
12
13
//------------------------------------------------------//
14
// 名前空間の定義
15
//------------------------------------------------------//
16
namespace RisolutoApps\Admin;
17
18
//------------------------------------------------------//
19
// クラス定義
20
//------------------------------------------------------//
21
class Auth extends \Risoluto\RisolutoControllerBase implements \Risoluto\RisolutoControllerInterface
22
{
23
    /**
24
     * play()
25
     *
26
     * 主処理を行う
27
     *
28
     * @access    public
29
     *
30
     * @param     void
31
     *
32
     * @return    void    なし
33
     */
34
    public function play()
35
    {
36
        // セッションをスタート
37
        $sess = new \Risoluto\Session();
38
        $sess->start();
39
40
        if ($sess->isThere( 'Auth' )) {
41
            // 認証情報がある場合は、メニュー画面へ遷移する
42
            \Risoluto\Url::redirectTo( 'Admin_Menu' );
43
            exit;
44
        } elseif (isset( $_POST[ 'userid' ] ) and isset( $_POST[ 'password' ] )) {
45
            // 入力値を処理
46
            $option = [
47
                'userid' => htmlentities( $_POST[ 'userid' ], ENT_QUOTES, 'UTF-8' ),
48
                'password' => htmlentities( $_POST[ 'password' ], ENT_QUOTES, 'UTF-8' )
49
            ];
50
51
            // POSTでユーザIDとパスワードが渡ってきた場合は認証処理を行う
52
            $auth_result = \Risoluto\Auth::callProviderMethod( 'doAuth', $option );
53
            if ($auth_result) {
54
                // 認証に成功した場合は詳細情報を取得
55
                $detail = \Risoluto\Auth::callProviderMethod( 'showUser', $option );
56
                $detail[ 0 ][ 'password' ] = '********';
57
                $group = \Risoluto\Auth::callProviderMethod( 'showGroupByNo', [ 'no' => $detail[ 0 ][ 'groupno' ] ] );
58
                $detail[ 0 ][ 'group' ] = $group[ 0 ];
59
60
                // 認証情報をセッションに追加してメニュー画面へ遷移する
61
                $sess->store( 'Auth', $detail[ 0 ] );
62
                $sess->store( 'csrf_token', $sess->genRand() );
63
                \Risoluto\Url::redirectTo( 'Admin_Menu' );
64
                exit;
65
            } else {
66
                // 認証に失敗した場合はエラー情報をセッションに追加してログイン画面に戻る
67
                $sess->store( 'AuthError', 'auth_failure' );
68
                \Risoluto\Url::redirectTo( 'Admin_Login' );
69
                exit;
70
            }
71
        } else {
72
            // それ以外の時はエラー情報をセッションに追加してログイン画面に戻る
73
            $sess->store( 'AuthError', 'invalid_access' );
74
            \Risoluto\Url::redirectTo( 'Admin_Login' );
75
            exit;
76
        }
77
    }
78
}