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 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题
  • ¥15 有没有代做有偿主要做数据可视化部分即可(2023全国高考更省一本线理科类)
  • ¥15 配置FPT报错,该如何处理
  • ¥15 请大家看一下这个代码咋写,一点思路都没有,最好能做一下,不要伪代码,有偿
  • ¥15 有偿请人帮写个安卓系统下禁止装软件及禁止拷入文件的程序
  • ¥100 用 H.265 对音视频硬编码 (CUDA)