diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index f45deadd..c906dfab 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -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); diff --git a/resources/assets/src/js/__tests__/auth.test.js b/resources/assets/src/js/__tests__/auth.test.js index e5c23cf8..731776ea 100644 --- a/resources/assets/src/js/__tests__/auth.test.js +++ b/resources/assets/src/js/__tests__/auth.test.js @@ -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', () => {
- `; @@ -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(); diff --git a/resources/assets/src/js/auth/register.js b/resources/assets/src/js/auth/register.js index 3fd1e442..70c028c1 100644 --- a/resources/assets/src/js/auth/register.js +++ b/resources/assets/src/js/auth/register.js @@ -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(); diff --git a/resources/lang/en/auth.yml b/resources/lang/en/auth.yml index fb249819..9197804b 100644 --- a/resources/lang/en/auth.yml +++ b/resources/lang/en/auth.yml @@ -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 diff --git a/resources/lang/zh_CN/auth.yml b/resources/lang/zh_CN/auth.yml index cf70d1c4..edd61186 100644 --- a/resources/lang/zh_CN/auth.yml +++ b/resources/lang/zh_CN/auth.yml @@ -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: 忘记密码 diff --git a/resources/views/auth/register.tpl b/resources/views/auth/register.tpl index ce0773ce..bb46cba3 100644 --- a/resources/views/auth/register.tpl +++ b/resources/views/auth/register.tpl @@ -31,12 +31,6 @@ -