feat: Added ReCaptcha Settings in Class

This commit is contained in:
IceToast 2022-01-15 00:48:38 +01:00
parent a8c19ffe2c
commit cb7a757a3a
5 changed files with 57 additions and 42 deletions

View file

@ -39,8 +39,10 @@ class Misc
"SETTINGS::DISCORD:CLIENT_SECRET" => "discord-client-secret",
"SETTINGS::DISCORD:GUILD_ID" => "discord-guild-id",
"SETTINGS::DISCORD:INVITE_URL" => "discord-invite-url",
"SETTINGS::DISCORD:ROLE_ID" => "discord-role-id"
"SETTINGS::DISCORD:ROLE_ID" => "discord-role-id",
"SETTINGS::RECAPTCHA:SITE_KEY" => "recaptcha-site-key",
"SETTINGS::RECAPTCHA:SECRET_KEY" => "recaptcha-secret-key",
"SETTINGS::RECAPTCHA:ENABLED" => "enable-recaptcha",
];
Config::set('services.discord.client_id', $request->get("discord-client-id"));
@ -49,14 +51,12 @@ class Misc
foreach ($values as $key => $value) {
$param = $request->get($value);
if (!$param) {
$param = "";
}
Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]);
Cache::forget("setting" . ':' . $key);
}
return redirect(route('admin.settings.index') . '#misc')->with('success', 'Misc settings updated!');
return redirect(route('admin.settings.index') . '#misc')->with('success', __('Misc settings updated!'));
}
}

View file

@ -41,17 +41,25 @@ class LoginController extends Controller
public function login(Request $request)
{
$request->validate([
$validationRules = [
$this->username() => 'required|string',
'password' => 'required|string',
'g-recaptcha-response' => ['required','recaptcha'],
]);
];
if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true') {
$validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
}
$request->validate($validationRules);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if (method_exists($this, 'hasTooManyLoginAttempts') &&
$this->hasTooManyLoginAttempts($request)) {
if (
method_exists($this, 'hasTooManyLoginAttempts') &&
$this->hasTooManyLoginAttempts($request)
) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);

View file

@ -53,30 +53,28 @@ class RegisterController extends Controller
*/
protected function validator(array $data)
{
$validationRules = [
'name' => ['required', 'string', 'max:30', 'min:4', 'alpha_num', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:64', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
];
if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true') {
$validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
}
if (Settings::getValueByKey('SETTINGS::SYSTEM:REGISTER_IP_CHECK', 'true') == 'true') {
//check if ip has already made an account
$data['ip'] = session()->get('ip') ?? request()->ip();
if (User::where('ip', '=', request()->ip())->exists()) session()->put('ip', request()->ip());
$validationRules['ip'] = ['unique:users'];
return Validator::make($data, [
'name' => ['required', 'string', 'max:30', 'min:4', 'alpha_num', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:64', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'g-recaptcha-response' => ['recaptcha'],
'ip' => ['unique:users'],
], [
'ip.unique' => "You have already made an account with us! Please contact support if you think this is incorrect."
return Validator::make($data, $validationRules, [
'ip.unique' => "You have already made an account! Please contact support if you think this is incorrect."
]);
}
return Validator::make($data, [
'name' => ['required', 'string', 'max:30', 'min:4', 'alpha_num', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:64', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'g-recaptcha-response' => ['recaptcha'],
]);
return Validator::make($data, $validationRules);
}
/**

View file

@ -1,4 +1,4 @@
<div class="tab-pane mt-3" id="invoices">
<div class="tab-pane mt-3 active" id="invoices">
<form method="POST" enctype="multipart/form-data" class="mb-3"
action="{{ route('admin.settings.update.invoicesettings') }}">
@csrf

View file

@ -1,5 +1,6 @@
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@ -8,7 +9,9 @@
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<link rel="icon" href="{{\Illuminate\Support\Facades\Storage::disk('public')->exists('favicon.ico') ? \Illuminate\Support\Facades\Storage::disk('public')->url('favicon.ico') : asset('favicon.ico')}}" type="image/x-icon">
<link rel="icon"
href="{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('favicon.ico') ? \Illuminate\Support\Facades\Storage::disk('public')->url('favicon.ico') : asset('favicon.ico') }}"
type="image/x-icon">
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
@ -17,27 +20,32 @@
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<link rel="stylesheet" href="{{asset('css/app.css')}}">
<link rel="preload" href="{{asset('plugins/fontawesome-free/css/all.min.css')}}" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="{{asset('plugins/fontawesome-free/css/all.min.css')}}"></noscript>
{!! htmlScriptTagJsApi() !!}
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<link rel="preload" href="{{ asset('plugins/fontawesome-free/css/all.min.css') }}" as="style"
onload="this.onload=null;this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="{{ asset('plugins/fontawesome-free/css/all.min.css') }}">
</noscript>
@if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true')
{!! htmlScriptTagJsApi() !!}
@endif
</head>
@yield('content')
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10.14.1/dist/sweetalert2.all.min.js"></script>
<script>
@if(Session::has('error'))
Swal.fire({
@if (Session::has('error'))
Swal.fire({
icon: 'error',
title: 'Oops...',
html: '{{Session::get('error')}}',
})
html: '{{ Session::get('error') }}',
})
@endif
@if(Session::has('success'))
Swal.fire({
@if (Session::has('success'))
Swal.fire({
icon: 'success',
title: '{{Session::get('success')}}',
title: '{{ Session::get('success') }}',
position: 'top-end',
showConfirmButton: false,
background : '#343a40',
@ -45,10 +53,11 @@
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})
})
@endif
</script>
</html>