Skip to content

Commit

Permalink
去除Validform表单验证依赖,更正后台数据验证
Browse files Browse the repository at this point in the history
  • Loading branch information
yuan-dian committed Nov 13, 2018
1 parent 568f89f commit 11cd106
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 180 deletions.
17 changes: 0 additions & 17 deletions application/admin/controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ public function logout()
session('user_auth_sign', null);
return ['msg'=>'退出成功','url'=>url('/admin/login')];
}
/**
* 修改密码
* @return array|mixed
* @author 原点 <467490186@qq.com>
* @throws \think\Exception\DbException
*/
public function editPassword()
{
if(request()->isPost()){
$data=input();
$uid=get_user_id();
$res=UserService::editPassword($uid,$data['oldpassword'],$data['password']);
return $res;
}else{
return $this->fetch();
}
}

/**
* 解锁
Expand Down
28 changes: 23 additions & 5 deletions application/admin/controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public function edit()
*/
public function check()
{
$map['user']=input('param');
$count=model('User')->where($map)->count();
if($count>0){
$msg=['status'=>'n','info'=>'账号已存在'];
$map['user']=input('username','','trim');
$res=model('User')->where($map)->field('uid')->find();
if($res){
$msg=['code'=>1,'msg'=>'账号已存在'];
}else{
$msg=['status'=>'y','info'=>'验证通过'];
$msg=['status'=>0,'info'=>'验证通过'];
}
return $msg;
}
Expand Down Expand Up @@ -172,4 +172,22 @@ public function groupList()
return $this->fetch();
}
}

/**
* 修改密码
* @return array|mixed
* @author 原点 <467490186@qq.com>
* @throws \think\Exception\DbException
*/
public function editPassword()
{
if(request()->isPost()){
$data=input();
$uid=$this->uid;
$res=UserService::editPassword($uid,$data['oldpassword'],$data['password']);
return $res;
}else{
return $this->fetch();
}
}
}
4 changes: 3 additions & 1 deletion application/admin/service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static function editPassword($uid,$oldpsd,$newpsd)
$list=User::get($uid);
if(!password_verify($oldpsd,$list['password'])){
$msg=Result::error('原密码错误');
return $msg;
}
$list->password=password_hash($newpsd, PASSWORD_DEFAULT);
$list->updatapassword=1;
Expand Down Expand Up @@ -147,6 +148,7 @@ public static function add($data)
//令牌数据无效时重置令牌
$validate->getError()!='令牌数据无效'? $token=Request::token():$token='';
$msg=Result::error($validate->getError(), null, ['token' =>$token]);
return $msg;
}
$user = new User;
$user->user = $data['user'];
Expand Down Expand Up @@ -231,7 +233,7 @@ public static function delete($uid)
$res=User::destroy($uid);
if($res){
AuthGroupAccess::where('uid','=',$uid)->delete();
$msg=Result::error('删除成功');
$msg=Result::success('删除成功');
}else{
$msg=Result::error('删除失败');
}
Expand Down
8 changes: 4 additions & 4 deletions application/admin/validate/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ class User extends Validate
{
protected $rule = [
'user' => 'require|max:25',
'password' => 'require|length:4,25',
'password' => 'require|length:6,25',
'code'=>'require|captcha'
];

protected $message = [
'user.require' => '用户名不能为空',
'user.max' => '用户名最大长度25位',
'user.length' => '用户名长度2-25位',
'password.require' => '密码不能为空',
'password.length' => '密码长度4-25位',
'password.length' => '密码长度6-25位',
'code.require'=>'验证码不能为空',
'code.captcha'=>'验证码错误'
];
public function sceneAdd()
{
return $this->only(['user','password'])->append('user', 'token');
return $this->only(['user','password'])->append('user', 'require|length:2,25|token');
}
}
61 changes: 0 additions & 61 deletions application/admin/view/login/edit_password.html

This file was deleted.

2 changes: 1 addition & 1 deletion application/admin/view/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//登录按钮
form.on("submit(login)",function(data){
var obj = $(this);
var data = $('#login-form').serialize();
var data = data.field;
obj.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
$.ajax({
url: "{:url('/admin/login')}",
Expand Down
13 changes: 10 additions & 3 deletions application/admin/view/system/clean_cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@
var $ = layui.jquery;
//监听提交
form.on('submit(save)', function(data){
$.post("{:url('/admin/cleanCache')}",data.field,function (res) {
layer.msg(res.msg, {time: 1500}, function () {
if (res.code) {
var obj = $(this);
obj.attr("disabled","disabled").addClass("layui-disabled");
$.post("{:url('/admin/cleanCache')}",data.field,function (data) {
var icon=5;
if(data.code){
icon=6;
}
layer.msg(data.msg, {icon:icon,time: 1500}, function () {
if (data.code) {
document.getElementById("form").reset();
}
obj.removeAttr("disabled").removeClass("layui-disabled");
});
});
return false;
Expand Down
19 changes: 13 additions & 6 deletions application/admin/view/system/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@
{/block}
{block name="script"}
<script>
layui.use(['form','jquery'], function(){
var form = layui.form;
var $ = layui.jquery;
layui.use(['form','jquery','layer'], function(){
var form = layui.form,$ = layui.jquery,layer=layui.layer;
//监听提交
form.on('submit(save)', function(data){
$.post("{:url('/admin/config')}",data.field,function (res) {
layer.msg(res.msg, {time: 1500}, function () {
if (res.code) {
var obj = $(this);
obj.attr("disabled","disabled").addClass("layui-disabled");
$.post("{:url('/admin/config')}",data.field,function (data) {
var icon=5;
if(data.code){
icon=6;
}
layer.msg(data.msg, {icon:icon,time: 1500}, function () {
if (data.code) {
location.reload();
}else{
obj.removeAttr("disabled").removeClass("layui-disabled");
}
});
});
Expand Down
55 changes: 28 additions & 27 deletions application/admin/view/system/edit_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
<div class="layui-form-item">
<label class="layui-form-label">所属层级</label>
<div class="layui-input-block">
{form:select name="pid" list="$menu" value="$data['pid']" option="['datatype'=>'*','nullmsg'=>'请选择层级!']"}
{form:select name="pid" list="$menu" value="$data['pid']" option="['lay-verif'=>'required']"}
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">名称</label>
<div class="layui-input-block">
<input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input" value="{:isset($data.title)?$data.title:''}" datatype="*" nullmsg="请输入名称!">
<input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input" value="{:isset($data.title)?$data.title:''}" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">url</label>
<div class="layui-input-block">
<input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input" value="{:isset($data.name)?$data.name:''}" datatype="*" nullmsg="请输入名称!">
<input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input" value="{:isset($data.name)?$data.name:''}" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
Expand Down Expand Up @@ -46,40 +46,41 @@
<div class="layui-form-item">
<div class="layui-input-block">
<input type="hidden" name="id" value="{:isset($data['id'])?$data['id']:''}">
<input type="hidden" name="__token__" id="token" value="{$Request.token}" />
<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
{/block}
{block name="script"}
{js href="/js/jquery.min.js" /}
{js href="/js/Validform_v5.3.2_min.js" /}

<script>
layui.use('form', function(){
var form = layui.form;
});
$("#form").Validform({
ajaxPost:true,
tiptype:function (msg,o,cssctl) {
if(o.type==3 && msg!='所填信息没有经过验证,请稍后…'){
layer.msg(msg, {time: 1500});//验证错误的提示
}
},
callback:function(data){ //ajax提交后的返回调用方法(相当于ajax里面的success那个方法)
layer.msg(data.msg, {time: 1500}, function () { //提示的插件,可以使用alert代替
if (data.code) {
setTimeout(function () {
//刷新父页面
parent.location.reload();
}, 500);
}else{
$('#token').val(data.data.token);
layui.use(['form','jquery','layer'], function(){
var form = layui.form,$=layui.jquery,layer=layui.layer;
//表单提交
form.on("submit(*)",function(data){
var obj = $(this);
obj.attr("disabled","disabled").addClass("layui-disabled");
$.post(data.form.action,data.field,function (data) {
var icon=5;
if(data.code){
icon=6;
}
});
}
layer.msg(data.msg,{icon: icon,time: 1500}, function () { //提示的插件,可以使用alert代替
if (data.code) {
setTimeout(function () {
//刷新父页面
parent.location.reload();
}, 500);
}else{
obj.removeAttr("disabled").removeClass("layui-disabled");
}
});
},'json');
return false;
});
});


</script>
{/block}
9 changes: 7 additions & 2 deletions application/admin/view/system/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@
if(obj.event === 'del'){
layer.confirm('确定删除操作?',{icon:3, title:'提示信息'},function(index){
$.post("{:url('/admin/deleteMenu')}",{id:data.id},function (data) {
layer.msg(data.msg);
var icon=5;
if(data.code){
obj.del();
icon=6;
}
layer.msg(data.msg,{icon: icon},function () {
if(data.code){
obj.del();//删除对应的行
}
});
});
});
}
Expand Down
14 changes: 11 additions & 3 deletions application/admin/view/system/site_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@
var $ = layui.jquery;
//监听提交
form.on('submit(save)', function(data){
$.post("{:url('/admin/siteConfig')}",data.field,function (res) {
layer.msg(res.msg, {time: 1500}, function () {
if (res.code) {
var obj = $(this);
obj.attr("disabled","disabled").addClass("layui-disabled");
$.post("{:url('/admin/siteConfig')}",data.field,function (data) {
var icon=5;
if(data.code){
icon=6;
}
layer.msg(data.msg, {icon: icon,time: 1500}, function () {
if (data.code) {
location.reload();
}else{
obj.removeAttr("disabled").removeClass("layui-disabled");
}
});
});
Expand Down
Loading

0 comments on commit 11cd106

Please sign in to comment.