public function addLogin($form = null) { $user = UserRoleManagerFactory::getUserRoleManager()->getUser(); $login = new Login(); $login->setUserId($user->getId()); $login->setUserName($user->getName()); $login->setUserRoleName($user->getUserRole()->getName()); $login->setUserRolePredefined($user->getUserRole()->getIsPredefined()); $login->save(); }
public function handle(User $rUser, Login $rLogin, Session $session) { $rLogin->setHash($_SESSION['Auth']['hash']); $rLogin->setIp($_SERVER['REMOTE_ADDR']); $rLogin->setDtIn(date('Y-m-d H:i:s')); $rLogin->setUserId($rUser->getId()); if (!$rLogin->save()) { return false; } return $this->next->handle($rUser, $rLogin); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Login(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Login'])) { $model->attributes = $_POST['Login']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->email_id)); } } $this->render('create', array('model' => $model)); }
public function gotosite($site = null) { if ($this->GetData('site')) { $site = $this->GetData('site'); } $site = Website::find_by_code($site); if (!$site) { Site::Flash('error', 'Unable to find the site you want to go to'); Redirect(''); } if ($user = Site::CurrentUser()) { try { $login = new Login(); $login->user_id = $user->id; $login->user = $user; $login->website_id = $site->id; $login->website = $site; $login->ip = Site::RemoteIP(); if ($login->save()) { header("Location: {$login->url}"); die; } else { Site::Flash('error', 'Unable to redirect you'); Redirect(''); } } catch (Error500 $e) { $error = 'Error'; if ($e->getMessage()) { $error .= ': ' . $e->getMessage(); } Site::Flash('error', $error); Redirect(''); } } else { if ($site) { header("Location: {$site->url}"); die; } Site::Flash('error', 'Unable to go to site'); Redirect(''); } }
public function setUpData() { $user = new User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->fb_id = '123456'; $user->save(); $this->_user_id = User::where('email', '*****@*****.**')->first()->user_id; $login = new Login(); $login->id = 1; $login->user_id = $this->_user_id; $login->session_id = '3f9a362bb40714f77cadfd9f5b9d801b'; $login->expired_at = '2019-07-30'; $login->save(); $this->_session = '3f9a362bb40714f77cadfd9f5b9d801b'; $this->_user_id = Login::where('session_id', $this->_session)->first()->user_id; $winery = new Winery(); $winery->id = 1; $winery->brand_name = 'Winery 1'; $winery->country_id = '1'; $winery->region = 'Abkhazia'; $winery->save(); $wine = new Wine(); $wine->wine_id = 1; $wine->name = 'Wine_1'; $wine->rakuten_id = 'rakuten_drinkshop_10508227'; $wine->original_name = "this is wine_1"; $wine->original_name_2 = "wine_1"; $wine->winery_id = 1; $wine->year = '2009'; $wine->wine_unique_id = '1_2009'; $wine->average_price = "2200.00"; $wine->average_rate = "3.5"; $wine->rate_count = "3"; $wine->save(); $this->session(array('user_id' => $this->_user_id)); }
public function saveOrUpdateLogin($model, &$person = null) { $prvlogin = strtolower($model->login); $model->attributes = $_POST['Login']; $model->login = strtolower($model->login); $model->pass = strtolower($model->pass); $isnew = empty($model->id); $success_saving_all = false; try { if(empty($person)) return $success_saving_all; if($isnew || $prvlogin !== $model->login) { $record = Personcompanyrole::model()->with(array( 'company' => array('condition'=>'company.id = ' . Yii::app()->user->company->id), 'login' => array('condition'=>'login.login="******"'), ))->together()->findAll(); $isduplicate = count($record) > 0 && isset($record[0]); } else { $isduplicate = false; } if($isduplicate) { return $success_saving_all; } if($isnew) { $model->created_at = new CDbExpression('NULL'); $model->updated_at = new CDbExpression('NULL'); } else { $model->updated_at = new CDbExpression('NULL'); } $withary = array( 'company' => array('condition'=>'company.id = ' . Yii::app()->user->company->id), 'person' => array('condition'=>'person.id = ' . $person->id), 'login' ); $records = Personcompanyrole::model()->with($withary)->together()->findAll(); $found = count($records) > 0; if($found) { foreach($records as $record) { if($record->role_id === $person->role_id) { $login = $record->login; break; } } if(empty($login)) { $login = new Login; } $login->login = $model->login; $login->pass = $model->pass; $login->status = 1; $success_saving_all = $login->save(); $person->login = $login; } else { $success_saving_all = $model->save(); $person->login = $model; } } catch (Exception $e) { $success_saving_all = false; Yii::log("Error occurred while saving/activating person. Rolling back... . Failure reason as reported in exception: " . $e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__); } return $success_saving_all; }
if ($request['METHOD'] == 'POST' && !empty($request['name']) && !empty($request['email']) && !empty($request['login']) && !empty($request['password']) && !empty($request['re_password']) && $request['password'] == $request['re_password'] && filter_var($request['email'], FILTER_VALIDATE_EMAIL)) { // $recaptcha = new ReCaptcha($secret); /* * $resp = $recaptcha->verify($request['g-recaptcha-response'], $request['REMOTE_ADDR']); */ $name = $request['name']; $email = $request['email']; $username = $request['login']; $password = $request['password']; $member = compact('name', 'email'); $model = new Member($member); $member = $model->save(); $id_member = $model->lastInsertId(); $login = compact('username', 'password', 'id_member'); $model = new Login($login); $login = $model->save(); if ($login && $member) { $password = md5($password); $sql = array('username' => $username, 'password' => $password, 'status' => '1'); $model = new Login(); $model->fields = array('username', 'id_member', 'status'); $rs = $model->get($sql); $sql = array('id_member' => $rs[0]['id_member']); $member = new Member(); $member->fields = array('name', 'email'); $rsMember = $member->get($sql); $rs = array_merge($rsMember[0], $rs[0]); Session::start(); Session::set('logado', $rs); ?> <script>
public static function login($input) { $error_code = ApiResponse::OK; $new_user = false; $user = null; if (array_key_exists('fb_id', $input) && !empty($input['fb_id'])) { $user = User::where('fb_id', $input['fb_id'])->first(); if ($user == null) { $user = new User(); $user->fb_id = $input['fb_id']; $user->save(); $user = User::find($user->id); $new_user = true; } } else { $validator = Validator::make($input, array('email' => 'required|email', 'password' => 'required')); //validate param if ($validator->fails()) { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } else { $user = User::where('email', $input['email'])->first(); if ($user == null || Hash::check($input['password'], $user->password) == false) { $error_code = ApiResponse::WRONG_AUTH; $data = ApiResponse::getErrorContent(ApiResponse::WRONG_AUTH); } } } if ($error_code == ApiResponse::OK) { $profile = Profile::where('user_id', $user->user_id)->first(); if (empty($profile)) { $profile = new Profile(); $profile->user_id = $user->user_id; $profile->save(); } $login = new Login(); $login->user_id = $user->user_id; $login->session_id = md5($user->user_id . microtime()); $login->expired_at = \Carbon\Carbon::now()->addYears(5); if ($login->save()) { $data = array("session" => $login->session_id, "user_id" => $login->user_id, "new_user" => $new_user); } } return array("code" => $error_code, "data" => $data); }
/** * Logs login actions by users to keep track of logins * @param int $status * @param string $details */ public static function log($status, $details) { $model = new Login(); $model->status = $status; $model->details = $details; $model->other_details = "User Agent: " . Yii::app()->request->userAgent . " IP Address: " . Yii::app()->request->userHostAddress; if (Yii::app()->user->id) { $model->user_id = Yii::app()->user->id; } $model->save(); }
/** * Displays the login page */ public function actionLogin() { $this->pageTitle = 'Login | ' . Yii::app()->name; $this->layout = '//layouts/accession'; $LoginForm = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($LoginForm); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { if (Login::model()->IPBanned()) { // this IP is banned $LoginForm->addError('email', Yii::app()->params['ipBanMessage']); } else { $LoginForm->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($LoginForm->validate() && $LoginForm->login()) { $User = User::model()->getUser(); if (!is_null($User)) { // Admin user $User->reset_hash = null; $User->save(); $login = new Login(); $login->success = 1; $login->user_id = $User->id; $login->date = date('Y-m-d H:i:s'); $login->ip = $_SERVER['REMOTE_ADDR']; $login->save(); $this->redirect(array('site/dashboard')); } else { // Accession user // Go straight to their details page $this->redirect(array('accession/updateDetails')); } } else { // Failed login $login = new Login(); $login->success = 0; $login->date = date('Y-m-d H:i:s'); $login->ip = $_SERVER['REMOTE_ADDR']; // See if we can find the user $User = User::model()->findByAttributes(array('email' => $_POST['LoginForm']['email'])); if ($User) { $login->user_id = $User->id; } $login->save(); // Check how many failed logins we have in last hour // If 5, we ban the IP if (!in_array($_SERVER['REMOTE_ADDR'], Yii::app()->params['ipWhiteList'])) { $criteria = new CDbCriteria(); $criteria->condition = "date > :date AND success = 0 AND ip = :ip"; $criteria->params = array(':ip' => $_SERVER['REMOTE_ADDR'], ':date' => date('Y-m-d H:i:s', strtotime('1 hour ago'))); $logins = Login::model()->findAll($criteria); if (sizeof($logins) >= 5 && !in_array($_SERVER['REMOTE_ADDR'], Yii::app()->params['ipWhiteList'])) { // Ban the ip $ipBan = new IpBan(); $ipBan->ip = $_SERVER['REMOTE_ADDR']; $ipBan->save(); $LoginForm->clearErrors(); $LoginForm->addError('email', 'Your IP has been banned for repeated failed login attempts. Please contact the site administrator.'); } elseif (sizeof($logins) == 4) { // Show warning $LoginForm->addError('password', 'You only have 1 login attempt remaining in this hour period. Another failed attempt within an hour and your IP will be banned.'); } } } } } // display the login form $this->render('login', array('LoginForm' => $LoginForm)); }
public function actionRegistration() { $id = Yii::app()->user->getState('sid'); $name = Yii::app()->user->getState('name'); $service = Yii::app()->user->getState('service'); if (!isset($id, $name, $service)) { Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('social', 'При авторизации произошла ошибка!')); $this->redirect(array('/user/account/login')); } $model = new User(); if (Yii::app()->request->isPostRequest && !empty($_POST['User'])) { $nick_name = $_POST['User']['nick_name']; $transaction = Yii::app()->db->beginTransaction(); try { $model->createAccount($nick_name, "{$nick_name}@{$nick_name}.ru", null, null, User::STATUS_ACTIVE); if ($model && !$model->hasErrors()) { //создадим запись в Login $login = new Login(); $login->setAttributes(array('user_id' => $model->id, 'identity_id' => Yii::app()->user->getState('sid'), 'type' => Yii::app()->user->getState('service'))); if (!$login->save()) { throw new CDbException(Yii::t('social', 'При создании учетной записи произошла ошибка!')); } $transaction->commit(); } else { throw new CDbException(Yii::t('social', 'При создании учетной записи произошла ошибка!')); } // авторизуем нового пользователя $socialLogin = new SocialLoginIdentity(Yii::app()->user->getState('service'), Yii::app()->user->getState('sid')); if ($socialLogin->authenticate()) { $this->cleanState(); Yii::app()->user->login($socialLogin); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('social', 'Вы успешно авторизовались!')); $this->redirect(array(Yii::app()->getModule('user')->loginSuccess)); } else { Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('social', 'При авторизации произошла ошибка!')); $this->cleanState(); $this->redirect(array('/user/account/login')); } } catch (Exception $e) { $transaction->rollback(); $this->cleanState(); Yii::log(Yii::t('social', "При авторизации через {servive} произошла ошибка!", array('{servive}' => Yii::app()->user->getState('service'))), CLogger::LEVEL_ERROR); Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('social', 'При создании учетной записи произошла ошибка!')); $this->redirect(array('/user/account/login')); } } $this->render('registration', array('model' => $model)); }
/** * Retrieves a one time URL for a login into a website * * @arg string The RPCSession code * @arg int The user ID to login * @arg string The name of the site * @arg string The IP of the user * * @param object $method The name of the RPC method * @param object $args An array of arguements, listed above * @return string The URL to use to access that site * @throws RPCException */ public function xlogin($method, $args) { $this->auth($args[0]); if (count($args) < 4) { throw new RPCException('Invalid Arguements', 500); } $user = User::find_by_id($args[1]); if (!$user) { throw new RPCException('Unable to find user', 500); } $site = Website::find_by_code($args[2]); if (!$site) { throw new RPCException('Unable to find site', 500); } $destination = ''; if (isset($args[4])) { $destination = $args[4]; } $login = new Login(); $login->user_id = $user->id; $login->user = $user; $login->website_id = $site->id; $login->website = $site; $login->destination = $destination; $login->ip = $args[3]; if ($login->save()) { return $login->url; } else { throw new RPCException($login->errorString(), 500); } }