Guest User

Untitled

a guest
May 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <h2>Please Log In To Manage</h2>
  2. <form id="form1" name="form1" method="post" action="<?=URL::to('/admin')?>">
  3. <input type="hidden" name="_token" value="{{ csrf_token() }}">
  4. User Name:<br />
  5. <input name="username" type="text" id="username" size="40" />
  6. <br /><br />
  7. Password:<br />
  8. <input name="password" type="password" id="password" size="40" />
  9. <br />
  10. <br />
  11. <br />
  12. <input type="submit" name="button" id="button" value="Log In" />
  13. </form>
  14.  
  15. Route::get('/admin',array('uses'=>'student@admin'));
  16.  
  17. public function admin()
  18. {
  19. return View::make('student.admin');
  20. $validator = Validator::make($data = Input::all() , User::rules());
  21. if ($validator->fails())
  22. {
  23. return Redirect::back()->withErrors($validator)->withInput();
  24. }
  25. else
  26. {
  27. $check = 0;
  28. $check = DB::table('admin')->get();
  29. $username = Input::get('username');
  30. $password = Input::get('password');
  31. if (Auth::attempt(['username' => $username, 'password' => $password]))
  32. {
  33. return Redirect::intended('/');
  34. }
  35. return Redirect::back()->withInput()->withErrors('That username/password combo does not exist.');
  36. }
  37. }
  38.  
  39. Route::get('/admin', 'UsersController@getAdminLogin');
  40. Route::get('/admin/dashboard', 'UsersController@dashboard');
  41. Route::post('/admin', 'UsersController@postAdminLogin');
  42.  
  43. {!! Form::open(['url' => '/admin']) !!}
  44. <div class="form-group">
  45. {!! Form::label('email', 'Email Id:') !!}
  46. {!! Form::text('email', null, ['class' => 'form-control input-sm']) !!}
  47. </div>
  48. <div class="form-group">
  49. {!! Form::label('password', 'Password') !!}
  50. {!! Form::password('password', ['class' => 'form-control input-sm']) !!}
  51. </div>
  52. <div class="form-group">
  53. {!! Form::submit('Login', ['class' => 'btn btn-primary btn-block']) !!}
  54. </div>
  55. {!! Form::close() !!}
  56.  
  57. <h4 class="text-center">
  58. Welcome {{ Auth::user()->full_name }}
  59. </h4>
  60.  
  61. /**
  62. * Display the admin login form if not logged in,
  63. * else redirect him/her to the admin dashboard.
  64. *
  65. */
  66. public function getAdminLogin()
  67. {
  68. if(Auth::check() && Auth::user()->role === 'admin')
  69. {
  70. return redirect('/admin/dashboard');
  71. }
  72. return view('admin_login');
  73. }
  74.  
  75. /**
  76. * Process the login form submitted, check for the
  77. * admin credentials in the users table. If match found,
  78. * redirect him/her to the admin dashboard, else, display
  79. * the error message.
  80. *
  81. */
  82. public function postAdminLogin(Request $request)
  83. {
  84. $this->validate($request, [
  85. 'email' => 'required|email|exists:users,email,role,admin',
  86. 'password' => 'required'
  87. ]);
  88.  
  89. $credentials = $request->only( 'email', 'password' );
  90.  
  91. if(Auth::attempt($credentials))
  92. {
  93. return redirect('/admin/dashboard');
  94. }
  95. else
  96. {
  97. // Your logic of invalid credentials.
  98. return 'Invalid Credentials';
  99. }
  100. }
  101.  
  102. /**
  103. * Display the dashboard to the admin if logged in, else,
  104. * redirect him/her to the admin login form.
  105. *
  106. */
  107. public function dashboard()
  108. {
  109. if(Auth::check() && Auth::user()->role === 'admin')
  110. {
  111. return view('admin.dashboard');
  112. }
  113. return redirect('/admin');
  114. }
  115.  
  116. Route::get('/admin',array('uses'=>'student@admin'));
  117.  
  118. public function admin(){
  119. // Won't work as you are already returning the view
  120. // before processing the admin form.
  121. return View::make(students.admin);
  122. // ...
  123. }
  124.  
  125. {!! Form::open(array('url' => 'foo/bar')) !!}
  126.  
  127. {!! Form::close() !!}
  128.  
  129. composer require "illuminate/html":"5.0.*"
  130.  
  131. Route::get('/admin',array('uses'=>'student@admin'));
  132.  
  133. Route::post('/admin',array('uses'=>'student@admin'));
  134.  
  135. public function admin(Request $request){
  136. if($request->isMethod('get')){
  137. return View::make('student.admin');
  138. } else {
  139. // your validation logic
  140. }
  141. }
Add Comment
Please, Sign In to add comment