优化后台秘密修改,前台文章评论状态判断

This commit is contained in:
tao 2021-12-25 13:52:30 +08:00
parent 1bb5c995cf
commit b9766d0c7b
9 changed files with 72 additions and 45 deletions

View File

@ -3,8 +3,8 @@
> TaoLer是一个简单迅捷的轻论坛系统适用于个人或组织区域型信息交流发布平台。
* 官网https://www.aieok.com
* 版本TaoLer 1.8.16
* 日期2021.12.21
* 版本TaoLer 1.8.17
* 日期2021.12.25
webman版新架构已适配90%

Binary file not shown.

View File

@ -176,32 +176,16 @@ class Admin extends AdminController
return View::fetch('set/user/repass');
}
//密码重设
//修改密码
public function repassSet()
{
$admin = AdminModel::find(Session::get('admin_id'));
if(Request::isAjax()){
$data = Request::param();
$salt = substr(md5(strtotime($admin['create_time'])),-6);
$pwd = substr_replace(md5($data['oldPassword']),$salt,0,6);
$data['oldPassword'] = md5($pwd);
if($admin['password'] != $data['oldPassword']){
return json(['code'=>-1,'msg'=>'当前密码错误']);
} elseif($data['password'] != $data['repassword']){
return json(['code'=>-1,'msg'=>'两次密码不一致']);
} else {
$password = md5(substr_replace(md5($data['password']),$salt,0,6));
$result = $admin->update([
'id' => $admin['id'],
'password' => $password
]);
if($result){
$res = ['code'=>0,'msg'=>'更新成功'];
} else {
$res = ['code'=>-1,'msg'=>'更新失败'];
}
return json($res);
}
$data = Request::only(['oldPassword','password','repassword']);
$data['admin_id'] = $this->aid;
$admin = new AdminModel;
$res = $admin->setpass($data);
return $res;
}
}

View File

@ -16,6 +16,12 @@ class Admin extends Model
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
protected $createTime = 'false';
//自动对password进行md5加密
protected function setPasswordAttr($value){
return md5($value);
}
//管理员关联角色
/*
@ -45,17 +51,19 @@ class Admin extends Model
public function login($data)
{
//查询用户
$admin = Db::name('admin')->where('username',$data['username'])->where('delete_time',0)->find();
$admin = $this->where('username',$data['username'])->where('delete_time',0)->find();
if(is_null($admin)){
return '用户名或密码错误';
return json(['code'=>-1,'msg'=>'用户名或密码错误']);
}
if($admin['status'] !=1){
return '用户被禁用或未审核,请联系管理员';
return json(['code' => -1,'msg'=> '用户被禁用或未审核,请联系管理员']);
}
//对输入的密码字段进行MD5加密再进行数据库的查询
$salt = substr(md5($admin['create_time']),-6);
$pwd = substr_replace(md5($data['password']),$salt,0,6);
$data['password'] = md5($pwd);
if($admin['password'] == $data['password']){
//将用户数据写入Session
@ -77,9 +85,45 @@ class Admin extends Model
);
//用户名密码正确返回1
return 1;
$res = ['code'=>0,'msg'=>'登陆成功', 'url'=>(string) url('index/index')];
} else {
return "用户名或密码错误!";
$res = ['code'=>-1,'msg'=>'用户名或密码错误','url'=>(string) url('admin/login')];
}
return json($res);
}
//修改密码
public function setpass($data)
{
$admin = $this->find($data['admin_id']);
$salt = substr(md5($admin['create_time']),-6);
$oldPassword = $this->pass($salt,$data['oldPassword']);
if($oldPassword != $admin['password']){
return json(['code'=>-1,'msg'=>'当前密码错误']);
}
if($data['password'] != $data['repassword']){
return json(['code'=>-1,'msg'=>'两次密码不一致']);
}
$data['password'] = substr_replace(md5($data['password']),$salt,0,6);
$admin->password = $data['password'];
$result = $admin->save();
if($result){
$res = ['code'=>0,'msg'=>'修改密码成功'];
} else {
$res = ['code'=>-1,'msg'=>'修改密码失败'];
}
return json($res);
}
//加密规则 加密字符串,原始秘密
protected function pass($salt, $pass)
{
$pwd = substr_replace(md5($pass),$salt,0,6);
return md5($pwd);
}
}

View File

@ -155,6 +155,7 @@ class User extends Model
$user = $this->find($data['user_id']);
$salt = substr(md5($user['create_time']),-6);
$pwd = substr_replace(md5($data['nowpass']),$salt,0,6);
//原注册密码加密规则
$data['nowpass'] = md5($pwd);
$result = $data['nowpass'] == $user['password'];
if(!$result){

View File

@ -84,12 +84,12 @@ class Article extends BaseController
$page = input('page') ? input('page') : 1;
$article = new ArticleModel();
$artDetail = $article->getArtDetail($id);
$arId = $artDetail->cate->id;
$tpl = Db::name('cate')->where('id',$arId)->value('detpl');
if(!$artDetail){
if(is_null($artDetail)){
// 抛出 HTTP 异常
throw new \think\exception\HttpException(404, '异常消息');
}
$arId = $artDetail->cate->id;
$tpl = Db::name('cate')->where('id',$arId)->value('detpl');
$comments = $artDetail->comments()->where('status',1)->order(['cai'=>'asc','create_time'=>'asc'])->paginate(['list_rows'=>10, 'page'=>$page]);
//$comment = new \app\common\model\Comment();
//$comments = $comment->getComment($id);
@ -119,6 +119,10 @@ class Article extends BaseController
//获取评论
$data = Request::only(['content','article_id','user_id']);
$sendId = $data['user_id'];
$art = Db::name('article')->field('id,status,is_reply,delete_time')->find($data['article_id']);
if($art['delete_time'] != 0 || $art['status'] != 1 || $art['is_reply'] != 1){
return json(['code'=>-1, 'msg'=>'评论不可用状态']);
}
if(empty($data['content'])){
return json(['code'=>0, 'msg'=>'评论不能为空!']);
}

View File

@ -7,7 +7,7 @@ return [
//应用名,此项不可更改
'appname' => 'TaoLer',
//版本配置
'version' => '1.8.15',
'version' => '1.8.17',
//加盐
'salt' => 'taoler',
//数据库备份目录

View File

@ -1 +1 @@
user-nav.html
!.gitignore

View File

@ -23,12 +23,6 @@
{:lang('my message')}
</a>
</li>
<li class="layui-nav-item {if($Request.action=='key')}layui-this{/if}">
<a href="{:url('Api/key')}">
<i class="layui-icon layui-icon-vercode"></i>
{:lang('my auth')}
</a>
</li>
<li class="layui-nav-item">
<a href="{:url('user/home',['id'=>session('user_id')])}">
<i class="layui-icon layui-icon-home"></i>