duanchui1955 2016-11-30 05:02
浏览 66
已采纳

Laravel 5.3中的奇怪登录问题

I'm using Laravel 5.3 I'm trying to build a simple login where there are two different backend panel for different user. I've placed a cross check of user and redirect it through middleware. I've made this with making Auth controller in the framework. Now the problem is with the login. I don't know but it is not connecting with the database properly, I mean the user is not getting logged in. But once I do a registration the user gets registered and database is being added. Now if I login through the recent user registered details, it logs in and show the appropriate view. Please help me out:

Following is my route file:

Auth::routes();
Route::get('/memberlogin', function(){
  return view('admin.memberlogin');
});

My Blade file:

@extends('admin.authlayouts')

@section('content')
    <!-- Login content -->
    <div class="col-xs-12 tab-pane fade in active login-content">
        <span class="text-center">Login to your account</span>
        <div class="col-xs-12 login-form">
            <span class="text-center"><img src="images/icon-login.png" alt="login-icon"></span>
            <form role="form" method="POST" action="{{ url('/login') }}">
              {{ csrf_field() }}
                <div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
                    <label class="sr-only" for="username">Username</label>
                    <input type="text" id="username" name="username" value="{{ old('username') }}" placeholder="Username" class="input-field username form-control" required autofocus>
                  @if ($errors->has('username'))
                      <span class="help-block">
                          <strong>{{ $errors->first('username') }}</strong>
                      </span>
                    @endif
                </div>
                <div class="form-group">
                    <label class="sr-only" for="password">Password</label>
                    <input id="password" type="password" name="password" placeholder="Password" class="input-field password form-control">
                  @if ($errors->has('password'))
                      <span class="help-block">
                          <strong>{{ $errors->first('password') }}</strong>
                      </span>
                    @endif
                </div>
                <div class="form-group">
                    <label><input type="checkbox" name="" id="remember-check"> Remember me</label>
                    <input type="submit" value="Sign in" class="btn btn-success pull-right">
                </div>
            </form>                        
            <div class="forget-password">
                <span class="bold">Forgot your password?</span>
                No worries, <a class="bold" href="/memberresetpassword">click here</a> to reset your password
            </div>
            <div class="text-center click-to-register">
                <span>Don't have an Account yet?</span>
                <a class="btn btn-success btn-lg" href="/memberregister">Create an account</a>
            </div>
        </div>
    </div>
@endsection

And my Controller/Auth/LoginController :

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use  \Auth;
class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = 'member/dashbaord';

    /**
     * Create a new controller instance.
     *
     * @return void
     */

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

}

And my Http/Middleware/RidirectIfAuthenticated :

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */

    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
           if (Auth::user()->is_admin == 0)
           {     
             return redirect()->intended('/admin/dashboard');   
           }
           else 
           {
             return redirect('/member/dashboard');      
           }  
         }
        return $next($request);
    }
}
  • 写回答

1条回答 默认 最新

  • dongye4192 2016-11-30 05:05
    关注

    You gotta login the user using:

    \Auth::attempt($credentials)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率