mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-02 11:18:56 +00:00
Add support for 2 Factor Authentification (2FA)
This commit is contained in:
@@ -159,12 +159,12 @@ class RegisterController extends Controller
|
||||
$confirmPassword = $request->input('password_confirmation');
|
||||
$email = $request->input('email');
|
||||
|
||||
// Get the default user role.
|
||||
$userDefault = Role::query()->where('isdefault', '=', 1)->first();
|
||||
// Get the default user role.
|
||||
$userDefault = Role::query()->where('isdefault', '=', 1)->first();
|
||||
|
||||
if (! empty($error)) {
|
||||
return $this->showRegistrationForm($request, $error);
|
||||
}
|
||||
if (! empty($error)) {
|
||||
return $this->showRegistrationForm($request, $error);
|
||||
}
|
||||
|
||||
if (Invite::isAllowed($inviteCode, $email) || Settings::settingValue('..registerstatus') !== Settings::REGISTER_STATUS_INVITE) {
|
||||
$user = $this->create(
|
||||
|
||||
@@ -84,18 +84,18 @@ class ResetPasswordController extends Controller
|
||||
$content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl');
|
||||
|
||||
app('smarty.view')->assign(
|
||||
[
|
||||
'content' => $content,
|
||||
'title' => $title,
|
||||
'meta_title' => $meta_title,
|
||||
'meta_keywords' => $meta_keywords,
|
||||
'meta_description' => $meta_description,
|
||||
'email' => $ret['email'] ?? '',
|
||||
'confirmed' => $confirmed,
|
||||
'error' => $error,
|
||||
'notice' => $onscreen,
|
||||
]
|
||||
);
|
||||
[
|
||||
'content' => $content,
|
||||
'title' => $title,
|
||||
'meta_title' => $meta_title,
|
||||
'meta_keywords' => $meta_keywords,
|
||||
'meta_description' => $meta_description,
|
||||
'email' => $ret['email'] ?? '',
|
||||
'confirmed' => $confirmed,
|
||||
'error' => $error,
|
||||
'notice' => $onscreen,
|
||||
]
|
||||
);
|
||||
app('smarty.view')->display($theme.'/basepage.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class BasePageController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['auth', 'web'])->except('api', 'contact', 'showContactForm', 'callback', 'getNzb', 'terms', 'capabilities', 'movie', 'apiSearch', 'tv', 'details', 'failed', 'showRssDesc', 'fullFeedRss', 'categoryFeedRss', 'cartRss', 'myMoviesRss', 'myShowsRss');
|
||||
$this->middleware(['auth', 'web', '2fa'])->except('api', 'contact', 'showContactForm', 'callback', 'getNzb', 'terms', 'capabilities', 'movie', 'apiSearch', 'tv', 'details', 'failed', 'showRssDesc', 'fullFeedRss', 'categoryFeedRss', 'cartRss', 'myMoviesRss', 'myShowsRss');
|
||||
// Buffer settings/DB connection.
|
||||
$this->settings = new Settings();
|
||||
$this->smarty = app('smarty.view');
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PasswordSecurity;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class PasswordSecurityController extends Controller
|
||||
{
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show2faForm(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$google2fa_url = '';
|
||||
if ($user->passwordSecurity()->exists()) {
|
||||
$google2fa_url = \Google2FA::getQRCodeInline(
|
||||
config('app.name'),
|
||||
$user->email,
|
||||
$user->passwordSecurity->google2fa_secret
|
||||
);
|
||||
}
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'google2fa_url' => $google2fa_url,
|
||||
];
|
||||
|
||||
return view('auth.2fa')->with('data', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
|
||||
*/
|
||||
public function generate2faSecret(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
// Add the secret key to the registration data
|
||||
PasswordSecurity::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'google2fa_enable' => 0,
|
||||
'google2fa_secret' => \Google2FA::generateSecretKey(),
|
||||
]
|
||||
);
|
||||
|
||||
return redirect('2fa')->with('success', 'Secret Key is generated, Please verify Code to Enable 2FA');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
|
||||
*/
|
||||
public function enable2fa(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$secret = $request->input('verify-code');
|
||||
$valid = \Google2FA::verifyKey($user->passwordSecurity->google2fa_secret, $secret);
|
||||
if ($valid) {
|
||||
$user->passwordSecurity->google2fa_enable = 1;
|
||||
$user->passwordSecurity->save();
|
||||
|
||||
return redirect('2fa')->with('success', '2FA is Enabled Successfully.');
|
||||
}
|
||||
|
||||
return redirect('2fa')->with('error', 'Invalid Verification Code, Please try again.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function disable2fa(Request $request)
|
||||
{
|
||||
if (! (Hash::check($request->get('current-password'), Auth::user()->password))) {
|
||||
// The passwords matches
|
||||
return redirect()->back()->with('error', 'Your password does not match with your account password. Please try again.');
|
||||
}
|
||||
|
||||
$validatedData = $request->validate([
|
||||
'current-password' => 'required',
|
||||
]);
|
||||
$user = Auth::user();
|
||||
$user->passwordSecurity->google2fa_enable = 0;
|
||||
$user->passwordSecurity->save();
|
||||
|
||||
return redirect('2fa')->with('success', '2FA is now Disabled.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user