/** * Creates or retrieve user information and set the information in user session * * @param LightOpenID $openId */ public function loginSuccessful(LightOpenID $openId) { // namePerson/first, namePerson/last, contact/email $attributes = $openId->getAttributes(); $email = $attributes['contact/email']; $userTbl = new App_Model_DbTable_User(); $user = $userTbl->findByEmail($email); // The user has successfully authenticated // but it does not exist in our database, so create the record if (!$user) { $userArray = array('username' => $attributes['namePerson/first'] . $attributes['namePerson/last'], 'email' => $attributes['contact/email'], 'is_active' => 1, 'role_id' => 3); $userId = $userTbl->insert($userArray); $user = $userTbl->find($userId); } if ($user) { $auth = Zend_Auth::getInstance(); $authStorage = $auth->getStorage(); $authStorage->write($user); } }
/** * Change the user selected theme * * @return array * @todo refresh ACL User, because if user hits Reload the cached ACL User is used */ public function changeThemeAction() { $usModel = new App_Model_DbTable_User(); $auth = Zend_Auth::getInstance(); $user = $auth->getIdentity(); $tId = $this->request->getParam('id', null); if (is_numeric($tId) && $user) { $usModel->setTheme($tId, $user->getId()); return $this->responseSuccess(); } return $this->responseFailure('Could not save', 'Could not save theme, are you looged in?'); }
/** * tokenLoginAction * * Request method: POST * * End Point: /auth/token-login * * Parameters: * - vanity_url * - security_code * * Sample Request: * <pre style="border: 1px solid #3D578C; background: #E2E8F2"> * /auth/token-login (data is in the POST) * </pre> * * Sample Response: * <pre style="border: 1px solid #3D578C; background: #E2E8F2"> { "user_uuid": "e77a48ed-ff5a-4c12-9a59-5c48379d3160", "session_uuid": "361092b7-d0b8-406c-8409-41db2853baf2" } * </pre> * * @return void */ public function tokenLoginAction() { $form = new App_Form_Auth_TokenLogin(); $jsonData = $this->getRequestJson(); if ($form->isValid($jsonData)) { $data = $form->getValues(); // get the user $map = new App_Model_Map_User(); $user = $map->fetchByVanityUrl($data['vanity_url']); // validate the security code if ($data['security_code'] == App_Model_DbTable_User::getSecurityToken($user->user_uuid)) { // authenticate $auth = Glo_Auth::getInstance(); $auth->forceAuthenticate($user->user_uuid); $this->view->user_uuid = $user->user_uuid; $this->view->session_uuid = Zend_Session::getId(); // $map = new App_Model_Map_UserAction(); $map->save(array('user_uuid' => $this->view->user_uuid, 'action' => 'token login')); $this->_helper->json($this->view); } else { throw new Glo_Auth_Exception_Failed('Incorrect security token provided.'); } } else { throw new Glo_Exception_BadData(array_shift(array_shift($form->getMessages()))); } }
/** * update the whole dataset of the user by id * * @param array $data The userrow as an array from the DB * @return App_User $this */ public function update($data) { if (count($data) === 0) { throw new Exception('Could not update App_User, invalid user'); } $dbUser = new App_Model_DbTable_User(); $dbGroup = new App_Model_DbTable_Group(); $this->fromArray($data); // sets the whole userdata $groupRow = $dbGroup->find($this->get('groupid')); $this->set('groupname', $groupRow->current()->ug_name); $roles = array(); foreach ($dbUser->getRoleBinding($this->get('id'), $this->get('groupid')) as $role) { $key = $role['uar_id']; $roles[$key] = $role['uar_name']; } $this->setRole($roles); return $this; }