Revert "Add a option for adding a player after registered"

This feature will be implemented as a plugin. This reverts commit ad255252b57b135ddecf89aa1331c40c97324be9.
This commit is contained in:
printempw 2018-06-15 22:41:49 +08:00
parent a2ad367651
commit 36064873e3
7 changed files with 9 additions and 123 deletions

View File

@ -9,10 +9,8 @@ use Utils;
use Cookie;
use Option;
use Session;
use Validator;
use App\Events;
use App\Models\User;
use App\Models\Player;
use Illuminate\Http\Request;
use App\Exceptions\PrettyPageException;
use App\Services\Repositories\UserRepository;
@ -143,38 +141,10 @@ class AuthController extends Controller
event(new Events\UserRegistered($user));
$msg = trans('auth.register.success');
$redirect = true;
if ($request->input('addPlayer') == 'add') {
if (! Player::where('player_name', $request->nickname)->first()) {
if (! Validator::make(
['name' => $request->nickname],
['name' => option('allow_chinese_playername') ? 'pname_chinese' : 'playername']
)->fails()) {
$player = new Player;
$player->uid = $user->uid;
$player->player_name = $request->input('nickname');
$player->preference = "default";
$player->last_modified = Utils::getTimeFormatted();
$player->save();
event(new Events\PlayerWasAdded($player));
} else {
$msg = trans('auth.register.success-with-chinese-player-name');
$redirect = false;
}
} else {
$msg = trans('auth.register.success-without-player');
$redirect = false;
}
}
return json([
'errno' => 0,
'msg' => $msg,
'msg' => trans('auth.register.success'),
'token' => $user->getToken(),
'redirect' => $redirect,
]) // Set cookies
->withCookie('uid', $user->uid, 60)
->withCookie('token', $user->getToken(), 60);

View File

@ -3,8 +3,6 @@
const $ = require('jquery');
window.$ = window.jQuery = $;
jest.useFakeTimers();
window.blessing = {
base_url: '/'
};
@ -124,11 +122,7 @@ describe('tests for "register" module', () => {
const fetch = jest.fn()
.mockImplementationOnce(option => {
option.beforeSend();
return Promise.resolve({ errno: 0, msg: 'success', redirect: false });
})
.mockImplementationOnce(option => {
option.beforeSend();
return Promise.resolve({ errno: 0, msg: 'success', redirect: true });
return Promise.resolve({ errno: 0, msg: 'success' });
})
.mockImplementationOnce(() => Promise.resolve(
{ errno: 1, msg: 'warning' }
@ -155,7 +149,6 @@ describe('tests for "register" module', () => {
<input id="confirm-pwd" />
<div id="captcha-form"></div>
<input id="captcha" />
<input id="add-player" type="checkbox" checked />
<button id="register-button"></button>
`;
@ -220,8 +213,7 @@ describe('tests for "register" module', () => {
email: 'a@b.c',
nickname: 'nickname',
password: 'password',
captcha: 'captcha',
addPlayer: 'add'
captcha: 'captcha'
}
}));
expect($('button').html()).toBe(
@ -229,13 +221,6 @@ describe('tests for "register" module', () => {
);
expect($('button').prop('disabled')).toBe(true);
expect(swal).toBeCalledWith({ type: 'success', html: 'success' });
url.mockClear();
expect(url).not.toBeCalled();
await $('button').click();
url.mockClear();
jest.runAllTimers();
expect(url).toBeCalledWith('user');
await $('button').click();
expect(refreshCaptcha).toBeCalled();

View File

@ -10,7 +10,6 @@ $('#register-button').click(e => {
password: $('#password').val(),
nickname: $('#nickname').val(),
captcha: $('#captcha').val(),
addPlayer: $('#add-player').prop('checked') ? 'add' : '',
};
(function validate({ email, password, nickname, captcha }, callback) {
@ -45,7 +44,7 @@ $('#register-button').click(e => {
return;
})(data, async () => {
try {
const { errno, msg, redirect } = await fetch({
const { errno, msg } = await fetch({
type: 'POST',
url: url('auth/register'),
dataType: 'json',
@ -57,14 +56,11 @@ $('#register-button').click(e => {
}
});
if (errno === 0) {
swal({ type: 'success', html: msg })
.then(() => window.location = url('user'));
swal({ type: 'success', html: msg });
if (redirect) {
setTimeout(() => {
window.location = url('user');
}, 1000);
}
setTimeout(() => {
window.location = url('user');
}, 1000);
} else {
showMsg(msg, 'warning');
refreshCaptcha();

View File

@ -19,11 +19,8 @@ register:
repeat-pwd: Repeat your password
close: Well, this site doesn't allow any register.
success: Registered successfully. Redirecting...
success-without-player: Your account is successfully registered. But you may need to add a player manually since there was already someone occupied the player name.
success-with-chinese-player-name: Your account is successfully registered. But you may need to add a player manually because the nickname contains Chinese characters.
max: You can't register more than :regs accounts.
registered: The email address is already registered.
auto-add-player: Add an player with the associated name
forgot:
title: Forgot Password

View File

@ -19,11 +19,8 @@ register:
repeat-pwd: 重复密码
close: 残念。。本皮肤站已经关闭注册咯 QAQ
success: 注册成功,正在跳转~
success-without-player: 注册成功。但您需要手动添加角色因为角色名重复。
success-with-chinese-player-name: 注册成功。但您需要手动添加角色因为角色名中包含中文字符。
max: 你最多只能注册 :regs 个账户哦
registered: 这个邮箱已经注册过啦,换一个吧
auto-add-player: 注册成功后自动新建同名角色
forgot:
title: 忘记密码

View File

@ -31,12 +31,6 @@
<span class="glyphicon glyphicon-pencil form-control-feedback"></span>
</div>
<div class="checkbox icheck" style="margin-top: 0;">
<label for="keep">
<input id="add-player" type="checkbox"> {{ trans('auth.register.auto-add-player') }}
</label>
</div>
<div class="row">
<div class="col-xs-8">
<div class="form-group has-feedback">

View File

@ -378,8 +378,7 @@ class AuthControllerTest extends TestCase
$response->seeJson([
'errno' => 0,
'msg' => trans('auth.register.success'),
'token' => $newUser->getToken(),
'redirect' => true
'token' => $newUser->getToken()
])->seeCookie('uid', $newUser->uid)
->seeCookie('token', $newUser->getToken());
$this->assertTrue($newUser->verifyPassword('12345678'));
@ -390,58 +389,6 @@ class AuthControllerTest extends TestCase
'ip' => '127.0.0.1',
'permission' => User::NORMAL
]);
$this->assertNull(\App\Models\Player::where('player_name', 'nickname')->first());
// Add a player automatically after success
$this->post(
'/auth/register',
[
'email' => 'aa@b.c',
'password' => '12345678',
'nickname' => 'new_player',
'captcha' => 'a',
'addPlayer' => 'add'
]
)->seeJson([
'errno' => 0,
'msg' => trans('auth.register.success'),
'redirect' => true
]);
$this->expectsEvents(Events\PlayerWasAdded::class);
$this->assertNotNull(\App\Models\Player::where('player_name', 'new_player')->first());
// Register with a duplicated player name
$this->post(
'/auth/register',
[
'email' => 'aaa@b.c',
'password' => '12345678',
'nickname' => 'new_player',
'captcha' => 'a',
'addPlayer' => 'add'
]
)->seeJson([
'errno' => 0,
'msg' => trans('auth.register.success-without-player'),
'redirect' => false
]);
// Should be warned if player name contains Chinese characters
option(['allow_chinese_playername' => false]);
$this->post(
'/auth/register',
[
'email' => 'b@b.c',
'password' => '12345678',
'nickname' => '角色player',
'captcha' => 'a',
'addPlayer' => 'add'
]
)->seeJson([
'errno' => 0,
'msg' => trans('auth.register.success-with-chinese-player-name'),
'redirect' => false
]);
}
public function testForgot()