前端用户中心功能完善
This commit is contained in:
@@ -171,4 +171,33 @@ class Base {
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,33 +243,4 @@ class Base extends BaseC {
|
|||||||
View::assign('extend_menu', array('管理插件' => $menu));
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ class Base extends BaseC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
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;
|
$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 == '') {
|
if ($template == '') {
|
||||||
$template = str_replace(".", "@", strtolower($this->request->controller())) . "/" . $this->request->action();
|
$template = str_replace(".", "@", strtolower($this->request->controller())) . "/" . $this->request->action();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\controller\user;
|
namespace app\controller\user;
|
||||||
|
|
||||||
|
use app\model\Member;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title 用户中心
|
* @title 用户中心
|
||||||
*/
|
*/
|
||||||
@@ -26,7 +28,21 @@ class Index extends Base {
|
|||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
*/
|
*/
|
||||||
public function profile() {
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class Member extends Model {
|
|||||||
['name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'],
|
['name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'],
|
||||||
];
|
];
|
||||||
|
|
||||||
public $useredit = [
|
public static $useredit = [
|
||||||
['name'=>'uid','type'=>'hidden'],
|
['name'=>'uid','type'=>'hidden'],
|
||||||
['name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''],
|
['name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''],
|
||||||
['name'=>'sex','title'=>'性别','type'=>'select','option'=>[['key' => '0', 'label'=>'保密'],['key' => '1', 'label' =>'男'],['key' => '2', 'label'=>'女']],'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();
|
return $info->append(['avatar', 'status_text'])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editUser($request){
|
public function editUser($request, $uid = 0){
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
|
$data['uid'] = $uid ? $uid : $data['uid'];
|
||||||
|
|
||||||
if (!$data['uid']) {
|
if (!$data['uid']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($data['password'] !== '') {
|
if (isset($data['password']) && $data['password'] !== '') {
|
||||||
$data['salt'] = \xin\helper\Str::random(6);
|
$data['salt'] = \xin\helper\Str::random(6);
|
||||||
return self::update($data, ['uid' => $data]);
|
return self::update($data, ['uid' => $data]);
|
||||||
}else{
|
}else{
|
||||||
unset($data['password']);
|
if(isset($data['password'])){
|
||||||
|
unset($data['password']);
|
||||||
|
}
|
||||||
return $this->where('uid', $data['uid'])->save($data);
|
return $this->where('uid', $data['uid'])->save($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ define(['jquery', 'layer', 'message'], function ($, layer) {
|
|||||||
var obj = {},
|
var obj = {},
|
||||||
content;
|
content;
|
||||||
obj = window.sessionStorage.getItem(name);
|
obj = window.sessionStorage.getItem(name);
|
||||||
if (sent.validatenull(obj)) obj = window.localStorage.getItem(name);
|
if (sent.utils.validatenull(obj)) obj = window.localStorage.getItem(name);
|
||||||
if (sent.validatenull(obj)) return;
|
if (sent.utils.validatenull(obj)) return;
|
||||||
try {
|
try {
|
||||||
obj = JSON.parse(obj);
|
obj = JSON.parse(obj);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -292,24 +292,24 @@ define(['jquery', 'layer', 'message'], function ($, layer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
},
|
validatenull: function (val) {
|
||||||
validatenull: function (val) {
|
if (typeof val == 'boolean') {
|
||||||
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;
|
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;
|
window.sent = sent;
|
||||||
|
|||||||
@@ -122,9 +122,8 @@
|
|||||||
<section class="content-header">
|
<section class="content-header">
|
||||||
<h1> </h1>
|
<h1> </h1>
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li><a href="#"><i class="fa fa-dashboard"></i> 用户中心</a></li>
|
<li><a href="{:url('/user/index/index')}"><i class="fa fa-dashboard"></i> 用户中心</a></li>
|
||||||
<li><a href="#">首页</a></li>
|
<li class="active">{$meta_title}</li>
|
||||||
<li class="active">我的</li>
|
|
||||||
</ol>
|
</ol>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -140,11 +139,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="pull-left info">
|
<div class="pull-left info">
|
||||||
<p>{:session('userInfo.nickname')}</p>
|
<p>{:session('userInfo.nickname')}</p>
|
||||||
|
<a href="{:url('/user/index/profile')}"><i class="fa fa-circle text-success"></i> {:session('userInfo.username')}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul class="sidebar-menu">
|
<ul class="sidebar-menu">
|
||||||
<li class="header">基础信息</li>
|
<li class="header">基础信息</li>
|
||||||
<li><a href="{:url('/user/index/profile')}"><i class="fa fa-book"></i> <span>个人资料</span></a></li>
|
<li><a href="{:url('/user/index/profile')}"><i class="fa fa-book"></i> <span>个人资料</span></a></li>
|
||||||
|
<li><a href="{:url('/user/index/avatar')}"><i class="fa fa-book"></i> <span>我的头像</span></a></li>
|
||||||
<li><a href="{:url('/user/index/repasswd')}"><i class="fa fa-book"></i> <span>修改密码</span></a></li>
|
<li><a href="{:url('/user/index/repasswd')}"><i class="fa fa-book"></i> <span>修改密码</span></a></li>
|
||||||
<li class="header">我的内容</li>
|
<li class="header">我的内容</li>
|
||||||
<li><a href="#"><i class="fa fa-book"></i> <span>我的内容</span></a></li>
|
<li><a href="#"><i class="fa fa-book"></i> <span>我的内容</span></a></li>
|
||||||
@@ -157,7 +158,7 @@
|
|||||||
{block name="body"}
|
{block name="body"}
|
||||||
<div class="box box-primary">
|
<div class="box box-primary">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title"></h3>
|
<h3 class="box-title">{$meta_title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body"></div>
|
<div class="box-body"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
{extend name="base" /}
|
||||||
|
{block name="body"}
|
||||||
|
<div class="box box-primary">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{$meta_title}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<form method="post" class="form form-horizontal" role="form">
|
||||||
|
{if !isset($info)}
|
||||||
|
{assign name="info" value="" /}
|
||||||
|
{/if}
|
||||||
|
{if !empty($fieldGroup)}
|
||||||
|
<div class="nav-tabs-custom">
|
||||||
|
<ul class="nav nav-tabs">
|
||||||
|
{volist name="fieldGroup" id="vGroup"}
|
||||||
|
<li {if $i eq 1}class="active"{/if}><a href="#tab{$key}" data-toggle="tab">{$key}</a></li>
|
||||||
|
{/volist}
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
{volist name="fieldGroup" id="vGroup"}
|
||||||
|
<div class="tab-pane fade {if condition="$i eq 1"}in active{/if}" id="tab{$key}">
|
||||||
|
{volist name="vGroup" id="field"}
|
||||||
|
{if $field['type'] eq 'hidden'}
|
||||||
|
<input type="hidden" name="{$field['name']}" value="{$info[$field['name']]|default=''}"/>
|
||||||
|
{else/}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">{$field['title']|htmlspecialchars}</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
{:form($field, $info)}
|
||||||
|
<div class="help-block">{$field['help']|default=''}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/volist}
|
||||||
|
</div>
|
||||||
|
{/volist}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{elseif isset($keyList) /}
|
||||||
|
{volist name="keyList" id="field"}
|
||||||
|
{if $field['type'] eq 'hidden'}
|
||||||
|
<input type="hidden" name="{$field['name']}" value="{$info[$field['name']]|default=''}"/>
|
||||||
|
{else/}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">{$field['title']|htmlspecialchars}</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
{:form($field, $info)}
|
||||||
|
<div class="help-block">{$field['help']|default=''}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/volist}
|
||||||
|
{/if}
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
|
{if isset($info['id'])}<input type="hidden" name="id" value="{$info['id']|default=''}">{/if}
|
||||||
|
<button class="btn btn-success submit-btn" type="submit">确 定</button>
|
||||||
|
<button class="btn btn-danger btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{extend name="base" /}
|
||||||
|
{block name="body"}
|
||||||
|
<div class="box box-primary">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{$meta_title}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
@@ -1 +1,41 @@
|
|||||||
{extend name="base" /}
|
{extend name="base" /}
|
||||||
|
{block name="body"}
|
||||||
|
<div class="box box-primary">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{$meta_title}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<!-- 修改密码表单 -->
|
||||||
|
<form method="post" class="form-horizontal" role="form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">原密码:</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="password" name="oldpassword" class="form-control " data-rule="required" autocomplete="off" />
|
||||||
|
<div class="help-block"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">新密码:</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="password" name="password" class="form-control " data-rule="required" autocomplete="off" />
|
||||||
|
<div class="help-block"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">确认密码:</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input type="password" name="repassword" class="form-control " data-rule="required" autocomplete="off" />
|
||||||
|
<div class="help-block"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
|
<input type="hidden" name="uid" value="{:session('userInfo.uid')}">
|
||||||
|
<button type="submit" class="btn btn-success submit-btn">确认提交</button>
|
||||||
|
<button class="btn btn-danger btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
Reference in New Issue
Block a user