Advertisement
Guest User

Controller

a guest
Aug 21st, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. use Validator;
  8. use App\User;
  9.  
  10.  
  11. class IndexController extends Controller
  12. {
  13.  
  14. /**
  15. * Display a listing of the resource.
  16. *
  17. * @return \Illuminate\Http\Response
  18. */
  19. public function __construct()
  20. {
  21. $this->middleware('guest');
  22.  
  23. }
  24.  
  25. public function index()
  26. {
  27. return view('index');
  28. }
  29.  
  30.  
  31. public function checklogin(Request $request)
  32. {
  33. $this->validate($request, [
  34. 'email' => 'required|email',
  35. 'password' => 'required',
  36.  
  37.  
  38.  
  39. ]);
  40. $user_data = array(
  41. 'email' => $request->input('email'),
  42. 'password' => $request->input('password'),
  43.  
  44. );
  45.  
  46. // if(Auth::attempt($user_data))
  47. // {
  48.  
  49. // return redirect('dashboard/index')->with('success', 'Successful login, Welcome dear '.Auth::user()->name.'.');
  50. // }
  51. // else
  52. // {
  53.  
  54. // return redirect()->route('index')->with('error', 'Your email or password is incorrect.');
  55. // }
  56.  
  57. $code = $request->input('CaptchaCode');
  58. $isHuman = captcha_validate($code);
  59.  
  60. if ($isHuman) {
  61. if(Auth::attempt($user_data))
  62. {
  63.  
  64. return redirect('dashboard/index')->with('success', 'Successful login, Welcome dear '.Auth::user()->name.'.');
  65. }
  66. else
  67. {
  68.  
  69. return redirect()->route('index')->with('error', 'Your email or password is incorrect.');
  70. }
  71. }
  72.  
  73. else {
  74. return redirect()->route('index')->with('error', 'Invalid Captcha, Please try again.');
  75. }
  76.  
  77.  
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement