8 * @author Cake <cake_67@users.sourceforge.jp>
9 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
10 * @link http://trpgtools-onweb.sourceforge.jp/
17 * The parent component
19 App::import('Component', 'Auth');
21 class AuthPlusComponent extends AuthComponent {
24 * The name of the model that represents users which will be authenticated. Defaults to 'User'.
29 var $userModel = 'User';
31 function initialize(&$controller)
33 parent::initialize($controller);
36 if (isset($controller->params["url"]["url"])) {
37 $this->loginRedirect = $controller->params["url"]["url"];
39 $this->loginRedirect = Configure::read('Routing.basePath');
41 if ("/".$this->loginRedirect == Router::normalize(Configure::read('Routing.loginPath'))) {
42 $this->loginRedirect = Router::normalize(Configure::read('Routing.basePath'));
43 if (Configure::read('mobileUserAgent')) {
44 $this->loginRedirect .= "m/";
51 $this->__setDefaults();
52 $this->Session->del($this->sessionKey);
53 $this->Session->destroy();
55 $this->_loggedIn = false;
56 return Router::normalize($this->logoutRedirect);
59 function isAuthorized($type = null, $object = null, $user = null) {
60 if ($type == 'orig') {
61 $user = $this->user();
67 } elseif (in_array($this->user('group_id'), array(
68 Configure::read('Group.admin'),
69 Configure::read('Group.subadmin'),
70 Configure::read('Group.watcher'))
74 } elseif ($this->user('group_id') == Configure::read('Group.member')) {
75 if (isset($this->params['prefix'])
76 && $this->params['prefix'] == Configure::read('Routing.admin')) {
87 $valid = parent::isAuthorized($type, $object, $user);
93 function login($data = null) {
96 if ($this->_loggedIn) {
98 $user = $this->user();
101 if (Configure::read('Session.destroyOldAuth')) {
102 $before_sid = $user['User']['sid'];
103 $new_sid = $this->Session->id();
105 if ($before_sid != $new_sid) {
107 session_write_close();
110 $this->Session->__initSession();
111 session_id($before_sid);
115 if (Configure::read('Session.save') == 'database') {
116 // session Lib.の__destroy()処理
117 $db =& ConnectionManager::getDataSource(Configure::read('Session.database'));
118 $table = $db->fullTableName(Configure::read('Session.table'));
119 $db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $before_sid);
121 $file = $sessionpath . DS . "sess_$before_sid";
126 $this->Session->__initSession();
127 session_id($new_sid);
133 $model =& $this->getModel();
134 $model->id = $user['User']['id'];
136 'useragent' => $_SERVER["HTTP_USER_AGENT"],
137 'host' => gethostbyaddr($_SERVER["REMOTE_ADDR"]),
138 'sid' => $this->Session->id(),
143 return $this->_loggedIn;
147 $this->Session->destroy();
149 return parent::logout();