Guest User

Untitled

a guest
Oct 27th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. public function login(Request $request)
  2. {
  3.  
  4. $rules = array(
  5. 'email' => 'required',
  6. 'password' => 'required',
  7.  
  8. );
  9. $messages = array();
  10. $validator = Validator::make($request->all(), $rules, $messages);
  11.  
  12. if ($validator->fails()) {
  13. return [
  14. 'status' => 204,
  15. 'message' => $validator->errors()->first()
  16. ];
  17. }
  18.  
  19. $user = User::where('email', $request->email)->first();
  20. if (!$user) {
  21. return response(['status' => 204, 'message' => 'User Not Found']);
  22. }
  23.  
  24. if (Hash::check($request->password, $user->password)) {
  25. $http = new Client;
  26. $response = $http->post(url('oauth/token'), [
  27. 'form_params' => [
  28. 'grant_type' => 'password',
  29. 'client_id' => '2',
  30. 'client_secret' => 'oWXBChJA8TUItWnvZ3J52KNhGMqsPkEqpDyhjnNf',
  31. 'username' => $request->email,
  32. 'password' => $request->password,
  33. 'scope' => '',
  34. ],
  35. ]);
  36. $getVerifyStatus = AppStatus::where('id', $user->profile_verify_status_id)->value('name');
  37.  
  38.  
  39. if ($getVerifyStatus == 'verified') {
  40. return response(['status' => 200, 'message' => 'Sign In Successfully','auth' => json_decode((string)$response->getBody(), true), 'user' => $user]);
  41.  
  42. }
  43. else {
  44. return response(['message' => 'Profile Not Verified', 'status' => 204]);
  45. }
  46. }
  47. else {
  48. return response(['message' => 'Password Not Match', 'status' => 204]);
  49. }
  50.  
  51. }
  52.  
  53. public function loginShipper()
  54. {
  55. return view('login');
  56. }
  57.  
  58. public function login()
  59. {
  60.  
  61. $validator = Validator::make(
  62. array(
  63. 'email' => $_POST['email'],
  64. 'password' => $_POST['password']
  65. ),
  66.  
  67. array(
  68. 'email' => 'required',
  69. 'password' => 'required'
  70. )
  71. );
  72.  
  73. if ($validator->fails()) {
  74. $messages = $validator->messages();
  75. return redirect('/')->with('message', $messages);
  76. }
  77. else
  78. {
  79. // $u_password = (Hash::check();
  80.  
  81. $url = 'http://localhost:81/mvp/api/shipper/login';
  82. $myvars = 'email=' . $_POST['email'] . '&password=' . $_POST['password'] . '&created_at=' . '';
  83.  
  84.  
  85. $ch = curl_init($url);
  86. curl_setopt($ch, CURLOPT_POST, 1);
  87. curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
  88. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  89. curl_setopt($ch, CURLOPT_HEADER, 0);
  90. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  91. $response = curl_exec($ch);
  92. curl_close($ch);
  93.  
  94. $json_response = json_decode($response);
  95.  
  96. // print_r($json_response);
  97. // exit();
  98.  
  99. $user = User::where(array('email' => $_POST['email']))->first();
  100.  
  101.  
  102.  
  103. if ($user) {
  104.  
  105. Session::put('user_id', $user->id);
  106.  
  107. Session::put('email', $user->email);
  108.  
  109. Session::put('access_token', $json_response->auth->access_token);
  110.  
  111. Session::save();
  112. return Redirect::route('brokers');
  113. //$messages = $validator->messages();
  114. // return redirect('/')->with('message', $messages);
  115. }
Add Comment
Please, Sign In to add comment