/** * 进行登录 */ public function todoAction() { // 参数检查 try { $request = $this->getRequest(); $username = $request->get('username'); $password = $request->get('password'); } catch (\Exceptions\Multi $e) { $this->json(FALSE, '手机号或密码格式不正确', 20001); } // 用户检查 $adminModel = new \AdminModel(); $adminArr = $adminModel->where('username=:u and password=:p and status=1', $username, $adminModel->enctypePassword($password))->limit(1)->select()->fetchRow(); if (!$adminArr) { $this->json(FALSE, '手机号或密码错误', 20002, $adminModel->enctypePassword($password)); } // 获取用户权限 $groupModel = new \GroupModel(); $groupArr = $groupModel->where('id=:id', $adminArr['group_id'])->select()->fetchRow(); // 计算用户权限 if ($groupArr['id'] != '*') { $rules = $adminArr['attach_rules'] ? explode(',', $adminArr['attach_rules']) : array(); $rules = implode(',', array_merge(explode(',', $groupArr['rules']), $rules)); } // 保存用户权限 $session = $this->getSession(); $session->set('admin.uid', $adminArr['id']); $session->set('admin.name', $adminArr['nickname']); $session->set('admin.ip', IP::client()); $session->set('admin.time', time()); $session->set('admin.avatar', $adminArr['avatar']); $session->set('admin.rules', $rules); // 登录成功返回 $this->json(TRUE, '登录成功', 20010); }
public function savepass() { $model = new AdminModel(); $id = session('adminid'); if (!IS_POST) { $this->message2('非法操作!', __APP__ . '/Admin'); } $password = I('password', ''); if ($password == '') { $this->message2('密码不能为空,请重新输入!', __URL__ . '/repass'); } if ($model->create()) { if (!empty($id)) { $data['password'] = md5(I('password')); if (false !== $model->where('id=\'' . $id . '\'')->data($data)->save()) { session('adminid', NULL); session('adminname', NULL); $this->message2('操作成功,请重新登陆系统', __APP__ . '/Admin'); } else { $this->message2('操作失败:' . $model->getDbError()); } } else { $this->message2('请选择编辑用户', __APP__ . '/Admin'); } } else { $this->message2('操作失败:数据验证( ' . $model->getError() . ' )', __URL__ . '/repass'); } }
public function check() { $db = new AdminModel(); $map['username'] = $_POST['userName']; $map['psd'] = MD5($_POST['pwd'] . q13as21345fdga); if ($_SESSION['verify'] != md5($_POST['verify'])) { $this->ajaxReturn(0, '验证码错误!', 0); } elseif (!$db->where($map)->find()) { $_SESSION['username'] = $_POST['userName']; $_SESSION['user_login_flag'] = true; $this->ajaxReturn(2, '登陆成功!正在跳转...', 2); $this->ajaxReturn(1, '用户名密码错误!', 1); } else { $_SESSION['username'] = $_POST['userName']; $_SESSION['user_login_flag'] = true; $this->ajaxReturn(2, '登陆成功!正在跳转...', 2); } }
public function check() { $db = new AdminModel(); $map['username'] = $_POST['userName']; $map['psd'] = MD5($_POST['psd'] . q13as21345fdga); if (!$db->where($map)->find()) { $this->assign('msg', '用户名或者密码错误!'); $this->display("Index:login"); } else { //echo "yes" ;exit; $_SESSION['user_login_flag'] = true; $_SESSION['username'] = $map['username']; $this->redirect('WapAdmin/index'); } }