Exemplo n.º 1
0
 $user_id_2 = array_key_exists('user_id_2', $_REQUEST) ? $_REQUEST['user_id_2'] : '';
 // --- 入力チェック
 if ($user_id_2 == '') {
     \Sop\Log::warning(__FILE__, __LINE__, 'Check user is not specified.');
     $msg001 = "Please assign a witness.";
     // 証人を指定してください
     \Sop\Api::exitWithError(array($msg001));
 }
 if ($user_id == $user_id_2) {
     \Sop\Log::warning(__FILE__, __LINE__, 'User specified oneself as check user.');
     $msg002 = "You can not assign a witness about yourself.";
     // 証人は入力者と異なる人を指定してください
     \Sop\Api::exitWithError(array($msg002));
 }
 // --- データ存在チェック
 $sel_sql = getSQLBaseForUser();
 $sel_sql .= " AND v_user.user_id = :user_id AND v_user.grp_id = :grp_id";
 $sql = "SELECT count(*) cnt FROM ({$sel_sql}) as tmp";
 // user2
 $params = array();
 $params[':user_id'] = $user_id_2;
 $params[':grp_id'] = $grp_id;
 $stmt = $db->prepare($sql);
 $stmt->execute($params);
 $cnt = 0;
 foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
     $cnt = (int) $row['cnt'];
 }
 if ($cnt == 0) {
     \Sop\Log::warning(__FILE__, __LINE__, 'Specified check user does not exist.');
     $msg003 = "There is not the inputted user.";
Exemplo n.º 2
0
 public static function getUser()
 {
     // ----------------------------------------
     // 指定されたuser_id、passwordを求める。
     // ----------------------------------------
     $user_id = '';
     $password = '';
     $verify_password = true;
     // ログイン済みならば、そのuser_idなどを使う。
     // (ログインしている最中にuser_idが削除された場合などを考慮して、後でチェックする。)
     if (Session::getSiteData('user_id') !== null) {
         $user_id = Session::getSiteData('user_id');
         $verify_password = false;
     } else {
         if (Config::get('use_sso')) {
             if (Session::getSiteData('sso_user_id') !== null) {
                 // シングル・サインオン経由でのサインイン
                 $user_id = Session::getSiteData('sso_user_id');
                 $verify_password = false;
             } else {
                 if (Session::getSiteData('sso_errors') !== null) {
                     // シングル・サインオンでエラーが発生した
                     self::exitWithLoginError(array(''), Session::getSiteData('sso_errors'));
                 }
             }
         } else {
             if (isset($_REQUEST['user_id'])) {
                 $user_id = $_REQUEST['user_id'];
             }
             if (isset($_REQUEST['password'])) {
                 $password = $_REQUEST['password'];
             }
         }
     }
     if ($user_id == '') {
         $msg01 = "User Id is not inputted.";
         // ユーザーIDが入力されていません
         self::exitWithLoginError(array($msg01), array());
     }
     // ----------------------------------------
     // データ取得
     // ----------------------------------------
     $sql = getSQLBaseForUser();
     $sql .= " AND v_user.user_id = :user_id";
     $params = array();
     $params[':user_id'] = $user_id;
     $user_list = array();
     foreach (\R::getAll($sql, $params) as $user) {
         $user['grp_id'] = (int) $user['grp_id'];
         // --- パスワードが一致しない場合はスキップ
         if ($verify_password) {
             if ($user['password'] != crypt($password, $user['password'])) {
                 continue;
             }
         }
         // ロールは展開する。
         $user['role_aprv'] = (bool) substr($user['role'], 0, 1);
         $user['role_upld'] = (bool) substr($user['role'], 1, 1);
         $user['role_user'] = (bool) substr($user['role'], 2, 1);
         array_push($user_list, $user);
     }
     // --- レコードなしの場合はエラー
     if (count($user_list) == 0) {
         if (Config::get('use_sso')) {
             $msg02 = "Account does not relate to the system.";
             // 'アカウントがシステムに紐づけされていません。
             self::exitWithLoginError(array(), array($msg02));
         } else {
             $msg03 = "User ID and a password are not correct. ";
             // 'ユーザーID、パスワードが正しくありません
             self::exitWithLoginError(array($msg03), array());
         }
     }
     return $user_list[0];
 }