Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login(Request $request)
- {
- $rules = array(
- 'email' => 'required',
- 'password' => 'required',
- );
- $messages = array();
- $validator = Validator::make($request->all(), $rules, $messages);
- if ($validator->fails()) {
- return [
- 'status' => 204,
- 'message' => $validator->errors()->first()
- ];
- }
- $user = User::where('email', $request->email)->first();
- if (!$user) {
- return response(['status' => 204, 'message' => 'User Not Found']);
- }
- if (Hash::check($request->password, $user->password)) {
- $http = new Client;
- $response = $http->post(url('oauth/token'), [
- 'form_params' => [
- 'grant_type' => 'password',
- 'client_id' => '2',
- 'client_secret' => 'oWXBChJA8TUItWnvZ3J52KNhGMqsPkEqpDyhjnNf',
- 'username' => $request->email,
- 'password' => $request->password,
- 'scope' => '',
- ],
- ]);
- $getVerifyStatus = AppStatus::where('id', $user->profile_verify_status_id)->value('name');
- if ($getVerifyStatus == 'verified') {
- return response(['status' => 200, 'message' => 'Sign In Successfully','auth' => json_decode((string)$response->getBody(), true), 'user' => $user]);
- }
- else {
- return response(['message' => 'Profile Not Verified', 'status' => 204]);
- }
- }
- else {
- return response(['message' => 'Password Not Match', 'status' => 204]);
- }
- }
- public function loginShipper()
- {
- return view('login');
- }
- public function login()
- {
- $validator = Validator::make(
- array(
- 'email' => $_POST['email'],
- 'password' => $_POST['password']
- ),
- array(
- 'email' => 'required',
- 'password' => 'required'
- )
- );
- if ($validator->fails()) {
- $messages = $validator->messages();
- return redirect('/')->with('message', $messages);
- }
- else
- {
- // $u_password = (Hash::check();
- $url = 'http://localhost:81/mvp/api/shipper/login';
- $myvars = 'email=' . $_POST['email'] . '&password=' . $_POST['password'] . '&created_at=' . '';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $response = curl_exec($ch);
- curl_close($ch);
- $json_response = json_decode($response);
- // print_r($json_response);
- // exit();
- $user = User::where(array('email' => $_POST['email']))->first();
- if ($user) {
- Session::put('user_id', $user->id);
- Session::put('email', $user->email);
- Session::put('access_token', $json_response->auth->access_token);
- Session::save();
- return Redirect::route('brokers');
- //$messages = $validator->messages();
- // return redirect('/')->with('message', $messages);
- }
Add Comment
Please, Sign In to add comment