Browse Source

密码修改

master
林一峰 7 years ago
parent
commit
3f0f3b75ba
  1. 49
      app/Http/Controllers/Api/UserController.php
  2. 38
      app/Http/Model/User.php
  3. BIN
      public/images/weixin/ad_tit.png
  4. 286
      resources/views/weixin/user/userinfo.blade.php
  5. 1
      routes/web.php

49
app/Http/Controllers/Api/UserController.php

@ -31,8 +31,15 @@ class UserController extends CommonController
//修改用户信息
public function userInfoUpdate(Request $request)
{
$data = '';
if($request->input('user_name', null)!==null){$data['user_name'] = $request->input('user_name');}
if($request->input('user_name', null)!==null)
{
$data['user_name'] = $request->input('user_name');
if(User::getOneUser($data))
{
return ReturnData::create(ReturnData::PARAMS_ERROR,null,'用户名已存在');
}
}
if($request->input('email', null)!==null){$data['email'] = $request->input('email');}
if($request->input('sex', null)!==null){$data['sex'] = $request->input('sex');}
if($request->input('birthday', null)!==null){$data['birthday'] = $request->input('birthday');}
@ -49,13 +56,47 @@ class UserController extends CommonController
if($request->input('password', null)!==null){$data['password'] = $request->input('password');}
if($request->input('head_img', null)!==null){$data['head_img'] = $request->input('head_img');}
if ($data != '')
if (isset($data))
{
User::modify(['id'=>Token::$uid],$data);
User::modify(array('id'=>Token::$uid),$data);
}
return ReturnData::create(ReturnData::SUCCESS);
}
//修改用户密码、支付密码
public function userPasswordUpdate(Request $request)
{
if($request->input('password', '')!='' && $request->input('old_password', '')!='')
{
$data['password'] = $request->input('password');
$data['old_password'] = $request->input('old_password');
if($data['password'] == $data['old_password']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'新旧密码相同');}
}
if($request->input('pay_password', '')!='')
{
$data['pay_password'] = $request->input('pay_password');
$data['old_pay_password'] = $request->input('old_pay_password','');
if($data['pay_password'] == $data['old_pay_password']){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'新旧密码相同');}
}
if (isset($data))
{
$res = User::userPasswordUpdate(array('id'=>Token::$uid),$data);
if($res === false)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS);
}
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
//用户列表
public function userList(Request $request)

38
app/Http/Model/User.php

@ -128,14 +128,46 @@ class User extends BaseModel
}
//获取用户信息
public static function getUserInfo($user_id)
public static function getUserInfo($user_id)
{
$user = self::where('id', $user_id)->first();
if(!$user){return false;}
$user->reciever_address = UserAddress::getOne($user->address_id);
$user->collect_goods_count = CollectGoods::where('user_id', $user_id)->count();
return $user;
$userinfo = $user->makeVisible(array('pay_password'))->toArray();
$user->pay_password = 0;
if($userinfo['pay_password']){$user->pay_password = 1;}
return $user;
}
//修改用户密码、支付密码
public static function userPasswordUpdate($where,array $param)
{
extract($param);
$data = '';
$user = self::where($where)->first();
if(!$user){return false;}
$user = $user->makeVisible(array('password','pay_password'))->toArray();
if(isset($old_password) && $old_password!=$user['password']){return false;} //旧密码错误
if(isset($password) && $password==''){return false;} //新密码为空
if(isset($old_pay_password) && $old_pay_password!=$user['pay_password']){return false;}
if(isset($pay_password) && $pay_password==''){return false;}
if(isset($password)){$data['password'] = $password;}
if(isset($pay_password)){$data['pay_password'] = $pay_password;}
if ($data != '' && self::where($where)->update($data))
{
return true;
}
return false;
}
//注册

BIN
public/images/weixin/ad_tit.png

Binary file not shown.

Before

Width: 140  |  Height: 90  |  Size: 5.3 KiB

After

Width: 140  |  Height: 90  |  Size: 3.0 KiB

286
resources/views/weixin/user/userinfo.blade.php

@ -22,7 +22,7 @@
<div class="floor">
<ul class="fui-list mt10">
<li>
<a href="javascript:update_avator();"><li>
<div class="ui-list-thumb">
<!-- <span style="background-image:url(<?php echo env('APP_URL'); ?>/images/weixin/no_user.jpg)"></span> -->
<form id="head_img" action="<?php echo env('APP_API_URL').'/image_upload'; ?>" method="post" enctype="multipart/form-data">
@ -35,15 +35,19 @@
<h4 class="ui-nowrap">头像</h4>
<div class="ui-reddot ui-reddot-static"></div>
</div>
<i id="avatorright" class="fa fa-angle-right" aria-hidden="true"></i>
</li>
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li></a>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/md5.min.js"></script>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/layer/mobile/layer.js"></script>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/jquery-form.js"></script>
<script type="text/javascript">
function update_avator()
{
$("#fileupload").trigger("click");
}
$(function(){
$("#avator,#avatorright").click(function(){
$("#fileupload").trigger("click");
});
$("#fileupload").change(function(){
$("#head_img").ajaxSubmit({
@ -85,6 +89,7 @@ $(function(){
<style>
.adr_add{margin:0 10px;}
.adr-form-group input[type=text],.adr-form-group input[type=password]{display:block;width:100%;font-size:16px;padding:12px;color:#777;vertical-align:middle;background-color:#fff;background-image:none;border:1px solid #ddd;border-radius:0;box-sizing:border-box;}
.bottoma{display:block;font-size:18px;padding:10px;border-radius:2px;}
</style>
<script>
function update_username()
@ -110,8 +115,28 @@ function update_username()
}
else
{
location.reload();
$.post('<?php echo env('APP_API_URL').'/user_info_update'; ?>',{user_name:user_name,access_token:'<?php echo $_SESSION['weixin_user_info']['access_token']; ?>'},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: '修改成功'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
},'json');
window.location.reload();
}
layer.close(index);
@ -135,7 +160,7 @@ function update_nickname()
'昵称修改',
'background-color: #FF4351; color:#fff;'
]
,content: '<div class="adr-form-group"><input type="text" name="nickname" class="" id="nickname" placeholder="请输入用户名"></div>'
,content: '<div class="adr-form-group"><input type="text" name="nickname" class="" id="nickname" placeholder="请输入昵称"></div>'
,btn: ['确定', '取消']
,yes: function(index){
var nickname = $("#nickname").val();
@ -150,8 +175,28 @@ function update_nickname()
}
else
{
location.reload();
$.post('<?php echo env('APP_API_URL').'/user_info_update'; ?>',{nickname:nickname,access_token:'<?php echo $_SESSION['weixin_user_info']['access_token']; ?>'},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: '修改成功'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
},'json');
window.location.reload();
}
layer.close(index);
@ -159,7 +204,7 @@ function update_nickname()
});
}
</script>
<a href="javascript:update_sex();"><li>
<a href="javascript:update_sex_layer();"><li>
<div class="ui-list-info">
<h4 class="ui-nowrap">性别</h4>
<div class="ui-txt-info"><?php if($user_info['sex']==0){echo '未知';}elseif($user_info['sex']==1){echo '男';}elseif($user_info['sex']==2){echo '女';} ?> &nbsp;</div>
@ -167,20 +212,66 @@ function update_nickname()
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li></a>
<script>
function update_sex()
function update_sex_layer()
{
//询问框
layer.open({
content: '<div style="padding:15px;"><a style="margin-bottom:10px;background-color:#1aad19;text-align:center;color:white;border:1px solid #179e16;" class="bottoma" onclick="layer.closeAll();" href="javascript:update_sex(1);">男</a><a style="margin-bottom:10px;background-color:#ea5a3d;text-align:center;color:white;border:1px solid #dd2727;" class="bottoma" onclick="layer.closeAll();" href="javascript:update_sex(2);">女</a></div>'
});
}
function update_sex(sex)
{
$.post('<?php echo env('APP_API_URL').'/user_info_update'; ?>',{sex:sex,access_token:'<?php echo $_SESSION['weixin_user_info']['access_token']; ?>'},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: '修改成功'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
},'json');
window.location.reload();
}
</script>
</ul>
<ul class="fui-list mt10">
<a href="javascript:update_password();"><li>
<div class="ui-list-info">
<h4 class="ui-nowrap">修改密码</h4>
<div class="ui-txt-info"> &nbsp;</div>
</div>
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li></a>
<script>
function update_password()
{
//询问框
layer.open({
title: [
'性别修改',
'修改密码',
'background-color: #FF4351; color:#fff;'
]
,content: '<div class="adr-form-group"><input type="text" name="sex" class="" id="sex" placeholder="请输入用户名"></div>'
,content: '<div class="adr-form-group"><input style="margin-bottom:10px;" type="password" name="old_password" class="" id="old_password" placeholder="请输入旧密码"><input type="password" name="password" class="" id="password" placeholder="请输入新密码"></div>'
,btn: ['确定', '取消']
,yes: function(index){
var sex = $("#sex").val();
var old_password = $("#old_password").val();
var password = $("#password").val();
if(sex == '')
if(password == '' || old_password=='')
{
layer.open({
content: '修改失败'
@ -190,8 +281,39 @@ function update_sex()
}
else
{
location.reload();
if(password == old_password)
{
layer.open({
content: '新旧密码一样'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
$.post('<?php echo env('APP_API_URL').'/user_password_update'; ?>',{password:md5(password),old_password:md5(old_password),access_token:'<?php echo $_SESSION['weixin_user_info']['access_token']; ?>'},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: '修改成功'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
},'json');
window.location.reload();
}
layer.close(index);
@ -199,23 +321,131 @@ function update_sex()
});
}
</script>
</ul>
<ul class="fui-list mt10">
<li>
<div class="ui-list-info">
<h4 class="ui-nowrap">修改密码</h4>
<div class="ui-txt-info"> &nbsp;</div>
</div>
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li>
<li>
<a href="javascript:<?php if($user_info['pay_password']){echo 'update_pay_password()';}else{echo 'set_pay_password()';} ?>;"><li>
<div class="ui-list-info">
<h4 class="ui-nowrap">支付密码</h4>
<div class="ui-txt-info"> &nbsp;</div>
</div>
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li>
</li></a>
<script>
//设置支付密码
function set_pay_password()
{
//询问框
layer.open({
title: [
'设置支付密码',
'background-color: #FF4351; color:#fff;'
]
,content: '<div class="adr-form-group"><input type="password" name="pay_password" class="" id="pay_password" placeholder="请输入新支付密码"></div>'
,btn: ['确定', '取消']
,yes: function(index){
var pay_password = $("#pay_password").val();
if(pay_password == '')
{
layer.open({
content: '设置失败'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
$.post('<?php echo env('APP_API_URL').'/user_password_update'; ?>',{pay_password:md5(pay_password),old_pay_password:'',access_token:'<?php echo $_SESSION['weixin_user_info']['access_token']; ?>'},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: '设置成功'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
},'json');
window.location.reload();
}
layer.close(index);
}
});
}
//修改支付密码
function update_pay_password()
{
//询问框
layer.open({
title: [
'修改支付密码',
'background-color: #FF4351; color:#fff;'
]
,content: '<div class="adr-form-group"><input style="margin-bottom:10px;" type="password" name="old_pay_password" class="" id="old_pay_password" placeholder="请输入旧支付密码"><input type="password" name="pay_password" class="" id="pay_password" placeholder="请输入新支付密码"></div>'
,btn: ['确定', '取消']
,yes: function(index){
var old_pay_password = $("#old_pay_password").val();
var pay_password = $("#pay_password").val();
if(pay_password == '' || old_pay_password == '')
{
layer.open({
content: '修改失败'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
if(pay_password == old_pay_password)
{
layer.open({
content: '新旧密码一样'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
$.post('<?php echo env('APP_API_URL').'/user_password_update'; ?>',{pay_password:md5(pay_password),old_pay_password:md5(old_pay_password),access_token:'<?php echo $_SESSION['weixin_user_info']['access_token']; ?>'},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: '修改成功'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
else
{
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
}
},'json');
window.location.reload();
}
layer.close(index);
}
});
}
</script>
</ul>
<div class="setting"><div class="close"><a href="<?php echo route('weixin_user_logout'); ?>" id="logout">安全退出</a></div></div>
</div>

1
routes/web.php

@ -131,6 +131,7 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::post('/user_signin', 'UserController@signin'); //签到
Route::get('/user_info', 'UserController@userInfo'); //用户详细信息
Route::post('/user_info_update', 'UserController@userInfoUpdate'); //修改用户信息
Route::post('/user_password_update', 'UserController@userPasswordUpdate'); //修改用户密码、支付密码
Route::get('/user_list', 'UserController@userList'); //用户列表
Route::get('/user_money_list', 'UserMoneyController@userMoneyList'); //用户余额明细

Loading…
Cancel
Save