7 changed files with 180 additions and 21 deletions
-
36app/Admin/Actions/Grid/v3/StoreUserPassword.php
-
63app/Admin/Controllers/v3/StoreUserController.php
-
73app/Admin/Forms/v3/StoreUserPasswordForm.php
-
2app/Admin/routes.php
-
10app/Models/v3/StoreUser.php
-
6config/label.php
-
11resources/lang/zh-CN/store-user.php
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid\v3; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use App\Admin\Forms\v3\StoreUserPasswordForm; |
||||
|
|
||||
|
class StoreUserPassword extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '修改密码'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$modal = Modal::make() |
||||
|
->xl() |
||||
|
->title($this->title) |
||||
|
->body(StoreUserPasswordForm::make()->setKey($id)) |
||||
|
->button($this->title); |
||||
|
|
||||
|
return $modal; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
|
||||
|
return [ |
||||
|
|
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms\v3; |
||||
|
|
||||
|
use App\Models\v3\GoodsBanners; |
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
use Symfony\Component\HttpFoundation\Response; |
||||
|
use App\Models\v3\StoreUser as StoreUserModel; |
||||
|
use App\Admin\Controllers\v3\StoreController; |
||||
|
|
||||
|
class StoreUserPasswordForm extends Form |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
// 获取外部传递参数
|
||||
|
$id = $input['id']; |
||||
|
$password= $input['password']; |
||||
|
|
||||
|
if($id > 0 && !empty($password)){ |
||||
|
$model = StoreUserModel::select('id','password','salt')->find($id); |
||||
|
$storeCon = new StoreController(); |
||||
|
$salt = $storeCon->random(8); |
||||
|
$passwordOld = $storeCon->stringHash($password,$model->salt); |
||||
|
|
||||
|
if($model && $model->password != $passwordOld){ |
||||
|
$model->salt = $salt; |
||||
|
$model->password = $storeCon->stringHash($password,$salt);; |
||||
|
if($model->save()){ |
||||
|
return $this->success('修改成功!'); |
||||
|
}else{ |
||||
|
return $this->error('修改失败!'); |
||||
|
} |
||||
|
}else{ |
||||
|
return $this->error('密码相同,无需修改!'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $this->error('请求参数为空!'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Build a form here. |
||||
|
*/ |
||||
|
public function form() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
$storeUser = StoreUserModel::select('username')->find($id); |
||||
|
$userName = empty($storeUser->username)?'':$storeUser->username; |
||||
|
$this->hidden('id')->value($id); |
||||
|
$this->display('username','账号')->value($userName); |
||||
|
$this->password('password')->minLength(6,'必须大于等于6位数')->required(); |
||||
|
$this->password('password_confirm','再次输入密码')->same('password'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue