diff --git a/app/controller/Base.php b/app/controller/Base.php index 581126fd..722f7de7 100644 --- a/app/controller/Base.php +++ b/app/controller/Base.php @@ -171,4 +171,33 @@ class Base { } return false; } + + protected function getCurrentTitle() { + $mate = ''; + $controller = strtr(strtolower($this->request->controller()), '.', '\\'); + $action = $this->request->action(); + $class = "\\app\\controller\\" . $controller; + if (class_exists($class)) { + $reflection = new \ReflectionClass($class); + $group_doc = $this->Parser($reflection->getDocComment()); + if(isset($group_doc['title'])){ + $mate = $group_doc['title']; + } + $method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC); + foreach ($method as $key => $v) { + if($action == $v->name){ + $title_doc = $this->Parser($v->getDocComment()); + if(isset($title_doc['title'])){ + $mate = $title_doc['title']; + } + } + } + } + return $mate; + } + + protected function Parser($text) { + $doc = new \doc\Doc(); + return $doc->parse($text); + } } diff --git a/app/controller/admin/Base.php b/app/controller/admin/Base.php index d748f69e..8831147c 100644 --- a/app/controller/admin/Base.php +++ b/app/controller/admin/Base.php @@ -243,33 +243,4 @@ class Base extends BaseC { View::assign('extend_menu', array('管理插件' => $menu)); } } - - protected function getCurrentTitle() { - $mate = ''; - $controller = strtr(strtolower($this->request->controller()), '.', '\\'); - $action = $this->request->action(); - $class = "\\app\\controller\\" . $controller; - if (class_exists($class)) { - $reflection = new \ReflectionClass($class); - $group_doc = $this->Parser($reflection->getDocComment()); - if(isset($group_doc['title'])){ - $mate = $group_doc['title']; - } - $method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC); - foreach ($method as $key => $v) { - if($action == $v->name){ - $title_doc = $this->Parser($v->getDocComment()); - if(isset($title_doc['title'])){ - $mate = $title_doc['title']; - } - } - } - } - return $mate; - } - - protected function Parser($text) { - $doc = new \doc\Doc(); - return $doc->parse($text); - } } \ No newline at end of file diff --git a/app/controller/user/Base.php b/app/controller/user/Base.php index bfe22661..c2bc4216 100644 --- a/app/controller/user/Base.php +++ b/app/controller/user/Base.php @@ -21,6 +21,7 @@ class Base extends BaseC { } if (!in_array($url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) { + View::assign('meta_title', isset($this->data['meta_title']) ? $this->data['meta_title'] : $this->getCurrentTitle()); } } @@ -36,6 +37,9 @@ class Base extends BaseC { $this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $pc_themes; } } + if(!is_dir($this->app->getRootPath() . $this->tpl_config['view_dir_name'])){ + $this->tpl_config['view_dir_name'] = 'public' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'default'; + } if ($template == '') { $template = str_replace(".", "@", strtolower($this->request->controller())) . "/" . $this->request->action(); } diff --git a/app/controller/user/Index.php b/app/controller/user/Index.php index 05d0a943..b9c0b682 100644 --- a/app/controller/user/Index.php +++ b/app/controller/user/Index.php @@ -8,6 +8,8 @@ // +---------------------------------------------------------------------- namespace app\controller\user; +use app\model\Member; + /** * @title 用户中心 */ @@ -26,7 +28,21 @@ class Index extends Base { * @return [type] [description] */ public function profile() { - return $this->fetch(); + if ($this->request->isPost()) { + $reuslt = (new Member())->editUser($this->request, session('userInfo.uid')); + if (false !== $reuslt) { + return $this->success('修改成功!'); + } else { + return $this->error('修改失败'); + } + }else{ + $info = Member::find(session('userInfo.uid')); + $this->data = [ + 'info' => $info, + 'keyList' => Member::$useredit + ]; + return $this->fetch('user@/edit'); + } } /** diff --git a/app/model/Member.php b/app/model/Member.php index 92c8abc9..e0326901 100644 --- a/app/model/Member.php +++ b/app/model/Member.php @@ -42,7 +42,7 @@ class Member extends Model { ['name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'], ]; - public $useredit = [ + public static $useredit = [ ['name'=>'uid','type'=>'hidden'], ['name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''], ['name'=>'sex','title'=>'性别','type'=>'select','option'=>[['key' => '0', 'label'=>'保密'],['key' => '1', 'label' =>'男'],['key' => '2', 'label'=>'女']],'help'=>''], @@ -208,17 +208,20 @@ class Member extends Model { return $info->append(['avatar', 'status_text'])->toArray(); } - public function editUser($request){ + public function editUser($request, $uid = 0){ $data = $request->post(); + $data['uid'] = $uid ? $uid : $data['uid']; if (!$data['uid']) { return false; } - if ($data['password'] !== '') { + if (isset($data['password']) && $data['password'] !== '') { $data['salt'] = \xin\helper\Str::random(6); return self::update($data, ['uid' => $data]); }else{ - unset($data['password']); + if(isset($data['password'])){ + unset($data['password']); + } return $this->where('uid', $data['uid'])->save($data); } } diff --git a/public/static/common/js/sent.js b/public/static/common/js/sent.js index 3347002c..1b26a62d 100644 --- a/public/static/common/js/sent.js +++ b/public/static/common/js/sent.js @@ -80,8 +80,8 @@ define(['jquery', 'layer', 'message'], function ($, layer) { var obj = {}, content; obj = window.sessionStorage.getItem(name); - if (sent.validatenull(obj)) obj = window.localStorage.getItem(name); - if (sent.validatenull(obj)) return; + if (sent.utils.validatenull(obj)) obj = window.localStorage.getItem(name); + if (sent.utils.validatenull(obj)) return; try { obj = JSON.parse(obj); } catch (error) { @@ -292,24 +292,24 @@ define(['jquery', 'layer', 'message'], function ($, layer) { } } return true; - } - }, - validatenull: function (val) { - if (typeof val == 'boolean') { + }, + validatenull: function (val) { + if (typeof val == 'boolean') { + return false; + } + if (typeof val == 'number') { + return false; + } + if (val instanceof Array) { + if (val.length == 0) return true; + } else if (val instanceof Object) { + if (JSON.stringify(val) === '{}') return true; + } else { + if (val == 'null' || val == null || val == 'undefined' || val == undefined || val == '') return true; + return false; + } return false; } - if (typeof val == 'number') { - return false; - } - if (val instanceof Array) { - if (val.length == 0) return true; - } else if (val instanceof Object) { - if (JSON.stringify(val) === '{}') return true; - } else { - if (val == 'null' || val == null || val == 'undefined' || val == undefined || val == '') return true; - return false; - } - return false; } }; window.sent = sent; diff --git a/public/template/default/user/base.html b/public/template/default/user/base.html index 33f0f0f6..2a0f6fd7 100644 --- a/public/template/default/user/base.html +++ b/public/template/default/user/base.html @@ -122,9 +122,8 @@

 

@@ -140,11 +139,13 @@

{:session('userInfo.nickname')}

+ {:session('userInfo.username')}