Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Copyright © 2017
- * "App" - Brought to you by:
- * ___________ ________ __
- * \__ ___/___ _____ _____ \_____ \ __ _______ _____/ |_ __ __ _____
- * | |_/ __ \\__ \ / \ / / \ \| | \__ \ / \ __\ | \/ \
- * | |\ ___/ / __ \| Y Y \/ \_/. \ | // __ \| | \ | | | / Y Y \
- * |____| \___ >____ /__|_| /\_____\ \_/____/(____ /___| /__| |____/|__|_| /
- * \/ \/ \/ \__> \/ \/ \/
- * https://github.com/Team-Quantum
- * .PolluX / https://github.com/RealPolluX
- * Created @ 2017-06-30 - 21:02 PM
- */
- // https://laracasts.com/discuss/channels/laravel/replacing-the-laravel-authentication-with-a-custom-authentication
- // https://jamesmcfadden.co.uk/custom-authentication-in-laravel-with-guards-and-user-service-providers
- // http://imrealashu.in/code/laravel/multi-auth-with-laravel-5-2-2/
- // https://github.com/jayminpanchal/laravel-multiauth
- namespace App\Http\Controllers\Auth;
- use App\Admin;
- use App\Database;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use App\Http\Controllers\Controller;
- use Validator;
- use Illuminate\Foundation\Auth\AuthenticatesUsers;
- class ElevationController extends Controller
- {
- /*
- |--------------------------------------------------------------------------
- | Elevation Controller
- |--------------------------------------------------------------------------
- |
- | This controller handles the administration pages access via a
- | second authentication (named 'elevation').
- |
- */
- use AuthenticatesUsers;
- protected $loginView = 'auth.admin.login';
- /**
- * Where to redirect users after login.
- *
- * @var string
- */
- protected $redirectTo = '/admin/dashboard';
- private $db;
- // ####################################################################################################
- public function showLoginForm()
- {
- return view('auth.admin.login');
- }
- /**
- * Get a validator for an incoming registration request.
- *
- * @param Request $request
- */
- protected function validateLogin(Request $request)
- {
- $this->validate($request, [
- $this->username() => 'required|string|min:3',
- 'mToken' => 'required|string|min:8',
- 'g-recaptcha-response' => 'required|captcha'
- ]);
- }
- public function username()
- {
- return 'mAccount';
- }
- protected function guard()
- {
- return Auth::guard('admin');
- }
- /**
- * Get the needed authorization credentials from the request.
- *
- * @param \Illuminate\Http\Request $request
- * @return array
- */
- protected function credentials(Request $request)
- {
- return $request->only($this->username(), 'token');
- }
- // ####################################################################################################
- public function __construct()
- {
- //$this->middleware('admin')->except('demote');
- $this->db = new Database(config('database.connections.common.host'),
- config('database.connections.common.username'), config('database.connections.common.password'),
- config('database.connections.common.database'), config('database.connections.common.port'),
- config('database.connections.common.charset'));
- }
- public function elevate(Request $request)
- {
- // login
- $data['name'] = Auth::guard('web')->user()->login;
- $data['token'] = $request->input('token');
- $data['g-recaptcha-response'] = $request->input('g-recaptcha-response');
- if($this->validateLogin($request))
- {
- $result = $this->db
- ->objectBuilder()
- ->where('mToken', $data['token'])
- ->get('common.gmlist');
- if(count($result) > 0)
- {
- if(Auth::attempt([
- 'mName' => $data['name'],
- 'mToken' => $data['token']
- ]))
- {
- redirect('/admin/dashboard');
- }
- }
- else{
- $storage = 'used data was: token->"'.$data['token'].'" and name->"'.$data['name'].'".';
- throw new \ErrorException('Elevation failed! :: '.$storage);
- }
- }
- }
- /*public function elevate(Request $request){
- $this->login($request);
- }*/
- public function demote(Request $request)
- {
- // logout
- $this->guard()->logout();
- $request->session()->flush();
- $request->session()->regenerate();
- return redirect('/admin/login');
- }
- public static function getAuthorityLevel($mAuthority = 'USER')
- {
- $level = config('game.authority.'.$mAuthority);
- if(!empty($level)){
- return $level;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement