public function actionLogin() { Utils::ensureOpenId(); $openId = Yii::$app->request->get('open_id'); if (!Yii::$app->user->getIsGuest() && ($model = UcenterMember::findOne(['openid' => $openId])) !== null) { return $this->redirect(Url::to(['site/member'])); } if ($_POST) { $username = $_POST['username']; $password = $_POST['password']; $openid = $_POST['open_id']; $model = UcenterMember::findOne(['username' => $username]); $result = member::login($username, $password, 4); if ($result['errorNum'] == 0) { if (Yii::$app->user->login($model)) { $model->openid = $openid; $model->save(); return $this->redirect(Url::to(['site/member'])); } } else { return $this->goBack(['info' => $result['errorMsg']], Url::to(['login'])); } } return $this->view('login'); }
/** * 用户登陆 * @return array|string */ public function actionLogin() { $result = App::AppGet(); try { if ($result['errorNum']) { $result = array('errorNum' => $result['errorNum'], 'errorMsg' => $result['errorMsg'], 'data' => null); } else { $data = $result['data']; if (array_key_exists('phone', $data) && array_key_exists('pwd', $data) && array_key_exists('from', $data)) { $phone = $data['phone']; $pwd = $data['pwd']; $from = $data['from']; $sessionkey = ''; if (array_key_exists('sessionkey', $data)) { $sessionkey = $data['sessionkey']; } $result = member::login($phone, $pwd, $from, $sessionkey); } else { $result = array('errorNum' => '1', 'errorMsg' => '参数错误', 'data' => null); } } } catch (ErrorException $e) { Yii::error("登陆异常 方法:actionLogin 参数:" . json_encode($result['data']), "app"); Yii::trace($e->getMessage(), "app"); $result = array('errorNum' => '7', 'errorMsg' => '服务器异常,请联系管理员', 'data' => null); } $result = App::AppReturn($result); return $result; }