예제 #1
0
 public function do_login()
 {
     if (IS_POST) {
         $returnUrl = $_SERVER['HTTP_REFERER'];
         if (empty($returnUrl)) {
             $returnUrl = U('Index/index');
         }
         $admin = D('Admin');
         // 自动验证 创建数据集
         if (!($data = $admin->create())) {
             $this->ajaxReturn(ReturnValue::faild($admin->getError()));
         }
         $pwd = $admin->password;
         // 组合查询条件
         $where = array();
         $where['username'] = $data['username'];
         $where['isdel'] = 0;
         $result = $admin->where($where)->field('id,username,password')->find();
         // 验证用户名 对比 密码
         if ($result && $result['password'] == $data['password']) {
             BaseController::do_login($result['id'], $result['username']);
             $this->ajaxReturn(ReturnValue::success($returnUrl));
         } else {
             $this->ajaxReturn(ReturnValue::faild('登录失败,用户名或密码不正确!'));
         }
     } else {
         if (BaseController::is_login()) {
             $this->redirect('Index/index');
         } else {
             $this->display("login");
         }
     }
 }
 public function changepassword()
 {
     if (IS_POST) {
         $password = I('post.password', '');
         $newpassword = I('post.newpassword', '');
         $confirmnewpassword = I('post.confirmnewpassword', '');
         if (strlen($newpassword) < 6 || strlen($newpassword) > 20) {
             $this->ajaxReturn(ReturnValue::faild('密码长度6--20位'));
         }
         if ($newpassword != $confirmnewpassword) {
             $this->ajaxReturn(ReturnValue::faild('两次密码输入不一致'));
         }
         $adminId = BaseController::get_login_userid();
         $admin = M('admin');
         $entity = $admin->find($adminId);
         if ($entity && $entity['password'] == $password) {
             $data['password'] = $newpassword;
             $admin->where('id=' . $adminId)->save($data);
             $this->ajaxReturn(ReturnValue::success("ok"));
         } else {
             $this->ajaxReturn(ReturnValue::faild('密码验证错误!'));
         }
     } else {
         $this->display();
     }
 }
예제 #3
0
 public function uploadCover()
 {
     $upload = new \Think\Upload();
     $upload->maxSize = 1048576;
     //1M
     $upload->exts = array('jpg', 'png', 'jpeg');
     $upload->rootPath = 'Public/images/cover/';
     $upload->savePath = '';
     $info = $upload->upload();
     //echo $info;
     if (!$info) {
         // 上传错误提示错误信息
         $this->ajaxReturn(ReturnValue::faild($upload->getError()));
     } else {
         // 上传成功
         $this->ajaxReturn(ReturnValue::success(__ROOT__ . "/" . $upload->rootPath . $upload->savePath . $info['file']['savepath'] . $info['file']['savename']));
     }
 }