/** * 登录 * http://demo.mpress_api.com/admin/login * @return bool */ public function loginAction() { $data = $this->getRequest()->getRequest(); if (!isset($data['username'])) { $this->responseJson(401, 'username is empty'); } else { if (empty($data['username'])) { $this->responseJson(401, 'username is empty'); } } if (!isset($data['password'])) { $this->responseJson(401, 'password is empty'); } else { if (empty($data['password'])) { $this->responseJson(401, 'password is empty'); } } $Admin = new AdminModel(); $ret = $Admin->login($data['username'], $data['password']); if ($ret[0]) { $_SESSION['adminid'] = $ret[2]; $this->responseJson(200, '登录成功'); } else { $this->responseJson(402, '登录失败'); } return false; }
public function loginAction() { //获取表单值 $user = $this->_getParam('user'); $pass = $this->_getParam('pass'); //实例化后台模型 $admin = new AdminModel(); //实例化session后台命名空间 $isValid = $admin->login($user, $pass); if ($isValid) { $this->session->adminName = $user; $this->_redirect('/admin/index/index'); } else { $this->_redirect('/admin/login/index'); } }
public function login() { if ($_POST) { $loginName = $_POST['loginName']; $password = $_POST['password']; if (isset($loginName) && isset($password)) { $adminModel = new AdminModel(); $_SESSION['admin'] = $adminModel->login($loginName, $password); if ($_SESSION['admin']) { R('Admin', 'setting'); } else { E('用户名或密码错误!'); } } } $this->display(); }
/** * 登录流程 */ public function doLoginAction() { if (!$this->getRequest()->isPost()) { $this->responseJson(401, '请求方式不正确'); } //$username = $this->getRequest()->getParam('username',''); //$password = $this->getRequest()->getParam('password',''); $username = $_POST['username']; $password = $_POST['password']; if (empty($username) && empty($password)) { $this->responseJson(401, '用户名或密码不能为空'); } $admin = new AdminModel(); $ret = $admin->login($username, $password); if ($ret[0]) { $_SESSION['adminid'] = $ret[2]; $this->responseJson(200, $ret[1]); } else { $this->responseJson(401, $ret[1]); } return false; }