function login($data = null)
 {
     $this->User = ClassRegistry::init('User');
     $this->Token = ClassRegistry::init('Token');
     if (empty($data)) {
         $data = $this->request->data;
     }
     $userId = $this->User->find('list', array('conditions' => array('User.username' => $data['User']['username']), 'fields' => array('User.id')));
     $userId = current($userId);
     if ($this->User->isOldUser($data['User']['username'])) {
         $plainPassword = $data['User']['password'];
         $salt = $this->User->getUserSalt($data['User']['username']);
         $this->request->data = $data;
         $data['User']['password'] = $this->hashOldPassword($salt, $data['User']['password']);
         // 			if($this->identify($this->request, $this->response)) {
         $data['User']['password'] = $this->updateToNewSalting($userId, $plainPassword);
     }
     // 		} else {
     // 			$data['User']['password'] = $this->customHashPassword($data['User']['password']);
     // 		}
     if ($success = $this->identify($this->request, $this->response)) {
         // Continue authentication
         // 			if($this->Token->hasPendingActivation($userId)) {
         // 				$this->Session->setFlash(__('Login failed due to pending email verification.', true));
         // 				$success = false;
         // 			} else {
         if ($success = parent::login()) {
             $this->updateLastLogin($userId);
             $this->Session->setFlash(__('Successfully logged in!', true));
             // 				}
         }
     }
     return $success;
 }
Пример #2
0
 function login($data = null)
 {
     $loggedIn = parent::login($data);
     if (!empty($loggedIn)) {
         $this->initializeSession();
     }
     return $loggedIn;
 }
Пример #3
0
 function login($data)
 {
     $user = $this->Session->read('User');
     if (!$user || $data['loginid'] != $user['User']['loginid']) {
         if (parent::login($data)) {
             $this->Session->write('User', $this->user());
             echo json_encode($this->user());
         } else {
             return false;
         }
     }
     return $user;
 }
Пример #4
0
 /**
  * 認証情報の更新
  * @param AuthComponent $auth
  */
 public static function refresh(AuthComponent $auth)
 {
     $authrModelNmae = 'TblUser';
     $authModel = ClassRegistry::init($authrModelNmae);
     $primaryKey = $authModel->primaryKey;
     $id = $auth->user($primaryKey);
     $data = $authModel->read(null, $id);
     $tmp1 = $data[$authrModelNmae];
     $tmp2 = $data;
     unset($tmp2[$authrModelNmae]);
     $authData = am($tmp1, $tmp2);
     $auth->login($authData);
 }
Пример #5
0
 /**
  * Log a user in. If a $user is provided that data will be stored as the logged in user.  If `$user` is empty or not
  * specified, the request will be used to identify a user. If the identification was successful,
  * the user record is written to the session key specified in AuthComponent::$sessionKey. Logging in
  * will also change the session id in order to help mitigate session replays.
  *
  * @param array $user Either an array of user data, or null to identify a user using the current request.
  * @return boolean True on login success, false on failure
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in
  */
 public function login($user = null)
 {
     // CUSTOMIZE ADD 2011/09/25 ryuring
     // 簡単ログイン
     // >>>
     if (!empty($this->fields['serial']) && !$user) {
         $serial = $this->getSerial();
         $Model = $model = $this->getModel();
         if ($serial) {
             $user = $Model->find('first', array('conditions' => array($Model->alias . '.' . $this->fields['serial'] => $serial), 'recursive' => -1));
         }
     }
     // <<<
     // CUSTOMIZE ADD 2011/09/25 ryuring
     // ログイン時点でもモデルを保存しておく Session::user() のキーとして利用する
     // >>>
     return parent::login($user);
     // <<<
 }
Пример #6
0
 /**
  * OAuth callback
  */
 public function callback($datasource = null)
 {
     $this->Twitter->setTwitterSource($datasource);
     // 正当な返り値かチェック
     if (!$this->Twitter->isRequested()) {
         $this->Twitter->deleteAuthorizeCookie();
         $this->flash(__d('twitter_kit', 'Authorization failure.'), '/', 5);
         return;
     }
     // $tokenを取得
     $token = $this->Twitter->getAccessToken();
     if (is_string($token)) {
         $this->flash(__d('twitter_kit', 'Authorization Error: %s', $token), '/', 5);
         return;
     }
     if (class_exists('TwitterUser') || (true || App::uses('TwitterUser', 'Model')) && class_exists('TwitterUser')) {
         /* @var $model TwitterUser */
         $model = ClassRegistry::init('TwitterUser');
     } else {
         /* @var $model TwitterKitUser */
         $model = ClassRegistry::init('TwitterKit.TwitterKitUser');
     }
     // 保存データの作成
     $data = $model->createSaveDataByToken($token);
     if (!$model->save($data)) {
         $this->flash(__d('twitter_kit', 'The user could not be saved'), array('plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'), 5);
         return;
     }
     $this->Auth->login($data);
     // Redirect
     if (ini_get('session.referer_check') && env('HTTP_REFERER')) {
         $this->flash(__d('twiter_kit', 'Redirect to %s', Router::url($this->Auth->redirect(), true) . ini_get('session.referer_check')), $this->Auth->redirect(), 0);
         return;
     }
     $this->redirect($this->Auth->redirect());
 }
Пример #7
0
 /**
  * OAuth callback
  */
 public function callback($datasource = null)
 {
     $this->Twitter->setTwitterSource($datasource);
     // 正当な返り値かチェック
     if (empty($this->params['url']['oauth_token']) || empty($this->params['url']['oauth_verifier'])) {
         $this->Twitter->deleteAuthorizeCookie();
         $this->flash(__d('twitter_kit', 'Authorization failure.', true), '/', 5);
         return;
     }
     // $tokenを取得
     $token = $this->Twitter->getAccessToken();
     if (is_string($token)) {
         $this->flash(__d('twitter_kit', 'Authorization Error: ', true) . $token, '/', 5);
         return;
     }
     if (ClassRegistry::isKeySet('TwitterUser')) {
         /* @var $model TwitterUser */
         $model = ClassRegistry::init('TwitterUser');
     } else {
         /* @var $model TwitterKitUser */
         $model = ClassRegistry::init('TwitterKit.TwitterKitUser');
     }
     // 保存データの作成
     $data = $model->createSaveDataByToken($token);
     if (!$model->save($data)) {
         $this->flash(__d('twitter_kit', 'The user could not be saved', true), array('plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'), 5);
         return;
     }
     $this->Auth->login($data);
     // Redirect
     if (ini_get('session.referer_check') && env('HTTP_REFERER')) {
         $this->flash(sprintf(__d('twiter_kit', 'Redirect to %s', true), Router::url($this->Auth->redirect(), true) . ini_get('session.referer_check')), $this->Auth->redirect(), 0);
         return;
     }
     $this->redirect($this->Auth->redirect());
 }
Пример #8
0
 /**
  * Main execution method.  Handles redirecting of invalid users, and processing
  * of login form data.
  *
  * @param object $controller A reference to the instantiating controller object
  * @return boolean
  * @access public
  */
 function startup(&$controller)
 {
     $methods = array_flip($controller->methods);
     $isErrorOrTests = strtolower($controller->name) == 'cakeerror' || strtolower($controller->name) == 'tests' && Configure::read() > 0;
     if ($isErrorOrTests) {
         return true;
     }
     $isMissingAction = $controller->scaffold === false && !isset($methods[strtolower($controller->params['action'])]);
     if ($isMissingAction) {
         return true;
     }
     if (!$this->__setDefaults()) {
         return false;
     }
     $url = '';
     if (isset($controller->params['url']['url'])) {
         $url = $controller->params['url']['url'];
     }
     $url = Router::normalize($url);
     $loginAction = Router::normalize($this->loginAction);
     $isAllowed = $this->allowedActions == array('*') || in_array($controller->params['action'], $this->allowedActions);
     if ($loginAction != $url && $isAllowed) {
         return true;
     }
     //get model registered
     $this->ldap = $this->getModel($this->userModel);
     # get global settings
     $settings = $this->CommonTasks->getGlobalSettings();
     if ($loginAction == $url) {
         if (empty($controller->data) || !isset($controller->data[$this->userModel])) {
             if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) {
                 $this->Session->write('Auth.redirect', $controller->referer(null, true));
             }
             return false;
         }
         $isValid = !empty($controller->data[$this->userModel][$this->fields['username']]) && !empty($controller->data[$this->userModel][$this->fields['password']]);
         if ($isValid) {
             $username = $controller->data[$this->userModel][$this->fields['username']];
             $password = $controller->data[$this->userModel][$this->fields['password']];
             if ($settings['auth_method_' . $this->userModel] == "ldap") {
                 $this->log("Using ldap auth", "debug");
                 //pr("Using ldap auth...");
                 if ($this->login($username, $password)) {
                     if ($this->autoRedirect) {
                         $controller->redirect($this->redirect(), null, true);
                     }
                     return true;
                 }
             } else {
                 $this->log("Using internal auth", "debug");
                 //pr("Using internal auth...");
                 //pr($controller->data);
                 // hash password
                 $data = $this->hashPasswords($controller->data);
                 $username = $data[$this->userModel]['username'];
                 $password = $data[$this->userModel]['password'];
                 $data = array($this->userModel . '.' . $this->fields['username'] => $username, $this->userModel . '.' . $this->fields['password'] => $password);
                 //pr($data);
                 if (parent::login($data)) {
                     if ($this->autoRedirect) {
                         $controller->redirect($this->redirect(), null, true);
                     }
                     return true;
                 }
             }
         }
         $this->Session->setFlash($this->loginError, 'default', array(), 'auth');
         $controller->data[$this->userModel][$this->fields['password']] = null;
         return false;
     } else {
         if (!$this->user()) {
             if (!$this->RequestHandler->isAjax()) {
                 $this->Session->setFlash($this->authError, 'default', array(), 'auth');
                 $this->Session->write('Auth.redirect', $url);
                 $controller->redirect($loginAction);
                 return false;
             } elseif (!empty($this->ajaxLogin)) {
                 $controller->viewPath = 'elements';
                 echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
                 $this->_stop();
                 return false;
             } else {
                 $controller->redirect(null, 403);
             }
         }
     }
     if (!$this->authorize) {
         return true;
     }
     extract($this->__authType());
     switch ($type) {
         case 'controller':
             $this->object =& $controller;
             break;
         case 'crud':
         case 'actions':
             if (isset($controller->Acl)) {
                 $this->Acl =& $controller->Acl;
             } else {
                 $err = 'Could not find AclComponent. Please include Acl in ';
                 $err .= 'Controller::$components.';
                 trigger_error(__($err, true), E_USER_WARNING);
             }
             break;
         case 'model':
             if (!isset($object)) {
                 $hasModel = isset($controller->{$controller->modelClass}) && is_object($controller->{$controller->modelClass});
                 $isUses = !empty($controller->uses) && isset($controller->{$controller->uses[0]}) && is_object($controller->{$controller->uses[0]});
                 if ($hasModel) {
                     $object = $controller->modelClass;
                 } elseif ($isUses) {
                     $object = $controller->uses[0];
                 }
             }
             $type = array('model' => $object);
             break;
     }
     if ($this->isAuthorized($type)) {
         return true;
     }
     $this->Session->setFlash($this->authError, 'default', array(), 'auth');
     $controller->redirect($controller->referer(), null, true);
     return false;
 }
Пример #9
0
 /**
  * OAuth callback
  */
 public function callback($datasource = null)
 {
     $this->Twitter->setTwitterSource($datasource);
     // 正当な返り値かチェック
     if (!$this->Twitter->isRequested()) {
         $this->Twitter->deleteAuthorizeCookie();
         $this->flash(__d('twitter_kit', 'Authorization failure.'), '/', 5);
         return;
     }
     // $tokenを取得
     $token = $this->Twitter->getAccessToken();
     if (is_string($token)) {
         $this->flash(__d('twitter_kit', 'Authorization Error: %s', $token), '/', 5);
         return;
     }
     if (class_exists('TwitterUser') || (true || App::uses('TwitterUser', 'Model')) && class_exists('TwitterUser')) {
         /* @var $model TwitterUser */
         $model = ClassRegistry::init('TwitterUser');
     } else {
         /* @var $model TwitterKitUser */
         //$model = ClassRegistry::init('TwitterKit.TwitterKitUser');
         $model = ClassRegistry::init('User');
     }
     $create_flg = false;
     //既に登録済みか?
     $tmp = $model->findTwitterUser($token['user_id']);
     if (!empty($tmp)) {
         $data = $model->updateSaveDataByToken($tmp, $token);
     } else {
         // 保存データの作成
         $data = $model->createSaveDataByToken($token);
         $model->create();
         $create_flg = true;
     }
     if (!$model->save($data, false)) {
         $this->flash(__d('twitter_kit', 'The user could not be saved'), array('plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'), 5);
         return;
     }
     if ($create_flg == true) {
         $data['User']['id'] = $model->getLastInsertId();
         //新規会員登録の際
         $ds = $this->Twitter->getTwitterSource();
         $ds->setToken($data['User']);
         //プロフィール画像の取得
         $params = array();
         $params['id'] = $data['User']['twitter_user_id'];
         $result = $ds->users_show($data['User']['twitter_user_id']);
         if (!empty($result['profile_image_url'])) {
             $image_url = str_replace("_normal", "", $result['profile_image_url']);
             $image_data = file_get_contents($image_url);
             //MIMEタイプの取得
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $mime_type = finfo_buffer($finfo, $image_data);
             finfo_close($finfo);
             //出力
             switch ($mime_type) {
                 case 'image/gif':
                     $ext = "gif";
                     break;
                 case 'image/png':
                     $ext = "png";
                     break;
                 case 'image/jpg':
                 case 'image/jpeg':
                     $ext = "jpg";
                     break;
             }
             $file_name = md5(date("YmdHis") . $data['User']['id']) . "." . $ext;
             file_put_contents(IMAGES . 'profileImg/' . $file_name, $image_data);
             //profile_imgを更新
             $model->id = $data['User']['id'];
             $model->saveField('profile_img', $file_name);
             $data['User']['profile_img'] = $file_name;
         }
         //メール送信
         $email = new CakeEmail('smtp');
         $email->to('*****@*****.**');
         $email->subject('twitterから会員登録がありました');
         $email->emailFormat('text');
         $email->template('regist');
         $postData['User']['nickname'] = $data['User']['nickname'];
         $email->viewVars(compact('postData'));
         $email->send();
     }
     $this->Auth->login($data['User']);
     // Redirect
     if (ini_get('session.referer_check') && env('HTTP_REFERER')) {
         $this->flash(__d('twiter_kit', 'Redirect to %s', Router::url($this->Auth->redirect(), true) . ini_get('session.referer_check')), $this->Auth->redirect(), 0);
         return;
     }
     //ログイン履歴を保存
     $this->LoginHistory->saveLoginHistory($data['User']['id'], $this->request);
     //$this->redirect($this->Auth->redirect());
     if ($create_flg == true) {
         $this->redirect("/users/edit");
     } else {
         $this->redirect("/");
     }
 }
Пример #10
0
 /**
  * Manually log-in a user with the given parameter data.  The $data provided can be any data
  * structure used to identify a user in AuthComponent::identify().  If $data is empty or not
  * specified, POST data from Controller::$data will be used automatically.
  *
  * After (if) login is successful, the user record is written to the session key specified in
  * AuthComponent::$sessionKey.
  *
  * @param mixed $data User object
  * @return boolean True on login success, false on failure
  * @access public
  */
 function login($data = null)
 {
     // CUSTOMIZE ADD 2011/09/25 ryuring
     // 簡単ログイン
     // >>>
     if (!empty($this->fields['serial']) && !$data) {
         $serial = $this->getSerial();
         $Model = $model =& $this->getModel();
         if ($serial) {
             $data = $Model->find('first', array('conditions' => array($Model->alias . '.' . $this->fields['serial'] => $serial), 'recursive' => -1));
         }
     }
     // <<<
     return parent::login($data);
 }