예제 #1
0
 /**
  * 修改个人密码
  */
 public function modifyUserPasswd($oldPasswd, $newPasswd)
 {
     if ($this->checkAuthority()) {
         $userOp = M('user');
         $user = session('LoginUser');
         $shlencryption = new userEncryption();
         $shlencryption->shlEncryption(trim($oldPasswd));
         if (strcmp($user['user_pwd'], $shlencryption->to_string()) == 0) {
             $shlencryption->shlEncryption(trim($newPasswd));
             $userData['user_pwd'] = $shlencryption->to_string();
             $modifyResult = $userOp->where("user_id = " . $user['user_id'])->save($userData);
             if ($modifyResult) {
                 $user['user_pwd'] = $shlencryption->to_string();
                 session('LoginUser', $user);
                 echo 'true';
             } else {
                 echo 'false ' . $userOp->getError();
             }
             return;
         } else {
             echo 'false 密码错误';
         }
     }
 }
예제 #2
0
 public function rRegist()
 {
     if (IS_POST) {
         $data['user_name'] = trim($this->_post('username'));
         //加密
         $shlencryption = new userEncryption();
         $shlencryption->shlEncryption(trim($this->_post('tpassword')));
         //传入
         $data['user_pwd'] = $shlencryption->to_string();
         $data['user_email'] = $this->_post('email');
         $data['user_signature'] = $this->_post('signature');
         // 文件 另外处理 $headicon = $this->_post('headicon');
         if (!empty($_FILES['headicon']['name'])) {
             import('ORG.Net.UploadFile');
             $upload = new UploadFile();
             // 实例化上传类
             //设置需要生成缩略图,仅对图像文件有效
             $upload->thumb = true;
             //设置需要生成缩略图的文件后缀
             $upload->thumbPrefix = 'thumb_';
             //生产1张缩略图
             //设置缩略图最大宽度
             $upload->thumbMaxWidth = '200';
             //设置缩略图最大高度
             $upload->thumbMaxHeight = '200';
             $upload->thumbRemoveOrigin = true;
             //移出原图
             $upload->maxSize = 3145728;
             // 设置附件上传大小
             $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
             // 设置附件上传类型
             $upload->savePath = './Upload/user/images/head/';
             // 设置附件上传目录
             $upload->saveRule = 'com_create_guid';
             //采用GUID序列命名
             if (!$upload->upload()) {
                 $this->error('图片上传失败!' . $upload->getErrorMsg());
             } else {
                 $info = $upload->getUploadFileInfo();
                 //保存当前数据对象
                 $data['user_headicon'] = 'thumb_' . $info[0]['savename'];
                 //保存blob头像
                 $data['user_head'] = file_get_contents('./Upload/user/images/head/' . $data['user_headicon']);
             }
         } else {
             $data['user_headicon'] = 'icon-head.png';
             $data['user_head'] = file_get_contents('./Public/images/icon-head.png');
         }
         $newUser = D('User');
         $result = $newUser->add($data);
         if ($result) {
             //TODO 注册成功,发送验证邮件,跳转到验证页面
             $loginUser = $newUser->where('user_id =' . $result)->select();
             if ($loginUser) {
                 session('LoginUser', $loginUser[0]);
                 U('UserHome/index', array(), 'html', true);
             } else {
                 U('Index/index', array(), 'html', true);
             }
         } else {
             //数据库存储失败,删除图片
             if ($data['user_headicon'] != '') {
                 unlink('./Upload/user/images/head/' . $data['user_headicon']);
             }
             $uploadFileName = './Upload/user/images/head/' . $data['user_headicon'];
             $this->error('创建失败: ' . $newUser->getError());
         }
     } else {
         $this->error('不是POST:' . $_SERVER['REQUEST_METHOD']);
     }
 }