Skip to content

Commit

Permalink
feat(admin): 增加验证用户支付时密码开关功能
Browse files Browse the repository at this point in the history
zhiyicx/thinksns-plus-android#2390
  • Loading branch information
medz committed Sep 29, 2018
1 parent e873876 commit 02d8ec0
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
54 changes: 54 additions & 0 deletions app/Admin/Controllers/Setting/Security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to version 2.0 of the Apache license, |
* | that is bundled with this package in the file LICENSE, and is |
* | available through the world-wide-web at the following url: |
* | http://www.apache.org/licenses/LICENSE-2.0.html |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <[email protected]> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/

namespace Zhiyi\Plus\Admin\Controllers\Setting;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;

class Security extends Controller
{
/**
* Get pay validate password switch.
* @return \Illuminate\Http\JsonResponse
*/
public function payValidateSwitch(): JsonResponse
{
$switch = (bool) setting('pay', 'validate-password', false);

return new JsonResponse(['switch' => $switch], JsonResponse::HTTP_OK);
}

/**
* Change pay validate password switch.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function changePayValidateSwitch(Request $request): Response
{
$switch = (bool) $request->input('switch', false);
setting('pay')->set('validate-password', $switch);

return new Response('', Response::HTTP_NO_CONTENT);
}
}
2 changes: 1 addition & 1 deletion public/assets/js/admin.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion resources/assets/admin/component/setting/Security.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
<!-- cors setting panel -->
<cors />

<!-- 支付验证密码开关 -->
<pay-switch />

</div>
</template>

<script>
import Cors from '../../components/modules/setting/Cors';
import PaySwitch from '../../components/modules/setting/security-pay-validate-password';
export default {
components:{
'cors': Cors,
Cors,
PaySwitch,
},
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="panel panel-default">
<div class="panel-heading">支付验证密码</div>
<div class="panel-body">
<sb-ui-loading v-if="loading" />
<div class="form-horizontal" v-else>
<div class="form-group">
<label class="col-sm-2 control-label">开关</label>
<div class="col-sm-4">
<sb-ui-button
class="btn btn-primary"
:label="setting ? '关闭' : '开启'"
@click="changeSwitchHandler"
>
</sb-ui-button>
</div>
<div class="col-sm-6 help-block">
默认关闭,如果开启那么用户发生付款行为需要用户输入登录密码进行安全验证,关闭后泽不需要输入密码验证!
</div>
</div>
</div>
</div>
</div>
</template>

<script>
import request, { createRequestURI } from '../../../util/request';
export default {
data: () => ({
loading: false,
setting: false,
}),
created() {
this.loading = true;
request.get(createRequestURI('setting/security/pay-validate-password'), {
validateStatus: status => status === 200,
}).then(({ data }) => {
this.setting = data.switch || false;
this.loading = false;
}).catch(() => {
this.$store.dispatch('alert-open', { type: 'danger', message: '获取配置失败,请联系技术人员!' });
});
},
methods: {
changeSwitchHandler({ stopProcessing }) {
request.put(
createRequestURI('setting/security/pay-validate-password'),
{ switch: !this.setting },
{
validateStatus: status => status === 204
}
).then(() => {
this.setting = ! this.setting;
this.submiting = false;
stopProcessing();
}).catch(() => {
this.$store.dispatch('alert-open', { type: 'danger', message: '更新配置失败,请联系技术人员!' });
stopProcessing();
});
}
}
}
</script>
3 changes: 3 additions & 0 deletions routes/new-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@

$route->get('file-storage/channels/public', AdminControllers\FileStorage\PublicChannel::class.'@show');
$route->patch('file-storage/channels/public', AdminControllers\FileStorage\PublicChannel::class.'@update');

$route->get('setting/security/pay-validate-password', AdminControllers\Setting\Security::class.'@payValidateSwitch');
$route->put('setting/security/pay-validate-password', AdminControllers\Setting\Security::class.'@changePayValidateSwitch');
});

0 comments on commit 02d8ec0

Please sign in to comment.