Example #1
0
 /**
  * 单例模式,实例化对象
  * @return type
  */
 public static function instance()
 {
     if (self::$instance == NULL) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public function editAjaxAction()
 {
     \BUser::instance()->checkLogin();
     if ($this->request->isAjax()) {
         $headimg = $this->request->getPost('headimg', 'string') ? $this->request->getPost('headimg', 'string') : '';
         $sex = $this->request->getPost('sex', 'string') ? $this->request->getPost('sex', 'string') : '';
         $qq = $this->request->getPost('qq', 'string') ? $this->request->getPost('qq', 'string') : '';
         $email = $this->request->getPost('email', 'string') ? $this->request->getPost('email', 'string') : '';
         $nickname = $this->request->getPost('nickname', 'string') ? $this->request->getPost('nickname', 'string') : '';
     }
     $uid = $this->session->get('uid');
     $userInfo = \User::findFirst("id = {$uid}");
     //imgbase64转URL
     if (preg_match('/^(data:\\s*image\\/(\\w+);base64,)/', $headimg, $result)) {
         $type = $result[2];
         $new_file = __DIR__ . '/../../public/upload/head/haed_' . $uid . '.' . $type;
         if (!file_exists($new_file)) {
             //如果文件不存在(默认为当前目录下)
             $fh = fopen($new_file, "w");
             fclose($fh);
             //关闭文件
         }
         if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $headimg)))) {
             $new_file = '/upload/head/haed_' . $uid . '.' . $type;
         } else {
             $new_file = '';
         }
     } else {
         $new_file = '';
     }
     $sql = 'UPDATE `ys_user` SET ';
     if ($userInfo) {
         if ($new_file) {
             $sql .= "headimg = '" . $new_file . "',";
         }
         if ($sex) {
             $sql .= "sex = '" . $sex . "',";
         }
         if ($qq) {
             if (!is_numeric($qq)) {
                 \ToolFlash::error("请输入正确的QQ号码");
             }
             if (\User::findFirst("id != {$uid} AND qq={$qq}")) {
                 \ToolFlash::error("QQ号码已存在");
             }
             $sql .= "qq = '" . $qq . "',";
         }
         if ($email) {
             if (!\ToolCheck::is_email($email)) {
                 \ToolFlash::error("邮箱格式不正确");
             }
             if (\User::findFirst("id != {$uid} AND email='{$email}'")) {
                 \ToolFlash::error("邮箱已存在");
             }
             $sql .= "email = '" . $email . "',";
         }
         if ($nickname) {
             $sql .= "nickname = '" . $nickname . "',";
         }
         $sql .= "utime = '" . time() . "' WHERE id = {$uid}";
         $db = \BalanceDb::instance();
         if ($db->execute($sql)) {
             $userInfo = \User::findFirst("id = {$uid}");
             \BUser::instance()->setLoginSession($userInfo->toArray());
             \ToolFlash::success("修改成功");
         } else {
             foreach ($userInfo->getMessages() as $message) {
                 error_log(print_r($message, true));
             }
             \ToolFlash::error("修改失败");
         }
     } else {
         \ToolFlash::error("找不到用户信息");
     }
 }