mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-07 04:59:36 +00:00
Fixed #243
This commit is contained in:
@@ -94,7 +94,7 @@ class IP
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function IPIP(string $ip): array // 通过IPIP查询IP地址的详细信息
|
||||
public static function IPIP(string $ip): array // 通过IPIP离线数据查询IP地址的详细信息
|
||||
{
|
||||
$filePath = database_path('ipipfree.ipdb'); // 来源: https://www.ipip.net/free_download/
|
||||
$location = (new City($filePath))->findMap($ip, 'CN');
|
||||
|
||||
@@ -238,10 +238,7 @@ class AuthController extends Controller
|
||||
$transfer_enable = MB * ((int) sysConfig('default_traffic') + ($inviter_id ? (int) sysConfig('referral_traffic') : 0));
|
||||
|
||||
// 创建新用户
|
||||
$user = Helpers::addUser($data['username'], $data['password'], $transfer_enable, sysConfig('default_days'), $inviter_id, $data['nickname']);
|
||||
|
||||
// 注册失败,抛出异常
|
||||
if (! $user) {
|
||||
if (! $user = Helpers::addUser($data['username'], $data['password'], $transfer_enable, sysConfig('default_days'), $inviter_id, $data['nickname'])) { // 注册失败,抛出异常
|
||||
return Redirect::back()->withInput()->withErrors(trans('auth.register.failed'));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,21 +13,6 @@ use Str;
|
||||
|
||||
class OAuthController extends Controller
|
||||
{
|
||||
public function route(Request $request, string $type)
|
||||
{
|
||||
$action = $request->input('action');
|
||||
$key = "services.{$type}.redirect";
|
||||
if ($action === 'binding') {
|
||||
config([$key => route('oauth.bind', ['type' => $type])]);
|
||||
} elseif ($action === 'register') {
|
||||
config([$key => route('oauth.register', ['type' => $type])]);
|
||||
} else {
|
||||
config([$key => route('oauth.login', ['type' => $type])]);
|
||||
}
|
||||
|
||||
return Socialite::driver($type)->redirect();
|
||||
}
|
||||
|
||||
public function simple(string $type)
|
||||
{
|
||||
$info = Socialite::driver($type)->stateless()->user();
|
||||
@@ -59,6 +44,21 @@ class OAuthController extends Controller
|
||||
return redirect()->route('profile')->with('successMsg', trans('auth.oauth.bind_success'));
|
||||
}
|
||||
|
||||
public function route(Request $request, string $type)
|
||||
{
|
||||
$action = $request->input('action');
|
||||
$key = "services.{$type}.redirect";
|
||||
if ($action === 'binding') {
|
||||
config([$key => route('oauth.bind', ['type' => $type])]);
|
||||
} elseif ($action === 'register') {
|
||||
config([$key => route('oauth.register', ['type' => $type])]);
|
||||
} else {
|
||||
config([$key => route('oauth.login', ['type' => $type])]);
|
||||
}
|
||||
|
||||
return Socialite::driver($type)->redirect();
|
||||
}
|
||||
|
||||
private function login(string $type, $info)
|
||||
{
|
||||
$user = User::whereUsername($info->getEmail())->first();
|
||||
@@ -119,6 +119,14 @@ class OAuthController extends Controller
|
||||
|
||||
public function register($type)
|
||||
{
|
||||
if (! sysConfig('is_register')) {
|
||||
return redirect()->route('register')->withErrors(trans('auth.register.error.disable'));
|
||||
}
|
||||
|
||||
if ((int) sysConfig('is_invite_register') === 2) { // 必须使用邀请码
|
||||
return redirect()->route('register')->withErrors(trans('validation.required', ['attribute' => trans('auth.invite.attribute')]));
|
||||
}
|
||||
|
||||
config(["services.{$type}.redirect" => route('oauth.register', ['type' => $type])]);
|
||||
$info = Socialite::driver($type)->stateless()->user();
|
||||
|
||||
|
||||
@@ -65,7 +65,9 @@
|
||||
<input type="text" class="form-control" name="code" value="{{old('code') ?: Request::query('code')}}"
|
||||
@if(sysConfig('is_invite_register') == 2) required @endif/>
|
||||
<label class="floating-label" for="code">
|
||||
{{trans('auth.invite.attribute')}}@if(sysConfig('is_invite_register') == 1)({{trans('auth.optional')}}) @endif
|
||||
{{trans('auth.invite.attribute')}}@if(sysConfig('is_invite_register') == 1)
|
||||
({{trans('auth.optional')}})
|
||||
@endif
|
||||
</label>
|
||||
</div>
|
||||
@if(sysConfig('is_free_code'))
|
||||
@@ -99,7 +101,7 @@
|
||||
<button type="submit" class="btn btn-primary btn-lg float-right">{{trans('auth.register.attribute')}}</button>
|
||||
@endif
|
||||
</form>
|
||||
@if(sysConfig('is_register') && sysConfig('oauth_path'))
|
||||
@if(sysConfig('is_register') && sysConfig('oauth_path') && sysConfig('is_invite_register') != 2)
|
||||
<div class="pt-20" style="display: inline-block;">
|
||||
<div class="line">
|
||||
<span> {{trans('auth.oauth.register')}} </span>
|
||||
@@ -164,67 +166,67 @@
|
||||
<script>
|
||||
@if($emailList)
|
||||
function getEmail() {
|
||||
let email = $('#emailHead').val().trim();
|
||||
const emailTail = $('#emailTail').val();
|
||||
if (email === '') {
|
||||
swal.fire({title: '{{trans('validation.required', ['attribute' => trans('validation.attributes.email')])}}', icon: 'warning', timer: 1500});
|
||||
return false;
|
||||
}
|
||||
email += '@' + emailTail;
|
||||
$('#username').val(email);
|
||||
return email;
|
||||
let email = $('#emailHead').val().trim();
|
||||
const emailTail = $('#emailTail').val();
|
||||
if (email === '') {
|
||||
swal.fire({title: '{{trans('validation.required', ['attribute' => trans('validation.attributes.email')])}}', icon: 'warning', timer: 1500});
|
||||
return false;
|
||||
}
|
||||
email += '@' + emailTail;
|
||||
$('#username').val(email);
|
||||
return email;
|
||||
}
|
||||
@endif
|
||||
|
||||
// 发送注册验证码
|
||||
function sendVerifyCode() {
|
||||
let flag = true; // 请求成功与否标记
|
||||
let email = $('#username').val().trim();
|
||||
let flag = true; // 请求成功与否标记
|
||||
let email = $('#username').val().trim();
|
||||
@if($emailList)
|
||||
email = getEmail();
|
||||
@endif
|
||||
|
||||
if (email === '') {
|
||||
swal.fire({title: '{{trans('validation.required', ['attribute' => trans('validation.attributes.email')])}}', icon: 'warning', timer: 1500});
|
||||
return false;
|
||||
swal.fire({title: '{{trans('validation.required', ['attribute' => trans('validation.attributes.email')])}}', icon: 'warning', timer: 1500});
|
||||
return false;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '{{route('sendVerificationCode')}}',
|
||||
dataType: 'json',
|
||||
data: {_token: '{{csrf_token()}}', username: email},
|
||||
success: function(ret) {
|
||||
if (ret.status === 'success') {
|
||||
swal.fire({title: ret.message, icon: 'success'});
|
||||
$('#sendCode').attr('disabled', true);
|
||||
flag = true;
|
||||
} else {
|
||||
swal.fire({title: ret.message, icon: 'error', timer: 1000, showConfirmButton: false});
|
||||
$('#sendCode').attr('disabled', false);
|
||||
flag = false;
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
swal.fire({title: '发送失败', icon: 'error'});
|
||||
flag = false;
|
||||
},
|
||||
});
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '{{route('sendVerificationCode')}}',
|
||||
dataType: 'json',
|
||||
data: {_token: '{{csrf_token()}}', username: email},
|
||||
success: function(ret) {
|
||||
if (ret.status === 'success') {
|
||||
swal.fire({title: ret.message, icon: 'success'});
|
||||
$('#sendCode').attr('disabled', true);
|
||||
flag = true;
|
||||
} else {
|
||||
swal.fire({title: ret.message, icon: 'error', timer: 1000, showConfirmButton: false});
|
||||
$('#sendCode').attr('disabled', false);
|
||||
flag = false;
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
swal.fire({title: '发送失败', icon: 'error'});
|
||||
flag = false;
|
||||
},
|
||||
});
|
||||
|
||||
// 请求成功才开始倒计时
|
||||
if (flag) {
|
||||
// 60秒后才能重新申请发送
|
||||
let left_time = 60;
|
||||
const tt = window.setInterval(function() {
|
||||
left_time--;
|
||||
if (left_time <= 0) {
|
||||
window.clearInterval(tt);
|
||||
$('#sendCode').removeAttr('disabled').text('{{trans('auth.request')}}');
|
||||
} else {
|
||||
$('#sendCode').text(left_time + ' s');
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
// 请求成功才开始倒计时
|
||||
if (flag) {
|
||||
// 60秒后才能重新申请发送
|
||||
let left_time = 60;
|
||||
const tt = window.setInterval(function() {
|
||||
left_time--;
|
||||
if (left_time <= 0) {
|
||||
window.clearInterval(tt);
|
||||
$('#sendCode').removeAttr('disabled').text('{{trans('auth.request')}}');
|
||||
} else {
|
||||
$('#sendCode').text(left_time + ' s');
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
$('#register-form').submit(function(event) {
|
||||
@@ -234,18 +236,18 @@
|
||||
|
||||
@switch(sysConfig('is_captcha'))
|
||||
@case(3)
|
||||
// 先检查Google reCAPTCHA有没有进行验证
|
||||
if ($('#g-recaptcha-response').val() === '') {
|
||||
swal.fire({title: '{{trans('auth.captcha.required')}}', icon: 'error'});
|
||||
return false;
|
||||
}
|
||||
// 先检查Google reCAPTCHA有没有进行验证
|
||||
if ($('#g-recaptcha-response').val() === '') {
|
||||
swal.fire({title: '{{trans('auth.captcha.required')}}', icon: 'error'});
|
||||
return false;
|
||||
}
|
||||
@break
|
||||
@case(4)
|
||||
// 先检查Google reCAPTCHA有没有进行验证
|
||||
if ($('#h-captcha-response').val() === '') {
|
||||
swal.fire({title: '{{trans('auth.captcha.required')}}', icon: 'error'});
|
||||
return false;
|
||||
}
|
||||
// 先检查Google reCAPTCHA有没有进行验证
|
||||
if ($('#h-captcha-response').val() === '') {
|
||||
swal.fire({title: '{{trans('auth.captcha.required')}}', icon: 'error'});
|
||||
return false;
|
||||
}
|
||||
@break
|
||||
@default
|
||||
@endswitch
|
||||
|
||||
Reference in New Issue
Block a user