/** * Registrates the current user in the database table * @param active user name * @return boolean */ public function registerName(UserCredentials $userCredentials) { $name = $userCredentials->getUsername(); $password = $userCredentials->getPassword(); $this->dal->insertUser($name, $password); return true; }
/** * Attempts to authenticate * @param UserCredentials $uc * @return boolean */ public function doLogin(UserCredentials $uc) { $this->matchingPassword = $this->rcDAL->load($uc->getName()); $loginByUsernameAndPassword = \Settings::USERNAME === $uc->getName() && \Settings::PASSWORD === $uc->getPassword() || $this->matchingPassword != "" && password_verify($uc->getPassword(), $this->matchingPassword); if ($loginByUsernameAndPassword) { $user = new LoggedInUser($uc); $_SESSION[self::$sessionUserLocation] = $user; return true; } return false; }
/** * Attempts to authenticate * @param UserCredentials $uc * @return boolean */ public function doLogin(UserCredentials $uc) { $this->tempCredentials = $this->tempDAL->load($uc->getName()); $loginByUsernameAndPassword = \Settings::USERNAME === $uc->getName() && \Settings::PASSWORD === $uc->getPassword(); $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword()); if ($loginByUsernameAndPassword || $loginByTemporaryCredentials) { $user = new LoggedInUser($uc); $_SESSION[self::$sessionUserLocation] = $user; return true; } return false; }
public function tryRegister(UserCredentials $uc, &$user) { $this->userName = $uc->getUserName(); $this->password = $uc->getPassword(); $user = new User($this->userName, $this->password); if (!User::checkIfUserExists($this->userName)) { User::AddUser($user); $this->validRegister = true; return true; } else { return false; } }
/** * Attempts to authenticate * @param UserCredentials $uc * @return boolean */ public function doLogin(UserCredentials $uc) { $this->tempCredentials = $this->tempDAL->load($uc->getName()); $this->userDAL = new \model\UserDAL($this->conn); $this->existingUser = $this->userDAL->getUserFromDatabase($uc); if ($this->existingUser == null) { $loginByUsernameAndPassword = false; } else { $loginByUsernameAndPassword = $this->existingUser->{"username"} === $uc->getName() && $this->existingUser->{"password"} === $uc->getPassword(); } $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword()); if ($loginByUsernameAndPassword || $loginByTemporaryCredentials) { $user = new LoggedInUser($uc); $_SESSION[self::$sessionUserLocation] = $user; return true; } return false; }
public function alreadyActive($attribute, $params) { $criteria = new CDbCriteria(); $criteria->condition = 'email_id=:email && status=:status'; $criteria->params = array(':email' => $this->email, ':status' => 'EMAIL_NOT_VERIFIED'); if (!UserCredentials::model()->find($criteria)) { $this->addError('email', 'Your account is already active !'); } }
protected function afterLogin($fromCookie) { if (!$fromCookie) { $user = UserCredentials::model()->findByPK(Yii::app()->user->id); $user->last_login_time = new CDbExpression('NOW()'); $user->last_login_ip = SecurityUtils::getRealIp(); $user->save(); } }
public function exists($attribute, $params) { $criteria = new CDbCriteria(); $criteria->condition = 'email_id=:email'; $criteria->params = array(':email' => $this->email); if (!UserCredentials::model()->find($criteria)) { $this->addError('email', 'An account by that email does not exist !'); } }
/** * @param $userId * * @return CoostoAuthContainer * @throws Exception */ public function getAuthContainer($userId) { $userCredentials = $this->_UserCredentials->getCredentials($userId); $login = $this->_login($userCredentials['UserCredentials']['username'], $userCredentials['UserCredentials']['password']); if ($login['status'] !== 'success') { throw new Exception(sprintf('Could not authenticate Costoo user %s', $userCredentials['UserCredentials']['username'])); } $this->_coostoApi->addDefaultQueryString('sessionid', $login['data']['sessionid']); $authContainer = new CoostoAuthContainer(); $authContainer->coostoApi = $this->_coostoApi; return $authContainer; }
public function tryLoginUser(UserCredentials $toLogin) { $registered = $this->userDAL->getUserByName($toLogin->getUsername()); $tempPassword = $this->tempDAL->getTempPassword($toLogin->getUsername()); $loginByPostCredentials = password_verify($toLogin->getPassword(), $registered->getPassword()); $loginByCookies = $tempPassword != "" && $tempPassword === $toLogin->getCookiePassword(); if (!$loginByPostCredentials && !$loginByCookies) { throw new \WrongCredentialsException("Wrong credentials"); } $this->loginUser($toLogin); }
public function exists($attribute, $params) { if ($this->id) { $user = UserCredentials::model()->findByPk($this->id); if ($user) { $password = SecurityUtils::encryptPassword($this->currentPassword, $user->salt); $criteria = new CDbCriteria(); $criteria->condition = 'password=:password'; $criteria->params = array(':password' => $password); if (!UserCredentials::model()->find($criteria)) { $this->addError('currentPassword', 'Please enter your current password !'); } } else { $this->addError('currentPassword', 'Sorry, could not process your password modification request at this time !'); } } else { $this->addError('currentPassword', 'Sorry, could not process your password modification request at this time !'); } }
public function authenticate() { $user = UserCredentials::model()->findByAttributes(array('email_id' => $this->username)); if ($user === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($user->status != 'ACTIVE') { $this->errorCode = self::ERROR_USERNAME_INACTIVE; } else { if (!SecurityUtils::comparePasswords($this->password, $user->salt, $user->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->_username = $user->email_id; $this->setState('id', $user->id); $this->setState('emailId', $user->email_id); $this->setState('last_login_time', $user->last_login_time); $this->errorCode = self::ERROR_NONE; } } } return !$this->errorCode; }
/** * Attempts to authenticate * @param UserCredentials $uc * @return boolean */ public function doLogin(UserCredentials $uc, \model\RegisterModel $regModel) { $this->tempCredentials = $this->tempDAL->load($uc->getName()); $loginByUsernameAndPassword = false; $userData = $regModel->getUser($uc->getName()); if ($userData) { $userDataSep = explode("::", $userData); $pwDecrypt = password_verify(trim($uc->getPassword()), trim($userDataSep[1])); $loginByUsernameAndPassword = strcmp($uc->getName(), $userDataSep[0]) == 0 && $pwDecrypt; // $loginByUsernameAndPassword = (strcmp($uc->getName(), $userDataSep[0]) == 0) && (strcmp(trim($uc->getPassword()), trim($userDataSep[1])) == 0); } else { $loginByUsernameAndPassword = false; } $loginByTemporaryCredentials = $this->tempCredentials != null && $this->tempCredentials->isValid($uc->getTempPassword()); if ($loginByUsernameAndPassword || $loginByTemporaryCredentials) { $user = new LoggedInUser($uc); $_SESSION[self::$sessionUserLocation] = $user; return true; } return false; }
public function actionForgotPassword() { if (!Yii::app()->user->isGuest) { $this->redirect('/home'); } $model = new ForgotPasswordForm(); if (isset($_POST) && isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { // Generate Password here and redirect $tempPass = SecurityUtils::generateRandomString(8); $user = UserCredentials::model()->find('email_id=:email', array(':email' => $model->email)); if ($user) { $user->salt = SecurityUtils::generateSalt($user->email_id); $user->password = SecurityUtils::encryptPassword($tempPass, $user->salt); if ($user->save()) { $data['temp_password'] = $tempPass; $data['user'] = $user->id; EmailApi::sendEmail($model->email, "ACCOUNT.RESET.PASSWORD", $data); Yii::app()->user->setFlash('success', "We have sent you a new password to your email.\n\t\t\t\t\t\t<br/> Please add " . Yii::app()->params['adminEmail'] . " to your whitelist."); $this->redirect('/home'); } } } } $this->render('forgotPassword', array('model' => $model)); }
public static function searchBuilders($data) { $criteria = new CDbCriteria(); $criteria->alias = 'uc'; $criteria->join = 'LEFT JOIN user_profiles up on uc.id=up.user_id'; $condition = null; $params = null; if (isset($data['country_id']) && $data['country_id'] != "") { if ($condition != '') { $condition .= ' && '; } $condition .= 'up.country_id=:country_id'; $params[':country_id'] = $data['country_id']; } if (isset($data['state_id']) && $data['state_id'] != "") { if ($condition != '') { $condition .= ' && '; } $condition .= 'up.state_id=:state_id'; $params[':state_id'] = $data['state_id']; } if (isset($data['city_id']) && $data['city_id'] != "") { if ($condition != '') { $condition .= ' && '; } $condition .= 'up.city_id=:city_id'; $params[':city_id'] = $data['city_id']; } if (isset($data['keyword']) && $data['keyword'] != "") { if ($condition != '') { $condition .= ' && '; } $condition .= '(up.first_name like :keyword || up.last_name like :keyword || up.gender like :keyword || up.address_line1 like :keyword || up.address_line2 like :keyword || uc.email_id like :keyword)'; $params[':keyword'] = '%' . $data['keyword'] . '%'; } if ($data['user_type'] == "builder" && isset($data['property_type_id']) && $data['property_type_id'] != null) { $criteria->join .= ' LEFT JOIN property p on p.user_id=uc.id'; if ($condition != '') { $condition .= ' && '; } $condition .= '('; $propertyTypes = $data['property_type_id']; foreach ($propertyTypes as $i => $propertyType) { if ($i != 0) { $condition .= ' || '; } $condition .= 'p.property_type_id=' . $propertyType; } $condition .= ')'; } if ($condition != '') { $condition .= ' && '; } if ($data['user_type'] == "builder") { $condition .= 'uc.id IN (SELECT user_id FROM user_builder_profile)'; } if ($condition != null) { $criteria->condition = $condition; $criteria->params = $params; } $users = UserCredentials::model()->findAll($criteria); return $users; }
private function saveUser(UserCredentials $credentials) { $this->DAL->saveUserCredentials($credentials->getUsername(), $credentials->getPassword()); }
/** * Manages all models. */ public function actionAll() { $dependency = new CDbCacheDependency('SELECT MAX(updated_time) FROM user_credentials'); $models = UserCredentials::model()->cache(1000, $dependency)->findAll(); $this->render('all', array('models' => $models)); }
$address = new \UserAddress(); $address->setField('city', 'Timisoara'); $address->setField('str', 'Borsec'); $addresses[] = $address; $address = new \UserAddress(); $address->setField('city', 'New York'); $address->setField('str', 'Times Square'); $addresses[] = $address; $address = new \UserAddress(); $address->setField('city', 'Munchen'); $address->setField('str', 'Leopold Strasse'); $addresses[] = $address; $addresses->removeEntities(function ($entity) { return $entity->getField('city') == 'Timisoara'; }); $user->setField('addresses', $addresses); $personalInfo = new \UserPersonalInfo(); $personalInfo->setField('address', 'some fake address'); $personalInfo->setField('jobs', array('developer', 'cto')); $credentials = new \UserCredentials(); $credentials->setField('email', '*****@*****.**'); $credentials->setField('password', $authApi->hashPassword('password')); $user->setField('personalInfo', $personalInfo); $user->setField('credentials', $credentials); $newUser = $user; $return = \UserMapper::save($user); $newUser->setField('parentId', $return); $newUser->setField('_id', null); $newReturn = \UserMapper::save($newUser); $foundUser = \UserMapper::get($newReturn->getField('_id')); print_r($foundUser->toArray());
/** * Attempts to register * @param UserCredentials $uc * @return boolean * */ public function doRegister(UserCredentials $uc) { if ($uc->getName() == "") { return false; } else { if ($uc->getPassword() == "") { return false; } else { if (strlen($uc->getName()) < 3) { return false; } else { if (strlen($uc->getPassword()) < 6) { return false; } else { if (strcmp($uc->getPassword(), $uc->getTempPassword()) !== 0) { return false; } else { if ($this->usernameExists($uc->getName())) { return false; } else { if (preg_match('/[^a-zA-Z0-9]+/', $uc->getName(), $matches)) { return false; } else { $this->registerUser($uc->getName(), $uc->getPassword()); $this->message = "Registered new user."; return true; } } } } } } } return false; }
public static function searchAgentWithCriteria($criteria) { $users = UserCredentials::model()->findAll($criteria); return $users; }
public function __construct(UserCredentials $uc) { $this->userName = $uc->getName(); $this->client = $uc->getClient(); }
public static function getUserById($id) { return UserCredentials::model()->findByPk($id); }
public function actionPeople() { Yii::beginProfile('search_people'); $session = new CHttpSession(); $session->open(); //$session->destroy(); // Initiate the entities. $users = null; $data = null; $modelUser = new UserCredentials(); $modelProfile = new UserProfiles(); $modelSpecialistType = new UserSpecialistType(); $modelState = new GeoState(); $modelCity = new GeoCity(); $modelLocality = new GeoLocality(); if (isset($_POST['GeoCity'])) { $modelCity->attributes = $_POST['GeoCity']; } if (isset($_POST['user_type'])) { //$data = $_POST['UserProfiles']; $data['user_type'] = $_POST['user_type']; $data['property_type_id'] = isset($_POST['property_type_id']) ? $_POST['property_type_id'] : null; $data['state_id'] = isset($_POST['GeoState']['state']) ? $_POST['GeoState']['state'] : null; $data['city_id'] = isset($_POST['GeoCity']['city']) ? $_POST['GeoCity']['city'] : null; $data['keyword'] = isset($_POST['keyword']) ? $_POST['keyword'] : null; $data['specialist_type_id'] = isset($_POST['specialist_type_id']) ? $_POST['specialist_type_id'] : null; $data['locality_id'] = isset($_POST['GeoLocality']['locality']) ? $_POST['GeoLocality']['locality'] : ''; if ($data['specialist_type_id'][0] == '') { $data['specialist_type_id'] = null; } if ($data['locality_id'] != '') { $locality = GeoLocality::model()->find('locality=:locality', array(':locality' => $data['locality_id'])); if ($locality) { $data['locality_id'] = $locality->id; } } $totalResults = 0; if ($_POST['user_type'] == "agent") { $criteria = AgentProfileApi::getCriteriaObject($data); $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = AgentProfileApi::searchAgentWithCriteria($criteria); if (isset($_SERVER['HTTP_REFERER'])) { unset($session['search-criteria-user-type']); } $session['search-criteria-user-type'] = 'agent'; } if ($_POST['user_type'] == "builder") { $criteria = BuilderProfileApi::getCriteriaObject($data); $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = BuilderProfileApi::searchBuilderWithCriteria($criteria); if (isset($_SERVER['HTTP_REFERER'])) { unset($session['search-criteria-user-type']); } $session['search-criteria-user-type'] = 'builder'; } if ($_POST['user_type'] == "specialist") { $criteria = SpecialistProfileApi::getCriteriaObject($data); $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = SpecialistProfileApi::searchSpecialistsWithCriteria($criteria); if (isset($_SERVER['HTTP_REFERER'])) { unset($session['search-criteria-user-type']); } $session['search-criteria-user-type'] = 'specialist'; } $session['search-criteria-user'] = $criteria; $session['results-page'] = $totalResults; } else { if (isset($_SERVER['HTTP_REFERER'])) { unset($session['search-criteria-user-type']); unset($session['search-criteria-user']); } if (isset($session['search-criteria-user']) && isset($session['search-criteria-user-type'])) { $criteria = $session['search-criteria-user']; $userType = $session['search-criteria-user-type']; if ($userType == "agent") { $data['user_type'] = 'agent'; $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = AgentProfileApi::searchAgentWithCriteria($criteria); } elseif ($userType == "builder") { $data['user_type'] = 'builder'; $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = BuilderProfileApi::searchBuilderWithCriteria($criteria); } else { $data['user_type'] = 'specialist'; $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = SpecialistProfileApi::searchSpecialistsWithCriteria($criteria); } } else { $data['user_type'] = 'agent'; $criteria = AgentProfileApi::getCriteriaObject($data); $totalResults = UserCredentials::model()->count($criteria); $pages = new CPagination($totalResults); $pages->pageSize = Yii::app()->params['resultsPerPage']; $pages->applyLimit($criteria); $users = AgentProfileApi::searchAgentWithCriteria($criteria); } } $this->render('people', array('pages' => $pages, 'modelState' => $modelState, 'modelUser' => $modelUser, 'modelProfile' => $modelProfile, 'modelCity' => $modelCity, 'modelLocality' => $modelLocality, 'modelSpecialistType' => $modelSpecialistType, 'users' => $users, 'totalResults' => $totalResults, 'userType' => $data['user_type'])); Yii::endProfile('search_people'); }