示例#1
0
 /**
  * @dataProvider invalidDataProvider
  */
 public function testInvalid($scenario, $attributes, $errors)
 {
     $form = new LoginForm($scenario);
     $form->userIdentityClass = 'UserIdentity';
     $form->setAttributes($attributes);
     $this->assertFalse($form->validate());
     $this->assertEquals($errors, $form->getErrors());
 }
示例#2
0
 public function actionIndex()
 {
     $model = new LoginForm();
     if (isset($_POST['LoginForm'])) {
         //echo "<pre>";print_r($_REQUEST);
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate() && $model->login()) {
             //echo "<pre>";print_r($_REQUEST);die;
             if ($_POST['LoginForm']['logintype'] == 'company') {
                 //echo "fsfsf";die;
                 //$user = Login::model()->exists('email=:email',array('email'=>$$_POST['LoginForm']['email']));
                 $email = $_SESSION['_registration__id'];
                 //echo $email;die;
                 $rec = ServiceUser::model()->findByAttributes(array('email' => $email));
                 //echo "<pre>";print_r($rec);die;
                 Yii::app()->session['loggedId'] = $rec->id;
                 Yii::app()->session['type'] = 'company';
                 Yii::app()->session['companyname'] = ucfirst($rec->company_name);
                 $this->redirect(array('dashboard'));
             } else {
                 $email = $_SESSION['_registration__id'];
                 $rec = CustomerUser::model()->findByAttributes(array('email' => $email));
                 //echo "<pre>";print_r($rec);die;
                 Yii::app()->session['loggedId'] = $rec->id;
                 Yii::app()->session['type'] = 'customer';
                 Yii::app()->session['customername'] = ucfirst($rec->cname);
                 $this->redirect(array('customerdashboard'));
             }
             //$this->redirect(array('dashboard'));
             //$this->redirect(array('dashboard'));
             //$rec=Login::model()->findByAttributes(array('email'=>$email,'password'=>$pass,'status'=>1));
             //$auth = new UserIdentity($email,$password);
             //$auth->authenticate();
             /* if()
                            { 
                            	  //Yii::app()->user->setState('id', $rec->id);
             	  //Yii::app()->session->add('id',$rec->id);
                               $this->redirect(array('dashboard'));
                            }
                            else
                            {
                                Yii::app()->user->setFlash('login', "Wrong Email and Password");
                                $this->redirect(array('index'));
                            }*/
         } else {
             $errors = $model->getErrors();
             //var_dump($errors);
         }
     }
     $links = CmsPages::model()->findAll();
     Yii::app()->params['MyArray'] = $links;
     $this->render('login', array('model' => $model));
 }
 public function run()
 {
     // Незачем выполнять последующие действия
     // для авторизованного пользователя:
     if (Yii::app()->user->isAuthenticated()) {
         $this->controller->redirect(Yii::app()->getUser()->getReturnUrl());
     }
     $module = Yii::app()->getModule('user');
     // Если восстановление отключено - ошбочка ;)
     if ($module->recoveryDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     // Новая форма восстановления пароля:
     $form = new LoginForm('recovery');
     if (($data = Yii::app()->getRequest()->getPost('LoginForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate() && Yii::app()->userManager->passwordRecovery($form->email)) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->ajax->success('Письмо с инструкциями отправлено на ваш E-mail.');
             } else {
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Письмо с инструкциями отправлено на ваш E-mail'));
             }
             $this->controller->redirect(array('/user/account/login'));
         } else {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 $errors = array();
                 foreach ($form->getErrors() as $error) {
                     $errors[] = $error[0];
                 }
                 Yii::app()->ajax->failure(implode('<br />', $errors));
             }
             /*
                             Yii::app()->user->setFlash(
                yupe\widgets\YFlashMessages::ERROR_MESSAGE,
                Yii::t('UserModule.user', 'Password recovery error.')
                             );
             * 
             */
         }
     }
     $this->controller->render('recovery', array('model' => $form));
 }
示例#4
0
 public static function login($params)
 {
     $resultInfo = array();
     $model = new LoginForm();
     $model->attributes = $params;
     $model->username = trim($model->username);
     if ($model->validate()) {
         $setInfoResult = LoginService::setUserInfo();
         if (!empty($setInfoResult)) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail']['username'] = $setInfoResult;
         } else {
             $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $model->getErrors();
     }
     return $resultInfo;
 }
 public function actionLogin()
 {
     if (!defined('CRYPT_BLOWFISH') || !CRYPT_BLOWFISH) {
         throw new CHttpException(500, "This application requires that PHP was compiled with Blowfish support for crypt().");
     }
     if (Yii::app()->user->isGuest) {
         $model = new LoginForm();
         // collect user input data
         if (isset($_POST['LoginForm'])) {
             $model->attributes = $_POST['LoginForm'];
             $model->email = $_POST['LoginForm']['email'];
             if ($model->validate() && $model->login()) {
                 echo json_encode(array('errors' => ''));
             } else {
                 $errors = $model->getErrors();
                 echo json_encode(array('errors' => $errors));
             }
         }
     } else {
         $this->redirect('/user/account');
     }
 }
 public function actionLogin()
 {
     if (!Yii::app()->user->isGuest) {
         if ($this->layout == 'application.views.touch.layouts.main') {
             $this->redirect($this->createUrl("/account/view"));
         } else {
             $this->redirect($this->createUrl("/account/index"));
         }
         return;
     }
     $model = new LoginForm();
     $errorMsg = $errorMsg_Wap = "";
     if ($msg = Yii::app()->request->getParam('msg', false)) {
         $errorMsg = $msg;
     }
     if (Yii::app()->request->isPostRequest) {
         if (empty($_POST['LoginForm']['phone'])) {
             $errorMsg_Wap = "Số điện thoại không được để trống";
         } else {
             $model->attributes = $_POST['LoginForm'];
             $model->phone = Formatter::formatPhone($_POST['LoginForm']['phone']);
             if ($model->validate() && $model->login()) {
                 MainUserIdentity::_logDetectMSISDN($_POST['LoginForm']['phone'], "F5", 'wap');
                 //LogDetectMsisdnModel::model()->logDetect(Formatter::formatPhone($_POST['LoginForm']['phone']), $_SERVER['REMOTE_ADDR'], 'F5', 'wap' , 1, "F5", NULL, NULL, $this->userSub->package_id, NULL, NULL, $_SERVER['REQUEST_URI']);
                 $back = Yii::app()->request->getParam('back', false);
                 if ($back) {
                     $this->redirect($back);
                 }
                 $this->redirect(Yii::app()->createUrl("/site"));
             } else {
                 $errors = $model->getErrors();
                 foreach ($errors as $key => $err) {
                     $errorMsg .= "<div class='errormsg'>{$err[0]}</div>";
                 }
             }
         }
     }
     $this->render('login', array('model' => $model, 'errorMsg' => $errorMsg, 'errorMsg_Wap' => $errorMsg_Wap));
 }
示例#7
0
 public function actionloginAffiliate()
 {
     if (isset($_GET["opauth"])) {
         try {
             $opauth_code = $_GET["opauth"];
             $response = unserialize(base64_decode($opauth_code));
             // Check if it's an error callback
             if (array_key_exists('error', $response) or !isset($response['auth'])) {
                 MyLog::Error('Error get info!');
                 $this->redirect('/');
             }
             $auth = $response['auth'];
             // Check if auth is missing info
             if (!isset($auth['provider']) or !isset($auth['uid']) or !isset($auth['info'])) {
                 MyLog::Error('Cannot get auth info!');
                 $this->redirect('/');
             }
             if (!in_array($auth['provider'], array('Facebook', 'Twitter', 'LinkedIn', 'Google', 'Orcid'))) {
                 MyLog::Error('Provider is not supported!');
                 $this->redirect('/');
             }
             $user = User::processAffiliateUser($auth);
             #process to mark as logined in
             $_SESSION['affiliate_login']['provider'] = $auth['provider'];
             $_SESSION['affiliate_login']['uid'] = $auth['uid'];
             #use useridentity to login
             $model = new LoginForm();
             $model->username = $auth['uid'];
             $model->password = $auth['uid'];
             #validate user input and redirect to the previous page if valid
             if ($model->validate()) {
                 $this->redirect(Yii::app()->user->returnUrl);
             } else {
                 Yii::log("FAILED VALIDATION: " . print_r($model->getErrors(), true), "error");
             }
         } catch (Exception $e) {
             MyLog::error(print_r($e, true));
             exit;
         }
     } else {
         $this->redirect('/');
     }
 }
    /**
     * Create a new account from Registration and then login
     * @param $model
     * @param $strPassword
     */
    protected function createAndLogin($model, $strPassword)
    {
        if (Yii::app()->params['MODERATE_REGISTRATION'] == 1) {
            $this->triggerEmailCampaign($model, 'onAddCustomer');
            Yii::app()->user->setFlash('success', Yii::t('customer', 'Your account has been created but must be approved before you can log in.
					 You will receive confirmation when you have been approved.'));
            $this->triggerEmailCampaign($model, 'onAddCustomer');
            $this->redirect($this->createUrl("/site"));
        }
        //We've successfully created the account, so just log in
        $loginModel = new LoginForm();
        $loginModel->email = $model->email;
        $loginModel->password = $strPassword;
        // validate user input and redirect to the previous page if valid
        if ($loginModel->validate() && $loginModel->login()) {
            Yii::app()->user->setFlash('success', Yii::t('customer', 'Your account has been created and you have been logged in automatically.'));
        } else {
            Yii::log("Error logging in our newly created user " . print_r($loginModel->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
            Yii::app()->user->setFlash('error', Yii::t('customer', 'Your account has been created but we had an error logging you in.'));
        }
        $this->triggerEmailCampaign($model, 'onAddCustomer');
        //Common SSL mode means we need to pass back to the original URL and log in again automatically
        if (Yii::app()->isCommonSSL) {
            $strIdentity = Yii::app()->user->id . "," . Yii::app()->shoppingcart->id . ",site,index";
            Yii::log('Log in ' . $strIdentity, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
            $redirString = _xls_encrypt($strIdentity);
            $url = Yii::app()->controller->createAbsoluteUrl('commonssl/login', array('link' => $redirString));
            $url = str_replace("https://" . Yii::app()->params['LIGHTSPEED_HOSTING_LIGHTSPEED_URL'], "http://" . Yii::app()->params['LIGHTSPEED_HOSTING_CUSTOM_URL'], $url);
        } else {
            $url = $this->createUrl("/site");
        }
        //No matter what happens, we always go home.
        $this->redirect($url);
    }
 /**
  * Checkout as a guest or as an existing user
  *
  * @return void
  */
 public function actionIndex()
 {
     $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     // did user leave checkout and come back?
     $returnRoute = $this->checkoutForm->getCheckoutPoint();
     if (is_null($returnRoute) === false && isset($_GET['showLogin']) === false) {
         // send user to correct checkout point
         $this->redirect($this->createAbsoluteUrl($returnRoute));
     }
     // if the user is already logged in take them straight to shipping
     if (!Yii::app()->user->isGuest) {
         $objCustomer = Customer::GetCurrent();
         $this->checkoutForm->contactEmail = $this->checkoutForm->contactEmail_repeat = $objCustomer->email;
         $this->checkoutForm->saveFormToSession();
         // set cart customer if missing
         $objCart = Yii::app()->shoppingcart;
         if ($objCart->customer_id !== $objCustomer->id) {
             $objCart->customer_id = $objCustomer->id;
             $objCart->save();
         }
         $this->redirect($this->createAbsoluteUrl('/checkout/shippingaddress'));
     }
     $this->publishJS('index');
     $this->layout = '/layouts/checkout-column2';
     $model = new LoginForm();
     $showLoginPasswordField = false;
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         // validate user input and continue if valid
         if ($model->guest == 0) {
             $showLoginPasswordField = true;
             $success = $model->validate() && $model->login();
         } else {
             $model->setScenario('Guest');
             $success = $model->validate();
         }
         if ($success) {
             $this->checkoutForm->passedScenario = $model->getScenario();
             $this->checkoutForm->contactEmail = strtolower($model->email);
             $this->checkoutForm->contactEmail_repeat = strtolower($model->email);
             $this->checkoutForm->saveFormToSession();
             if ($this->checkoutForm->validate()) {
                 if ($model->guest) {
                     $this->redirect($this->createAbsoluteUrl('/checkout/shipping'));
                 } else {
                     $this->redirect($this->createAbsoluteUrl("/checkout/shippingaddress"));
                 }
             }
         }
         $this->checkoutForm->addErrors($model->getErrors());
     }
     $blnShowLogin = false;
     if (isset($_SESSION['checkoutform.cache'])) {
         $model->email = $_SESSION['checkoutform.cache']['contactEmail'];
     }
     if (isset($_GET['showLogin'])) {
         $blnShowLogin = $_GET['showLogin'];
     }
     // display the login form
     $this->render('index', array('model' => $model, 'error' => $this->formatErrors(), 'blnShowLogin' => $blnShowLogin, 'showLoginPasswordField' => $showLoginPasswordField));
 }
示例#10
0
 public function run()
 {
     $controller = $this->getController();
     $model = new LoginForm();
     $userredis = new UserRedis();
     try {
         if (isset($_POST['UserLogin'])) {
             $model->attributes = $_POST['UserLogin'];
             if ($model->validate()) {
                 $user = UserRegistration::model()->find('LOWER(user_email)=?', array(strtolower($model->user_email)));
                 $userInfo = $userredis->getUserinfo(trim($user->uid));
                 $user_array = json_decode($userInfo, TRUE);
                 Yii::app()->session->open();
                 Yii::app()->session['userid'] = $user->uid;
                 Yii::app()->session['username'] = $user->user_name;
                 Yii::app()->session['mobile'] = $user->user_mobile;
                 Yii::app()->session['email'] = $user->user_email;
                 if (isset($_POST['UserLogin']['form_name'])) {
                     $state = 'mob_notchanged';
                     $this->seller_type = '';
                     $this->listingid = '';
                     $mobileno = '';
                     $mob_sta = '';
                     if ($_POST['UserLogin']['form_name'] == 'register_user') {
                         $html = $controller->renderPartial('/layouts/auth/_user_logout_form', array(), TRUE);
                         $html_ano = "";
                     } else {
                         if ($_POST['UserLogin']['form_name'] == 'contact_user') {
                             $html = $controller->renderPartial('/contactseller/_user_mobile_confirm_form', array('listingid' => $_POST['listingid']), TRUE);
                             $html_ano = $controller->renderPartial('/layouts/auth/_user_logout_form', array(), TRUE);
                         } else {
                             if ($_POST['UserLogin']['form_name'] == 'mobile_change') {
                                 /*Yii::import('application.controllers.contact_seller.UpdateusermobileAction');
                                 	 $mobileno_changed = 'mobile_changed';
                                 	 $obj =new UpdateusermobileAction($_POST['userid'],$_POST['mobileno']);
                                 	 $result = $obj->run();*/
                                 $userRedis = new UserRedis();
                                 $userInfo = $userRedis->getUserinfo($_POST['userid']);
                                 $user_array = json_decode($userInfo, TRUE);
                                 $useridArray = UserRegistration::model()->findAll(array('select' => 'uid', 'condition' => 'user_mobile=:user_mobile', 'params' => array(':user_mobile' => $_POST['mobileno'])));
                                 $user_array['mobile_status'] = '1';
                                 $user_array['mobile'] = $_POST['mobileno'];
                                 $userRedis->setUserinfo($_POST['userid'], json_encode($user_array));
                                 UserRegistration::model()->updateByPk($_POST['userid'], array('user_mobile' => $_POST['mobileno']));
                                 UserRegistration::model()->updateByPk($_POST['userid'], array('user_mobile_status' => '1'));
                                 if (!empty($useridArray)) {
                                     foreach ($useridArray as $key => $value) {
                                         if ($value['uid'] != '' && $_POST['userid'] != $value['uid']) {
                                             $userRinfo = $userRedis->getUserinfo($value['uid']);
                                             $userRarray = json_decode($userRinfo, TRUE);
                                             $userRarray['mobile_status'] = '0';
                                             $userRedis->setUserinfo($value['uid'], json_encode($userRarray));
                                             UserRegistration::model()->updateByPk($value['uid'], array('user_mobile_status' => '0'));
                                         }
                                     }
                                 }
                                 $html = $controller->renderPartial('/layouts/auth/_user_logout_form', array(), TRUE);
                                 $json_array = array('status' => 'sucess', 'html' => $html);
                                 echo json_encode($json_array);
                                 exit;
                             }
                         }
                     }
                 }
                 if (isset($_POST['result_user_mobile'])) {
                     $state = 'mob_changed';
                     $mob_sta = 'notverified';
                     if (isset($_POST['listingid'])) {
                         $this->listingid = $_POST['listingid'];
                         $this->currentDateTime = date('H:i');
                         $this->newDateTime = date('h:i A', strtotime($this->currentDateTime));
                         if ($this->currentDateTime >= Yii::app()->params['starttime'] && $this->currentDateTime <= Yii::app()->params['endtime']) {
                             $this->seller_type = 'view';
                         } else {
                             if ($userredis->getListingDetails($this->listingid, 'status')) {
                                 $this->seller_type = 'view';
                             } else {
                                 $this->seller_type = 'call';
                             }
                         }
                     }
                     if ($_POST['result_user_mobile'] != $user->user_mobile) {
                         $mobileno = $_POST['result_user_mobile'];
                         $user_array['mobile'] = $mobileno;
                         $sms_result = Yii::app()->sms->send_message($mobileno, $this->sms_type, $user->uid);
                         $html = $controller->renderPartial('/contactseller/_otp_form', array('seller_type' => $this->seller_type, 'user_array' => $user_array), TRUE);
                         $html_ano = $controller->renderPartial('/layouts/auth/_user_logout_form', array(), TRUE);
                     }
                 }
                 $json_array = array('status' => 'sucess', 'state' => $state, 'message' => 'User Details Verified Sucessfully', 'html' => $html, 'html_ano' => $html_ano, 'listingid' => $this->listingid, 'userid' => $user->uid, 'mobile_number' => $mobileno, 'mob_sta' => $mob_sta, 'url' => $controller->createUrl('contactseller/mobilenumberverification'));
                 echo json_encode($json_array);
             } else {
                 $_error = $model->getErrors();
                 $_error['status'] = 'error';
                 echo json_encode($_error);
             }
         }
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
         exit;
     }
 }
示例#11
0
 public function actionLogin()
 {
     $model = new LoginForm();
     //echo "<pre>";print_r($_REQUEST);die;
     // if it is ajax validation request
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate() && $model->login()) {
             //echo "<pre>";print_r($_SESSION);die;
             $user = $_SESSION['_admin__id'];
             $rec = Admin::model()->findByAttributes(array('username' => $user));
             //echo $rec->id;die;
             Yii::app()->session['username'] = $rec->id;
             $this->redirect('dashboard', array('model' => $model));
         } else {
             $errors = $model->getErrors();
             $this->render('index', array('model' => $model));
         }
     }
     // $this->render('index',array('model'=>$model));
     /*if(isset($_POST['LoginForm']) && $_POST['LoginForm']==='login-form')
     		{
     			//echo "<pre>";print_r($_REQUEST);die;
     			echo CActiveForm::validate($model);
     			Yii::app()->end();
     		}
     
     		// collect user input data
     		if(isset($_POST['LoginForm']))
     		{
     			
     			
     			
     			$uName=$_POST['LoginForm']['username'];
     			$uPass=$_POST['LoginForm']['password'];
     			$pass=md5($uPass);
     			$admin = Admin::model()->findByAttributes(array('username'=>$uName,'password'=>$pass));
                 $count=count($admin);
                 //echo $count;die;
                  $model->attributes=$_POST['LoginForm'];  
     			
                    
     				//$this->redirect(Yii::app()->user->returnUrl);
     				Yii::app()->session['username']=$uName;
                //Yii::app()->session->add('username',$uName);
     
     			if($count>0)
     			{
     			    //Yii::app()->session['username']=$uName;
                      Yii::app()->session['username']=$admin->id;
     				$this->redirect('dashboard',array('model'=>$model));
     			}
     			else
     			{
     			    $this->render('index',array('model'=>$model));		
     		 	}	
                  
     			
     		} */
     // display the login form
     //$this->render('index',array('model'=>$model));
 }
示例#12
0
 public function actionRegister()
 {
     if (isset(Yii::app()->user->roles)) {
         $this->render('return', array('returnurl' => Yii::app()->user->returnUrl));
     } else {
         $model = new RegisterForm();
         if (isset($_POST['RegisterForm'])) {
             // collect user input data
             $model->attributes = $_POST['RegisterForm'];
             //if the input is valid
             if ($model->validate()) {
                 $newuser = new User();
                 $newuser->name = $model->username;
                 $newuser->password = $model->password;
                 $newuser->auth = 1;
                 //update the database
                 if ($newuser->save()) {
                     $login = new LoginForm();
                     $login->attributes = $_POST['RegisterForm'];
                     // validate user input and redirect to the previous page if valid
                     if ($login->validate() && $login->login()) {
                         $this->redirect(Yii::app()->homeUrl);
                     } else {
                         print_r($login->getErrors());
                         exit;
                     }
                 } else {
                     print_r($newuser->getErrors());
                     exit;
                 }
             } else {
                 print_r($model->getErrors());
                 exit;
             }
             // validate user input and redirect to the previous page if valid
         }
         // display the login form
         $this->render('register', array('model' => $model));
     }
 }