Example #1
0
 public function loginAction()
 {
     if ($this->isLogin()) {
         $this->redirect(\Func\url('/', true));
     }
     if ($this->isAjax()) {
         $data = $this->request->getPost();
         if (empty($data)) {
             $this->pageError('param');
         }
         $modelForm = new OperatorForm('login');
         if ($result = $modelForm->validate($data)) {
             if ($info = $modelForm->login()) {
                 if ($info->status == Operator::STATUS_FREEZE) {
                     $this->error('该账号已冻结');
                 }
                 $_sess = ['oid' => $info->oid, 'username' => $info->username, 'rid' => $info->rid, 'rname' => Role::getNameById($info->rid), 'bname' => Branch::getNameById($info->bid), 'bid' => $info->bid, 'auth' => Operator::getAuthByRid($info->rid), 'expire' => time() + $this->getConfig('session', 'expire')];
                 $this->session->set('operator', $_sess);
                 $this->success(['msg' => '登录成功', 'redirect' => ['url' => \Func\url('/'), 'seconds' => 0]]);
             } else {
                 $this->error('账号或密码错误');
             }
         }
         $error = $modelForm->getErrors();
         if ($error) {
             $this->error($error);
         }
         $this->error('参数错误');
     }
     $this->single('login');
 }