JSlip  1.0
LoginController.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/Controller.php');
9 require_once(dirname(__FILE__) . '/LoginModel.php');
10 
12 {
13  public $param;
14  public $rest;
15  public $viewName;
16  public $token;
17  public $model;
18 
19  function __construct() {
20  $this->model = new LoginModel();
21  }
22 
23  public function main($param) {
24 
25  $this->rest = '';
26  $this->param = $param;
27 
28  $this->param['base'] = dirname(__FILE__);
29 
30  if (empty($this->param['act'])) {
31  $this->_init();
32  } else {
33  switch ($this->param['act']) {
34  case 'check': $this->_check(); break;
35  default: $this->_init(); break;
36  }
37  }
38  }
39 
40  private function _init() {
41 
42  // Member Information
43  $_SESSION['minfo'] = [];
44 
45  // A Token Seed
46  $_SESSION['tseed'] = (string)random_int(1111111111, 9999999999);
47 
48  $this->viewName = 'login';
49  $this->token = password_hash($_SESSION['tseed'], PASSWORD_DEFAULT);
50  }
51 
52  private function _check() {
53 
54  if ((int)date('Ymd') > (int)str_replace('-', '', EXPIRE)) {
55  $this->rest = json_encode(['sts' => 'NG', 'err' => '有効期限切れです。']);
56  return;
57  }
58 
59  if (!password_verify($_SESSION['tseed'], $this->param['token'])) {
60  $this->rest = json_encode(['sts' => 'NG', 'err' => '不正トークン']);
61  return;
62  }
63 
64  if (!$this->model->chkPasswd($this->param['account'], $this->param['passwd'])) {
65  $this->rest = json_encode(['sts' => 'NG', 'err' => 'アカウン名またはパスワードに誤りがあります。']);
66  return;
67  }
68 
69  $info = $this->model->getMemberInfo($this->param['account']);
70 
71  if (empty($info['role'])) {
72  $this->rest = json_encode(['sts' => 'NG', 'err' => 'メンバー情報が見つかりません。']);
73  return;
74  }
75 
76  $info['bcnt'] = $this->model->cntBasic($info['mid']);
77 
78  if ($info['bcnt'] == 1) {
79  $info['bid'] = $this->model->getBid($info['mid']);
80  } else {
81  $info['bid'] = -1;
82  }
83 
84  $_SESSION['minfo'] = $info;
85 
86  if ($info['role'] == 'root') {
87  $this->rest = json_encode(['sts' => 'OK', 'url' => $this->param['url_base'], 'func' => 'RootMenu']);
88  } else {
89  $this->rest = json_encode(['sts' => 'OK', 'url' => $this->param['url_base'], 'func' => 'UserMenu']);
90  }
91  }
92 }
EXPIRE
const EXPIRE
Definition: local.php:13
LoginController\_init
_init()
Definition: LoginController.php:40
LoginController\$model
$model
Definition: LoginController.php:17
LoginController\$rest
$rest
Definition: LoginController.php:14
Controller
Definition: Controller.php:15
LoginController\__construct
__construct()
Definition: LoginController.php:19
LoginController\main
main($param)
Definition: LoginController.php:23
LoginController\$token
$token
Definition: LoginController.php:16
LoginController
Definition: LoginController.php:11
LoginController\_check
_check()
Definition: LoginController.php:52
LoginController\$param
$param
Definition: LoginController.php:13
LoginModel
Definition: LoginModel.php:10
LoginController\$viewName
$viewName
Definition: LoginController.php:15