Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,765 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<?php | ||
/** | ||
* AdminCommon | ||
* | ||
* Admin系共通処理処理を実現するためのクラス | ||
* | ||
* @package risoluto | ||
* @author Risoluto Developers | ||
* @license http://opensource.org/licenses/bsd-license.php new BSD license | ||
* @copyright (C) 2008-2014 Risoluto Developers / All Rights Reserved. | ||
*/ | ||
|
||
//------------------------------------------------------// | ||
// 名前空間の定義 | ||
//------------------------------------------------------// | ||
namespace RisolutoApps\Admin; | ||
|
||
//------------------------------------------------------// | ||
// クラス定義 | ||
//------------------------------------------------------// | ||
class AdminCommon | ||
{ | ||
/** | ||
* loginCheck(\Risoluto\Session $sess, $admin = true) | ||
* | ||
* ログインチェック処理を行う | ||
* | ||
* @access public | ||
* | ||
* @param \Risoluto\Session $sess セッションオブジェクト | ||
* @param boolean $admin 管理者権限必須か否か(true:必須、デフォルト/false:ログイン成功なら誰でもOK) | ||
* | ||
* @return array 認証情報 | ||
* @throws \Exception 管理者権限必須の時に権限を持ってないユーザの場合はThrow | ||
*/ | ||
public function loginCheck(\Risoluto\Session $sess, $admin = true) | ||
{ | ||
if ($sess->isThere('Auth')) { | ||
// 認証情報がある場合は取得する | ||
$detail = $sess->Load('Auth'); | ||
|
||
if ($admin and $detail['groupno'] != 1) { | ||
// 管理者権限を持っていない場合はエラー | ||
throw new \Exception('Admin user required'); | ||
} else { | ||
// 管理者権限を持っている場合はそのまま戻る | ||
return $detail; | ||
} | ||
} else { | ||
// 認証情報がない場合はログイン画面へ遷移する | ||
$sess->store('AuthError', 'invalid_access'); | ||
\Risoluto\Url::redirectTo('Admin_Login'); | ||
exit; | ||
} | ||
} | ||
|
||
/** | ||
* getGroupList($mode = '') | ||
* | ||
* グループリスト取得処理を行う | ||
* | ||
* @access public | ||
* | ||
* @param string $mode 取得モード(name_only / id_and_name) | ||
* | ||
* @return array 取得したグループリスト | ||
*/ | ||
public function getGroupList($mode = '') | ||
{ | ||
// まずはグループ情報を普通に取得 | ||
$grouplist = \Risoluto\Auth::callProviderMethod('showGroupAll'); | ||
$retval = array(); | ||
|
||
// 指定されたモードによって返却する配列を変える | ||
foreach ($grouplist as $dat) { | ||
switch ($mode) { | ||
case 'name_only': | ||
$retval[$dat['no']] = $dat['groupname']; | ||
break; | ||
|
||
case 'id_and_name': // FALL THRU | ||
default: | ||
$retval[$dat['no']] = array('id' => $dat['groupid'], 'name' => $dat['groupname']); | ||
break; | ||
} | ||
} | ||
|
||
// 処理結果を返却する | ||
return $retval; | ||
} | ||
|
||
/** | ||
* checkEnteredUserData($target, $csrf_token) | ||
* | ||
* 入力内容のチェック処理を行う | ||
* | ||
* @access public | ||
* | ||
* @param array $target チェック対象となるデータが格納された配列 | ||
* @param string $csrf_token CSRF対策のためのトークン | ||
* @param integer $selfno 自分自身のユーザno(省略可、省略された場合はユーザIDの重複チェック時に考慮) | ||
* | ||
* @return array チェック結果 | ||
* @throws \Exception CSRFトークンが一致しなかった場合はThrow | ||
*/ | ||
public function checkEnteredUserData($target, $csrf_token, $selfno = '') | ||
{ | ||
// 戻り値を初期化 | ||
$retval = array(); | ||
$retval['entered'] = array(); | ||
$retval['error']['msg'] = array(); | ||
$retval['error']['form_crit'] = array(); | ||
|
||
//--- ユーザIDのチェック | ||
$dup_master = \Risoluto\Auth::callProviderMethod('showUser', array('userid' => $target['userid'])); | ||
$retval['entered']['userid'] = htmlentities($target['userid'], ENT_QUOTES, 'UTF-8'); | ||
if (isset($target['userid']) and !empty($target['userid'])) { | ||
if (!empty($selfno)) { | ||
// 自分自身のユーザnoがセットされている場合は、重複データにそれが含まれていないかを確認する | ||
$retval['entered']['no'] = $selfno; | ||
$dups = array(); | ||
foreach ($dup_master as $dat) { | ||
if ($dat['no'] != $selfno) { | ||
$dups[] = $dat; | ||
} | ||
} | ||
} else { | ||
// セットされていない場合は取得したものをそのまま使う | ||
$dups = $dup_master; | ||
} | ||
|
||
// フォーマットチェック | ||
if (!preg_match('/[[:alnum:]\_\-\@\.]{1,255}/', $target['userid']) or count($dups) > 0) { | ||
// フォーマットにそぐわない場合はエラーにする | ||
$retval['error']['msg'][] = 'invalid_userid'; | ||
$retval['error']['form_crit'][] = 'userid'; | ||
} | ||
} else { | ||
// 未入力の場合はエラーにする | ||
$retval['entered']['userid'] = ''; | ||
$retval['error']['msg'][] = 'empty_userid'; | ||
$retval['error']['form_crit'][] = 'userid'; | ||
} | ||
|
||
//--- ユーザ名のチェック | ||
$retval['entered']['username'] = htmlentities($target['username'], ENT_QUOTES, 'UTF-8'); | ||
if (isset($target['username']) and !empty($target['username'])) { | ||
// フォーマットチェック | ||
if (strlen($target['username']) > 255) { | ||
// フォーマットにそぐわない場合はエラーにする | ||
$retval['error']['msg'][] = 'invalid_username'; | ||
$retval['error']['form_crit'][] = 'username'; | ||
} | ||
} else { | ||
// 未入力の場合はエラーにする | ||
$retval['entered']['username'] = ''; | ||
$retval['error']['msg'][] = 'empty_username'; | ||
$retval['error']['form_crit'][] = 'username'; | ||
} | ||
|
||
//--- パスワードのチェック | ||
$retval['entered']['password'] = htmlentities($target['password'], ENT_QUOTES, 'UTF-8'); | ||
$retval['entered']['password_confirm'] = $retval['entered']['password']; | ||
if (isset($target['password']) and !empty($target['password'])) { | ||
// フォーマットチェック | ||
if ($target['password'] != $target['password_confirm']) { | ||
// フォーマットにそぐわない場合はエラーにする | ||
$retval['error']['msg'][] = 'invalid_password'; | ||
$retval['error']['form_crit'][] = 'password'; | ||
} | ||
} else { | ||
// 未入力の場合はエラーにする | ||
$retval['entered']['password'] = ''; | ||
$retval['entered']['password_confirm'] = ''; | ||
$retval['error']['msg'][] = 'empty_password'; | ||
$retval['error']['form_crit'][] = 'password'; | ||
} | ||
|
||
//--- 所属グループのチェック | ||
$retval['entered']['groupno'] = htmlentities($target['groupno'], ENT_QUOTES, 'UTF-8'); | ||
if (isset($target['groupno'])) { | ||
// フォーマットチェック | ||
if (!preg_match('/\d{1,}/', $target['groupno'])) { | ||
// フォーマットにそぐわない場合はエラーにする | ||
$retval['error']['msg'][] = 'invalid_groupno'; | ||
$retval['error']['form_crit'][] = 'groupno'; | ||
} | ||
} else { | ||
// 未入力の場合はエラーにする | ||
$retval['entered']['groupno'] = ''; | ||
$retval['error']['msg'][] = 'empty_groupno'; | ||
$retval['error']['form_crit'][] = 'groupno'; | ||
} | ||
|
||
//--- ステータスのチェック | ||
$retval['entered']['status'] = htmlentities($target['status'], ENT_QUOTES, 'UTF-8'); | ||
if (isset($target['status'])) { | ||
// フォーマットチェック | ||
if (!preg_match('/\d{1,}/', $target['status'])) { | ||
// フォーマットにそぐわない場合はエラーにする | ||
$retval['error']['msg'][] = 'invalid_status'; | ||
$retval['error']['form_crit'][] = 'status'; | ||
} | ||
} else { | ||
// 未入力の場合はエラーにする | ||
$retval['entered']['status'] = ''; | ||
$retval['error']['msg'][] = 'empty_status'; | ||
$retval['error']['form_crit'][] = 'status'; | ||
} | ||
|
||
//--- CSRFトークンのチェック | ||
if ($target['csrf_token'] != $csrf_token) { | ||
throw new \Exception('CSRF Check Error'); | ||
} | ||
|
||
// エラー関係の配列から重複を排除する | ||
$retval['error']['msg'] = array_unique($retval['error']['msg']); | ||
$retval['error']['form_crit'] = array_unique($retval['error']['form_crit']); | ||
|
||
// 処理結果を返却する | ||
return $retval; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Auth | ||
* | ||
* 認証処理を実現するためのクラス | ||
* | ||
* @package risoluto | ||
* @author Risoluto Developers | ||
* @license http://opensource.org/licenses/bsd-license.php new BSD license | ||
* @copyright (C) 2008-2014 Risoluto Developers / All Rights Reserved. | ||
*/ | ||
|
||
//------------------------------------------------------// | ||
// 名前空間の定義 | ||
//------------------------------------------------------// | ||
namespace RisolutoApps\Admin; | ||
|
||
//------------------------------------------------------// | ||
// クラス定義 | ||
//------------------------------------------------------// | ||
class Auth extends \Risoluto\RisolutoControllerBase implements \Risoluto\RisolutoControllerInterface | ||
{ | ||
/** | ||
* play() | ||
* | ||
* 主処理を行う | ||
* | ||
* @access public | ||
* | ||
* @param void | ||
* | ||
* @return void なし | ||
*/ | ||
public function play() | ||
{ | ||
// セッションをスタート | ||
$sess = new \Risoluto\Session(); | ||
$sess->start(); | ||
|
||
if ($sess->isThere('Auth')) { | ||
// 認証情報がある場合は、メニュー画面へ遷移する | ||
\Risoluto\Url::redirectTo('Admin_Menu'); | ||
exit; | ||
} elseif (isset($_POST['userid']) and isset($_POST['password'])) { | ||
// 入力値を処理 | ||
$option = array( | ||
'userid' => htmlentities($_POST['userid'], ENT_QUOTES, 'UTF-8'), | ||
'password' => htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8') | ||
); | ||
|
||
// POSTでユーザIDとパスワードが渡ってきた場合は認証処理を行う | ||
$auth_result = \Risoluto\Auth::callProviderMethod('doAuth', $option); | ||
if ($auth_result) { | ||
// 認証に成功した場合は詳細情報を取得 | ||
$detail = \Risoluto\Auth::callProviderMethod('showUser', $option); | ||
$detail[0]['password'] = '********'; | ||
$group = \Risoluto\Auth::callProviderMethod('showGroupByNo', array('no' => $detail[0]['groupno'])); | ||
$detail[0]['group'] = $group[0]; | ||
|
||
// 認証情報をセッションに追加してメニュー画面へ遷移する | ||
$sess->store('Auth', $detail[0]); | ||
$sess->store('csrf_token', $sess->genRand()); | ||
\Risoluto\Url::redirectTo('Admin_Menu'); | ||
exit; | ||
} else { | ||
// 認証に失敗した場合はエラー情報をセッションに追加してログイン画面に戻る | ||
$sess->store('AuthError', 'auth_failure'); | ||
\Risoluto\Url::redirectTo('Admin_Login'); | ||
exit; | ||
} | ||
} else { | ||
// それ以外の時はエラー情報をセッションに追加してログイン画面に戻る | ||
$sess->store('AuthError', 'invalid_access'); | ||
\Risoluto\Url::redirectTo('Admin_Login'); | ||
exit; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Login | ||
* | ||
* ログイン画面を実現するためのクラス | ||
* | ||
* @package risoluto | ||
* @author Risoluto Developers | ||
* @license http://opensource.org/licenses/bsd-license.php new BSD license | ||
* @copyright (C) 2008-2014 Risoluto Developers / All Rights Reserved. | ||
*/ | ||
|
||
//------------------------------------------------------// | ||
// 名前空間の定義 | ||
//------------------------------------------------------// | ||
namespace RisolutoApps\Admin; | ||
|
||
//------------------------------------------------------// | ||
// クラス定義 | ||
//------------------------------------------------------// | ||
class Login extends \Risoluto\RisolutoControllerBase implements \Risoluto\RisolutoControllerInterface | ||
{ | ||
// View関連の処理を使用する | ||
use \Risoluto\RisolutoViewTrait; | ||
|
||
/** | ||
* play() | ||
* | ||
* 主処理を行う | ||
* | ||
* @access public | ||
* | ||
* @param void | ||
* | ||
* @return void なし | ||
*/ | ||
public function play() | ||
{ | ||
// セッションをスタート | ||
$sess = new \Risoluto\Session(); | ||
$sess->start(); | ||
|
||
if ($sess->isThere('Auth')) { | ||
// 認証情報がある場合は、メニュー画面へ遷移する | ||
\Risoluto\Url::redirectTo('Admin_Menu'); | ||
exit; | ||
} | ||
|
||
$auth_error = ''; | ||
if ($sess->isThere('AuthError')) { | ||
// 認証エラー情報がある場合は取得する | ||
$auth_error = $sess->load('AuthError'); | ||
$sess->revoke('AuthError'); | ||
} | ||
|
||
// ヘッダ情報のセット | ||
$header = $this->getDefaultHeader(); | ||
$header = $this->replaceHeader($header, 'robots', 'NOINDEX,NOFOLLOW'); | ||
|
||
// テンプレートエンジン関連の処理 | ||
$assign_value = array('header' => $header, 'autherr' => $auth_error); | ||
$this->risolutoView($assign_value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{* | ||
This file is part of Risoluto( http://www.risoluto.org/ ) | ||
Risoluto is released under New BSD License( http://opensource.org/licenses/bsd-license.php ) | ||
(C) 2008-2014 Risoluto Developers / All Rights Reserved. | ||
*} | ||
{include file="$__RISOLUTO_APPS/common/header.tpl"} | ||
<h1>Risolutoへのログイン</h1> | ||
|
||
{if $autherr == 'auth_failure'} | ||
<div class="alert alert-danger" role="alert">入力されたユーザIDとパスワードではログインできませんでした</div> | ||
{elseif $autherr == 'invalid_access'} | ||
<div class="alert alert-info" role="alert">ユーザIDとパスワードを入力し、ログインボタンをクリックしてください</div> | ||
{/if} | ||
|
||
<form action="?seq=Admin_Auth" method="post" role="form"> | ||
<div class="form-group"> | ||
<label for="userid">ユーザID</label> | ||
<input type="text" class="form-control" id="userid" name="userid" placeholder="ユーザIDを入力してください"> | ||
<label for="password">パスワード</label> | ||
<input type="password" class="form-control" id="password" name="password" placeholder="パスワードを入力してください"> | ||
</div> | ||
<div class="form-group"> | ||
<button type="submit" class="btn btn-default btn-lg btn-block">ログイン</button> | ||
</div> | ||
</form> | ||
{include file="$__RISOLUTO_APPS/common/footer.tpl"} |
Oops, something went wrong.