Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h2>Please Log In To Manage</h2>
- <form id="form1" name="form1" method="post" action="<?=URL::to('/admin')?>">
- <input type="hidden" name="_token" value="{{ csrf_token() }}">
- User Name:<br />
- <input name="username" type="text" id="username" size="40" />
- <br /><br />
- Password:<br />
- <input name="password" type="password" id="password" size="40" />
- <br />
- <br />
- <br />
- <input type="submit" name="button" id="button" value="Log In" />
- </form>
- Route::get('/admin',array('uses'=>'student@admin'));
- public function admin()
- {
- return View::make('student.admin');
- $validator = Validator::make($data = Input::all() , User::rules());
- if ($validator->fails())
- {
- return Redirect::back()->withErrors($validator)->withInput();
- }
- else
- {
- $check = 0;
- $check = DB::table('admin')->get();
- $username = Input::get('username');
- $password = Input::get('password');
- if (Auth::attempt(['username' => $username, 'password' => $password]))
- {
- return Redirect::intended('/');
- }
- return Redirect::back()->withInput()->withErrors('That username/password combo does not exist.');
- }
- }
- Route::get('/admin', 'UsersController@getAdminLogin');
- Route::get('/admin/dashboard', 'UsersController@dashboard');
- Route::post('/admin', 'UsersController@postAdminLogin');
- {!! Form::open(['url' => '/admin']) !!}
- <div class="form-group">
- {!! Form::label('email', 'Email Id:') !!}
- {!! Form::text('email', null, ['class' => 'form-control input-sm']) !!}
- </div>
- <div class="form-group">
- {!! Form::label('password', 'Password') !!}
- {!! Form::password('password', ['class' => 'form-control input-sm']) !!}
- </div>
- <div class="form-group">
- {!! Form::submit('Login', ['class' => 'btn btn-primary btn-block']) !!}
- </div>
- {!! Form::close() !!}
- <h4 class="text-center">
- Welcome {{ Auth::user()->full_name }}
- </h4>
- /**
- * Display the admin login form if not logged in,
- * else redirect him/her to the admin dashboard.
- *
- */
- public function getAdminLogin()
- {
- if(Auth::check() && Auth::user()->role === 'admin')
- {
- return redirect('/admin/dashboard');
- }
- return view('admin_login');
- }
- /**
- * Process the login form submitted, check for the
- * admin credentials in the users table. If match found,
- * redirect him/her to the admin dashboard, else, display
- * the error message.
- *
- */
- public function postAdminLogin(Request $request)
- {
- $this->validate($request, [
- 'email' => 'required|email|exists:users,email,role,admin',
- 'password' => 'required'
- ]);
- $credentials = $request->only( 'email', 'password' );
- if(Auth::attempt($credentials))
- {
- return redirect('/admin/dashboard');
- }
- else
- {
- // Your logic of invalid credentials.
- return 'Invalid Credentials';
- }
- }
- /**
- * Display the dashboard to the admin if logged in, else,
- * redirect him/her to the admin login form.
- *
- */
- public function dashboard()
- {
- if(Auth::check() && Auth::user()->role === 'admin')
- {
- return view('admin.dashboard');
- }
- return redirect('/admin');
- }
- Route::get('/admin',array('uses'=>'student@admin'));
- public function admin(){
- // Won't work as you are already returning the view
- // before processing the admin form.
- return View::make(students.admin);
- // ...
- }
- {!! Form::open(array('url' => 'foo/bar')) !!}
- {!! Form::close() !!}
- composer require "illuminate/html":"5.0.*"
- Route::get('/admin',array('uses'=>'student@admin'));
- Route::post('/admin',array('uses'=>'student@admin'));
- public function admin(Request $request){
- if($request->isMethod('get')){
- return View::make('student.admin');
- } else {
- // your validation logic
- }
- }
Add Comment
Please, Sign In to add comment