/** * Displays the login page, * If there is an error in validation or parameters it returns the form code with errors * if everything is ok, it returns JSON with result=>1 and realname=>"..." parameters * ATTENTION: This function is also used by mobile clients */ public function actionLogin() { $model = new LoginForm(); $processOutput = true; // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and if ok return json data and end application. if ($model->validate() && $model->login()) { echo CJSON::encode(array("result" => "1", "id" => Yii::app()->user->id, "realname" => $model->getName(), "minDataSentInterval" => Yii::app()->params->minDataSentInterval, "minDistanceInterval" => Yii::app()->params->minDistanceInterval)); Yii::app()->end(); } if (Yii::app()->request->isAjaxRequest) { $processOutput = false; } } if (isset($_REQUEST['client']) && $_REQUEST['client'] == 'mobile') { if ($model->getError('password') != null) { $result = $model->getError('password'); } else { if ($model->getError('email') != null) { $result = $model->getError('email'); } else { if ($model->getError('rememberMe') != null) { $result = $model->getError('rememberMe'); } } } echo CJSON::encode(array("result" => $result)); Yii::app()->end(); } else { Yii::app()->clientScript->scriptMap['jquery.js'] = false; Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false; $this->renderPartial('login', array('model' => $model), false, $processOutput); } }
/** * Authenticate user logging in * * @author Kuldeep Dangi <*****@*****.**> */ public function actionLogin() { if (isset($_GET['username'])) { $model = new LoginForm(); $userModel = new Users(); $nCashModel = new Ncash(); //$userFollowObj = new UserFollow(); $model->attributes = $_GET; if ($model->validate() && $model->login()) { $userModel = $this->loadModel(Yii::app()->user->user_id); if (!empty($_GET['deviceType']) && !empty($_GET['deviceToken'])) { if (empty($userModel->deviceToken)) { $nCashModel->addAmount(Yii::app()->user->user_id, self::NCASH_AMOUNT_APP_LOGIN, 6); } $userModel->deviceType = $_GET['deviceType']; $userModel->deviceToken = $_GET['deviceToken']; $userModel->save(); } $this->result['success'] = true; $this->result['message'] = 'User logged in successfully.'; $this->result['data'] = $userModel; // $this->result['data']['profile'] = $userModel; // $this->result['data']['followers'] = // $userFollowObj->getUserFollowers($userModel->user_id); } else { $this->result['message'] = $model->getError('password'); } } $this->sendResponse($this->result); }
/** * Displays the login page */ public function actionLogin() { if (!Yii::app()->user->isGuest) { Yii::app()->user->logout(); } $this->makeSSL(); $model = new LoginForm(); $redirect = isset($_REQUEST["redirect"]) ? $_REQUEST["redirect"] : "index"; $error = ""; // collect user input data if (isset($_POST['username']) and isset($_POST["password"])) { $model->username = $_POST["username"]; $model->password = $_POST["password"]; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $this->redirect($redirect); } else { # Get Error from the login model $error = $model->getError('account'); # Log the error in the DB $log = new LogObj(); $log->ipaddress = $_SERVER["SERVER_ADDR"]; $log->username = "******"; $log->log_message = "Attempted to log in as '" . $_POST["username"] . "'. Returned error: " . $error; $log->type = "login"; $log->date_logged = date("Y-m-d H:i:s"); $log->save(); } } // display the login form $this->render('login', array('model' => $model, "error" => $error)); }
public function actionAjaxReg() { if(isset($_POST['Member'])) { $registerModel = new Member; $registerModel->attributes = $_POST['Member']; if($registerModel->validate()) { $registerModel->password = md5($registerModel->password); if($registerModel->save(false)){ $arr = array( 'status'=>'200', 'msg'=>'注册成功!', ); }else{ $arr = array( 'status'=>'302', 'msg'=>'注册失败!', ); } //注册成功,再自动登录 $loginModel = new LoginForm; $loginModel->username = $registerModel->name; $loginModel->password = $_POST['Member']['password'];//$registerModel->password; //$loginModel->attributes = $arr['LoginForm']; if($loginModel->login()){ $arr = array( 'status'=>'200', 'msg'=>'登录成功', ); }else{ $arr = array( 'status'=>'302', 'msg'=>$loginModel->getError(), ); } }else{ $arr = array( 'status'=>'302', 'msg'=>'表单不能为空!', ); } echo json_encode($arr); exit; }else{ $arr = array( 'status'=>'302', 'msg'=>'没有发送POST!', ); //$this->redirect('/login'); exit; } }