Jan 19, 2016
0
Level 5
Multiple Logins
I'm using Laravel 4.2 and I'm trying to create a site that has 2 logins. One is the admin login which I have working and the other is the students login which I'm struggling with.
The issue I'm having is that even though the email and password is correct it still directs to the index page instead of the student dashboard.
I've tried looking it up but I don't see any tutorials on having multiple logins.
My StudentsController.php
<?php
class StudentsController extends \BaseController {
public function create()
{
echo "This is the StudentsController create";
return View::make('students::register');
}
/**
* Store a newly created resource in storage.
* POST /students
*
* @return Response
*/
public function store()
{
$students = new Student();
$input = Input::all();
$validation = Validator::make($input, Student::$rules);
if($validation->fails()){
// return Redirect::route('admin.students.create')
return Redirect::action('StudentsController@create')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors');
}
if($validation->passes()){
$students->name = Input::get('name');
$students->email = Input::get('email');
$students->password = Input::get('password');
$students->save();
$students = Student::all();
return View::make('students::complete', compact('students'));
}
}
public function studentLogin(){
echo "This is the StudentsController studentLogin";
return View::make('students::studentLogin');
}
public function studentDoLogin()
{
//Checks to see if the email and password matches the one in the database.
if(Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'))))
{
//If email and password matches the one in the database then redirect to admin/menus
return Redirect::to('student_area/dashboard')->with('message', 'You are now logged in!');
}else{
//If email and password doesn't match then redirect back to admin/
return Redirect::to('/')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
public function studentDashboard(){
echo "This is the StudentsController studentDashboard";
}
}
My Student.php
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Student extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
//Allows the fields in the array to be fillable
protected $fillable = array('name', 'email', 'password');
//Doesn't allow the id to be changed
protected $guarded = array('id');
protected $table = 'students';
protected $hidden = array('password', 'remember_token');
//Validation rules
public static $rules = array(
'name' => 'required',
'email' => 'required'
);
}
My index.blade.php
@extends('templates::public')
@section('content')
<h1>This is the public view</h1>
{{ HTML::linkAction('StudentsController@create', 'Register', array(), array("class" => "btn btn-info create-frame", "role" => "button")) }}
{{ HTML::linkAction('StudentsController@studentLogin', 'Login', array(), array("class" => "btn btn-info create-frame", "role" => "button")) }}
@stop
My studentLogin.blade.php
{{ Form::open(array('url' => 'student_login/')) }}
<div class="form_group">
{{ Form::label('email', 'Email') }}
{{ Form::text('email', '' , array("class" => "form-control")) }}
</div>
<div class="form_group password-section">
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array("class" => "form-control")) }}
</div>
<div class="form_group submit_button">
{{ Form::submit('Submit', array("class" =>"btn btn-info submit", "role" => "button")) }}
</div>
{{ Form::close() }}
my routes.php
Route::get('/register', 'StudentsController@create');
// Route::resource('/register', 'StudentsController');
Route::post('/register', 'StudentsController@store');
Route::get('/student_login', 'StudentsController@studentLogin');
//Route to process the form
Route::post('/student_login', array('uses' => 'StudentsController@studentDoLogin'));
Route::get('student_area/dashboard', 'StudentsController@studentDashboard');
Please or to participate in this conversation.