public function postLogin()
 {
     $this->loadModel('User');
     $key = 'iznWsaal5lKhOKu4f7f0YagKW81ClEBXqVuTjrFovrXXtOggrqHdDJqkGXsQpHf';
     $email = trim($this->request->data['email']);
     $password = trim($this->request->data['password']);
     $encrypted_password = Security::cipher($password, $key);
     $opts = array('conditions' => array('and' => array('User.user_email' => $email, 'User.password' => $encrypted_password)));
     $userInfo = $this->User->find('first', $opts);
     if ($userInfo) {
         //session
         CakeSession::write('session_id', $userInfo['User']['user_id']);
         CakeSession::write('session_name', $userInfo['User']['user_name']);
         CakeSession::write('session_email', $userInfo['User']['user_email']);
         $this->redirect('../User/user_profile');
     } else {
         $this->loadModel('CreateGroup');
         $opts = array('conditions' => array('and' => array('CreateGroup.group_admin_email' => $email, 'CreateGroup.password' => $encrypted_password)));
         $groupInfo = $this->CreateGroup->find('first', $opts);
         if ($groupInfo) {
             //session
             CakeSession::write('session_id', $groupInfo['CreateGroup']['group_id']);
             CakeSession::write('session_name', $groupInfo['CreateGroup']['group_name']);
             CakeSession::write('session_code', $groupInfo['CreateGroup']['group_code']);
             CakeSession::write('session_email', $groupInfo['CreateGroup']['group_admin_email']);
             $this->redirect('../Admin/group_profile');
         } else {
             $this->Session->write('login_message', 'Invalid username or password');
             $this->redirect('../login/home');
         }
     }
 }
Example #2
0
 public function login()
 {
     //echo hash('sha512', 'TransF0rm3rs');
     if ($this->request->is('post')) {
         $username = stripslashes($this->request->data['username']);
         $password = stripslashes(hash('sha512', stripslashes($this->request->data['password'])));
         $conditions = array('conditions' => array('username' => $username, 'password' => $password));
         $admin = $this->Admin->find('all', $conditions);
         if (count($admin) > 0) {
             // admin user found;
             $this->Session->setFlash(__('Yay! You have been logged in.'));
             CakeSession::write('admin_user', $admin);
             $this->redirect('/admin/reports');
         } else {
             $this->loadModel('AffiliateMember');
             $this->AffiliateMember->recursive = 2;
             $admin = $this->AffiliateMember->find('all');
             if (count($admin) > 0) {
                 $this->Session->setFlash(__('Yay! You have been logged in.'));
                 CakeSession::write('admin_user', $admin);
                 $this->redirect('/admin/reports');
             } else {
                 $this->Session->setFlash(__('Oops! The user account could not be found.'));
             }
         }
     }
 }
Example #3
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     unset($this->controller);
     Configure::write('Config.language', null);
     CakeSession::write('Auth.User', null);
     parent::tearDown();
 }
 /**
  * Authenticates the identity contained in a request.  Will use the `settings.userModel`, and `settings.fields`
  * to find POST data that is used to find a matching record in the `settings.userModel`.  Will return false if
  * there is no post data, either username or password is missing, of if the scope conditions have not been met.
  *
  * @param CakeRequest $request The request that contains login information.
  * @param CakeResponse $response Unused response object.
  * @return mixed.  False on login failure.  An array of User data on success.
  */
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $userModel = $this->settings['userModel'];
     list($plugin, $model) = pluginSplit($userModel);
     if (empty($request->data[$model])) {
         return false;
     }
     if (empty($request->data[$model][$this->settings['post_key']]) || empty($request->data[$model][$this->settings['fields']['password']])) {
         return false;
     }
     $User = ClassRegistry::init($userModel);
     $password = $request->data[$model][$this->settings['fields']['password']];
     foreach ($this->settings['fields']['username'] as $username) {
         $conditions = array();
         if (!empty($this->settings['scope'])) {
             $conditions = array_merge($conditions, $this->settings['scope']);
         }
         $conditions[$model . '.' . $username] = $request->data[$model][$this->settings['post_key']];
         $conditions[$model . '.' . $this->settings['fields']['password']] = $this->_password($password);
         $result = $User->find('first', array('conditions' => $conditions, 'contain' => $this->settings['contain']));
         if (!empty($result) || !empty($result[$model])) {
             CakeSession::write(Configure::read('SessionKey'), $result);
             unset($result[$model][$this->settings['fields']['password']]);
             return $result[$model];
         }
     }
     return false;
 }
 /**
  * tearDown
  *
  * @return void
  */
 public function tearDown()
 {
     Configure::write('Config.language', null);
     CakeSession::write('Auth.User', null);
     unset($this->Questionnaire);
     parent::tearDown();
 }
 /**
  * 動画変換とデータ保存 MP4例外テスト
  *
  * @return void
  * @throws Exception
  */
 public function testSaveConvertVideoMp4Exception()
 {
     // 暫定対応(;'∀') ffmpeg未インストールによる travis-ci error のため、コメントアウト
     //$this->setExpectedException('InternalErrorException');
     // AuthComponent::user('id');対応
     $Session = new CakeSession();
     $Session->write('Auth.User.id', 1);
     $data = array('Video' => array('block_id' => 2));
     $video = array('Video' => array('mp4_id' => 1), Video::VIDEO_FILE_FIELD => array('FilesPlugin' => array('plugin_key' => 'videos')));
     $roomId = 1;
     // テストファイル準備
     $contentsId = $video['Video']['mp4_id'];
     $fileName = 'video1.mp4';
     $this->_readyTestFile($contentsId, $roomId, $fileName);
     // 例外を発生させるためのモック
     $videoMock = $this->getMockForModel('Videos.Video', ['save']);
     $videoMock->expects($this->any())->method('save')->will($this->returnValue(false));
     $videoMock->FileModel = ClassRegistry::init('Files.FileModel');
     try {
         // 動画変換とデータ保存
         $videoMock->saveConvertVideo($data, $video, $roomId);
     } catch (Exception $e) {
         // テストファイル削除
         $this->_deleteTestFile();
         // 暫定対応(;'∀') ffmpeg未インストールによる travis-ci error のため、コメントアウト
         //throw $e;
     }
 }
 public function postLogin()
 {
     $this->loadModel('User');
     //admin send request to user with its url parameter group_id and random_no
     $group_id = trim($this->request->data['group_id']);
     $random_no = trim($this->request->data['random_no']);
     $email = trim($this->request->data['email']);
     $password = base64_encode(trim($this->request->data['password']));
     $opts = array('conditions' => array('and' => array('User.txt_email' => $email, 'User.txt_pswd' => $password)));
     $userInfo = $this->User->find('first', $opts);
     if ($userInfo) {
         CakeLog::write('info', '.....Login successfully...');
         //session
         CakeSession::write('session_id', $userInfo['User']['nbr_user_id']);
         CakeSession::write('session_name', $userInfo['User']['txt_name']);
         CakeSession::write('session_email', $userInfo['User']['txt_email']);
         CakeLog::write('info', ' Session values are Session User Id : ' . $userInfo['User']['nbr_user_id'] . ' Session User Name : ' . $userInfo['User']['txt_name'] . ' Session User Email : ' . $userInfo['User']['txt_email']);
         //When admin send request to user if user not registered then user register to self and
         //directly join to the admin requested group by using URL parameter group Id and random number.
         if (!empty($group_id) && !empty($random_no)) {
             $this->Request($group_id, $random_no, $email);
             //delete session values
             CakeSession::delete('group_id');
             CakeSession::delete('random_no');
         }
         $this->redirect('../Ideas/view_ideas');
     } else {
         CakeLog::write('info', '.....Invalid username or password...');
         $this->Session->write('login_message', 'Invalid username or password');
         $this->redirect('../');
     }
 }
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     // Server Side Flow
     $this->access_token = $this->_retrive_access_token($request);
     if ($this->access_token) {
         $user = $this->_retrive_userdata();
         $user->access_token = $this->access_token;
         $userModel = $this->settings['userModel'];
         list($plugin, $model) = pluginSplit($userModel);
         $fields = $this->settings['fields'];
         $conditions = array($model . '.' . $fields['username'] => $user->id);
         if (!empty($this->settings['scope'])) {
             $conditions = array_merge($conditions, $this->settings['scope']);
         }
         $result = ClassRegistry::init($userModel)->find('first', array('conditions' => $conditions, 'recursive' => 0));
         if (empty($result) || empty($result[$model])) {
             $session_name = $this->settings['session'];
             CakeSession::write($session_name, $user);
             return false;
         }
         unset($result[$model][$fields['password']]);
         $user->id = $result[$model]['_id'];
         $session_name = $this->settings['session'];
         CakeSession::write($session_name, $user);
         return $result[$model];
     }
     return false;
 }
 public function login()
 {
     if (isset($this->Controller->request->query['code'])) {
         $code = $this->Controller->request->query['code'];
     }
     if (isset($this->Controller->request->query['state'])) {
         $state_request = $this->Controller->request->query['state'];
     }
     if (empty($code)) {
         CakeSession::write('state', md5(uniqid(rand(), TRUE)));
         $state_session = CakeSession::read('state');
         // CSRF protection
         $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . $this->app_id . "&redirect_uri=" . urlencode($this->my_url) . "&state=" . $state_session . "&scope=email";
         $this->__redirectFunc($dialog_url);
     }
     if (CakeSession::read('state') && CakeSession::read('state') === $state_request) {
         $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $this->app_id . "&redirect_uri=" . urlencode($this->my_url) . "&client_secret=" . $this->app_secret . "&code=" . $code;
         $response = file_get_contents($token_url);
         parse_str($response, $params);
         CakeSession::write('access_token', $params['access_token']);
         $graph_url = "https://graph.facebook.com/me?access_token=" . CakeSession::read('access_token');
         $user = json_decode(file_get_contents($graph_url));
         return $user;
     } else {
         echo "The state does not match. You may be a victim of CSRF.";
     }
 }
 /**
  * Signin URL
  *
  * @param string Anchor text
  * @param string redirect url
  * @return string HTML tag
  */
 public function signin($text = 'Login', $redirect = null, $scope = null)
 {
     $api = Configure::read('SocialSignIn.API.Twitter');
     $url = Router::url(array('plugin' => 'social_sign_in', 'controller' => 'oauth', 'action' => 'signin'));
     CakeSession::write($this->session . '.callback', $redirect, true);
     $output = '<a href="' . $url . '">' . $text . "</a>\n";
     return $output;
 }
Example #11
0
 public function testListLanguages()
 {
     CakeSession::delete('Config.language');
     $result = $this->MultiLanguage->listLanguages();
     $this->assertRegExp('/<span class="hhh">\\s*English\\s*<\\/span>/i', $result);
     CakeSession::write('Config.language', 'fra');
     $result = $this->MultiLanguage->listLanguages();
     $this->assertRegExp('/<span class="hhh">\\s*Français\\s*<\\/span>/i', $result);
 }
Example #12
0
 public function afterSave($created, $options = array())
 {
     parent::afterSave($created, $options);
     if (AuthComponent::user()) {
         App::uses('CakeSession', 'Model/Datasource');
         CakeSession::write('Auth', $this->findById(AuthComponent::user('id')));
     }
     return true;
 }
Example #13
0
 /**
  * QloginControllerTest::testAdminIndex()
  *
  * @return void
  */
 public function testAdminReset()
 {
     $user = array('id' => 1, 'role_id' => 1);
     CakeSession::write('Auth.User', $user);
     $url = Router::url(array('admin' => true, 'plugin' => 'tools', 'controller' => 'tiny_urls', 'action' => 'reset'));
     $result = $this->testAction($url, array('return' => 'contents'));
     $this->assertNull($result);
     $this->assertTextContains('admin/tools/tiny_urls', $this->headers['Location']);
 }
Example #14
0
 /**
  * testAdminMenus
  */
 public function testAdminMenus()
 {
     CakeSession::write('Auth.User', array('id' => 1, 'role_id' => 1));
     CroogoNav::add('contents', array('title' => 'Contents', 'url' => '#'));
     $items = CroogoNav::items();
     $expected = '<ul class="nav nav-stacked"><li><a href="#" class="menu-contents sidebar-item"><i class="icon-white icon-large"></i> <span>Contents</span></a></li></ul>';
     $result = $this->Croogo->adminMenus(CroogoNav::items());
     $this->assertEquals($expected, $result);
 }
 public function setCartConfiguration(Model $Model, $id, $configuration)
 {
     $products = CakeSession::read('WebshopShoppingCart.products');
     if ($products === null) {
         $products = array();
     }
     $products[$id]['configuration'] = $configuration;
     CakeSession::write('WebshopShoppingCart.products', $products);
 }
 /**
  * Initializes a new api transaction session
  *
  * @param string $processorClass 
  * @param string $orderId Order UUID
  * @return string
  */
 public function initialize($processorClass, $orderId)
 {
     $token = str_replace('-', '', String::uuid());
     CakeSession::write('Payment', array('orderId' => $orderId, 'token' => $token, 'processor' => $processorClass));
     CakeSession::write('Payment.token', $token);
     CakeSession::write('Payment.processor', $processorClass);
     $this->write('payment', __d('cart', 'Payment process started'));
     return $token;
 }
Example #17
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->generateNc('ControlPanel.ControlPanel', array('components' => array('ControlPanel.ControlPanelLayout')));
     CakeSession::write('getNotificationError', null);
     $this->controller->Notification = $this->getMockForModel('Notifications.Notification', array('validCacheTime', 'ping', 'serialize', 'updateNotifications'));
     $this->_mockForReturn('Notifications.Notification', 'validCacheTime', false);
     $this->_mockForReturn('Notifications.Notification', 'ping', true);
 }
 public function testInitialize()
 {
     CakeSession::delete('Config.language');
     $this->MultiLanguageComponent->initialize($this->Controller);
     $fallback = array_keys(Configure::read('MultiLanguage.fallback'));
     $this->assertEqual(Configure::read('Config.language'), $fallback[0]);
     CakeSession::write('Config.language', 'deu');
     $this->MultiLanguageComponent->initialize($this->Controller);
     $this->assertEqual(Configure::read('Config.language'), 'deu');
 }
Example #19
0
 public function setUp()
 {
     parent::setUp();
     // BUGFIX for CakePHP2.5 - One has to write to the session before deleting actually works
     CakeSession::write('Auth', '');
     CakeSession::delete('Auth');
     $this->Controller = new CommonComponentTestController(new CakeRequest(), new CakeResponse());
     $this->Controller->constructClasses();
     $this->Controller->startupProcess();
 }
Example #20
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     unset($this->Block);
     unset($this->Video);
     unset($this->VideoBlockSetting);
     unset($this->VideoFrameSetting);
     unset($this->VideoViewLog);
     CakeSession::write('Auth.User', null);
     parent::tearDown();
 }
Example #21
0
 /**
  * Sets the search history to the session
  *
  * Returns array
  *    []
  *        search_name
  *        search_id
  *
  * @param string $searchType
  * @param int $id
  * @param string $name
  * @return array
  */
 public function storeSearchResult($searchType, $id, $name)
 {
     $data = CakeSession::read($searchType);
     $data[] = array("search_name" => $name, "search_id" => $id);
     if (count($data) > 10) {
         array_shift($data);
     }
     //store the search in the session for the recent searches section
     CakeSession::write($searchType, $data);
     return $data;
 }
Example #22
0
 public static function currentSite($siteId = null)
 {
     $_this = Sites::getInstance();
     self::$_site = $_this->_getSite($siteId);
     $_this->_overrideSetting(array('title', 'tagline', 'theme', 'timezone', 'locale', 'status'));
     if (!empty(self::$_site['SiteMeta'])) {
         $_this->_overrideMeta();
     }
     CakeSession::write(self::$_sessionKey, self::$_site);
     return self::$_site;
 }
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     if (!CakeSession::check($this->_strategy)) {
         $config = ClassRegistry::init('Opauth.OpauthSetting')->findByName($this->_strategy);
         if (!empty($config['OpauthSetting'])) {
             CakeSession::write($this->_strategy, $config['OpauthSetting']);
         }
     }
     $this->_config = CakeSession::read($this->_strategy);
 }
 public function currentBasketId()
 {
     if (!CakeSession::check('WebshopShoppingBasket.current_basket_id')) {
         $basketId = $this->createBasket();
         if (!$basketId) {
             return false;
         }
         CakeSession::write('WebshopShoppingBasket.current_basket_id', $basketId);
     }
     return CakeSession::read('WebshopShoppingBasket.current_basket_id');
 }
 public function setFlash($message, $element = 'default', $params = array(), $key = 'flash')
 {
     if ($flashes = CakeSession::read('Message.' . $key)) {
         array_push($flashes, compact('message', 'element', 'params'));
         CakeSession::write('Message.' . $key, $flashes);
     } else {
         $flashes = array();
         array_push($flashes, compact('message', 'element', 'params'));
         CakeSession::write('Message.' . $key, $flashes);
     }
 }
Example #26
0
 /**
  * Login as given roles
  *
  * @param CakeTestCase $test CakeTestCase instance
  * @param string $role role key
  * @return void
  */
 public static function login(CakeTestCase $test, $role = Role::ROLE_KEY_SYSTEM_ADMINISTRATOR)
 {
     $test->controller->Components->Auth->staticExpects($test->any())->method('user')->will($test->returnCallback(function ($key = null) use($role) {
         CakeSession::write('Auth.User', self::$roles[$role]);
         if (isset(self::$roles[$role][$key])) {
             return self::$roles[$role][$key];
         } else {
             return self::$roles[$role];
         }
     }));
     $test->controller->Components->Auth->login(['username' => self::$roles[$role]['username'], 'password' => self::$roles[$role]['password']]);
 }
Example #27
0
 /**
  * SetUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->Controller = new MobileComponentTestController(new CakeRequest(null, false), new CakeResponse());
     $this->Controller->constructClasses();
     $this->Controller->Mobile->Controller = $this->Controller;
     CakeSession::write('User', '');
     CakeSession::delete('User');
     CakeSession::write('Session', '');
     CakeSession::delete('Session');
     Configure::delete('User');
 }
Example #28
0
 /**
  * AuthTest::testHasRoleWithSession()
  *
  * @return void
  */
 public function testHasRoleWithSession()
 {
     if (!defined('USER_ROLE_KEY')) {
         define('USER_ROLE_KEY', 'Role');
     }
     CakeSession::write('Auth.User.id', 1);
     $roles = [['id' => '1', 'name' => 'User', 'alias' => 'user'], ['id' => '2', 'name' => 'Moderator', 'alias' => 'moderator'], ['id' => '3', 'name' => 'Admin', 'alias' => 'admin']];
     CakeSession::write('Auth.User.' . USER_ROLE_KEY, $roles);
     $res = Auth::hasRole(4);
     $this->assertFalse($res);
     $res = Auth::hasRole(3);
     $this->assertTrue($res);
 }
Example #29
0
 /**
  * Used to set a session variable that can be used to output messages in the view.
  *
  * In your controller: $this->Flash->set('This has been saved');
  *
  * ### Options:
  *
  * - `key` The key to set under the session's Flash key
  * - `element` The element used to render the flash message. Default to 'default'.
  * - `params` An array of variables to make available when using an element
  *
  * @param string $message Message to be flashed. If an instance
  *   of Exception the exception message will be used and code will be set
  *   in params.
  * @param array $options An array of options.
  * @return void
  */
 public function set($message, $options = array())
 {
     $options += $this->_defaultConfig;
     if ($message instanceof Exception) {
         $options['params'] += array('code' => $message->getCode());
         $message = $message->getMessage();
     }
     list($plugin, $element) = pluginSplit($options['element'], true);
     if (!empty($options['plugin'])) {
         $plugin = $options['plugin'] . '.';
     }
     $options['element'] = $plugin . 'Flash/' . $element;
     CakeSession::write('Message.' . $options['key'], array('message' => $message, 'key' => $options['key'], 'element' => $options['element'], 'params' => $options['params']));
 }
Example #30
0
 /**
  * Handles the login of an admin user.
  *
  * @param string $user
  * @param string $pass
  * @return boolean
  */
 public function login($user, $pass)
 {
     require_once APPLICATION_PATH . MODEL_DIR . '/Admin_user.php';
     $admin_user = new Admin_user();
     $logged_in_user = $admin_user->getUser($user, $pass);
     if (!empty($logged_in_user)) {
         CakeSession::write('admin', true);
         CakeSession::write('auth', true);
         CakeSession::write('admin_user', $logged_in_user);
         return TRUE;
     } else {
         $this->status = FALSE;
         return FALSE;
     }
 }