M
M
miniven2016-03-23 12:54:51
HTML
miniven, 2016-03-23 12:54:51

Why after authorization does not redirect to the desired page?

Made authorization on laravel.
The controller is like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use Auth;

class UserController extends Controller
{
    public function authget() {
    	$data = [
    		'pagetitle' => 'Авторизация'
    	];

    	return view('pages.auth', $data);
    }

    public function authpost(Request $request) {
    	$rules = array('username' => 'required', 'password' => 'required');

    	$auth = Auth::attempt(array(
    		'username' => $request->only('username')['username'],
    		'password' => $request->only('password')['password']
    	), false);

    	if (!Auth::check()) {
    		return redirect()->route('user.auth.get');
    	}
        
    	return redirect()->route('pages.admin');
    }
}

And routes:
Route::get('/', ['uses' => '[email protected]', 'as' => 'pages.index']);
Route::post('/admin', ['uses' => '[email protected]', 'as' => 'index.store']);
Route::get('/admin', ['uses' => '[email protected]', 'as' => 'pages.admin', 'middleware' => 'auth']);
Route::get('/service_{id}/delete', ['uses' => '[email protected]', 'as' => 'service.delete']);
Route::get('/service/add', ['uses' => '[email protected]', 'as' => 'service.add']);
Route::post('/form/call', ['uses' => '[email protected]', 'as' => 'index.call']);

After a failed authorization, it redirects to the authorization page, and if successful, it should direct to the admin panel, but it redirects to authorization again. Moreover, I checked that the controller distinguishes when authorization is successful and when it is not.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2016-03-23
@zvermafia

Try like this:

if ( ! $auth)
{
    return redirect()->route('user.auth.get');
}

Instead of:
if ( ! Auth::check())
{
    return redirect()->route('user.auth.get');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question