Преглед изворни кода

Merge branch 'master' into dev-vj

Vijayakrishnan Krishnan пре 5 година
родитељ
комит
7ae8da9af5
2 измењених фајлова са 20 додато и 18 уклоњено
  1. 19 17
      app/Http/Controllers/LoginController.php
  2. 1 1
      app/Lib/Backend.php

+ 19 - 17
app/Http/Controllers/LoginController.php

@@ -36,20 +36,21 @@ class LoginController extends Controller
                 'cellNumber' => $request->post('cell-number'),
                 'password' => $request->post('password')
             ]);
-        }catch (\Exception $e) {
-            //TODO: Redirect with message
-        }
+            $data = json_decode($apiResponse->getContents());
 
-        $data = json_decode($apiResponse->getContents());
+            if (!property_exists($data, 'success') || !$data->success) {
+                return back()->with('message', 'Invalid login credentials.')
+                    ->withInput($request->input());
+            }
 
-        if(!property_exists($data, 'success') || !$data->success) {
-            return back()->with('message', 'Invalid login credentials.')
-                ->withInput($request->input());
-        }
+            Cookie::queue('sessionKey', $data->data->sessionKey);
 
-        Cookie::queue('sessionKey', $data->data->sessionKey);
+            return redirect()->route('dashboard');
 
-        return redirect()->route('dashboard');
+        } catch (\Exception $e) {
+            //TODO: Redirect with message
+            return redirect()->back()->with('message', $e->getMessage()); 
+        }
     }
 
 
@@ -59,25 +60,26 @@ class LoginController extends Controller
 
         try {
             //$apiResponse = $api->get('session/logOut?sessionKey=' . $request->cookie('sessionKey'));
-            $apiResponse = $api->sendRequest('session/logOut', 'GET',
+            $apiResponse = $api->sendRequest(
+                'session/logOut',
+                'GET',
                 [
                     'headers'  => [
                         'sessionKey' => $request->cookie('sessionKey')
                     ]
-                ]);
+                ]
+            );
 
             $data = json_decode($apiResponse->getContents());
 
-            if(!property_exists($data, 'success') || !$data->success) {
+            if (!property_exists($data, 'success') || !$data->success) {
                 //TODO: throw message to log
                 throw new Exception('Failed to log out of backend');
             }
-
-        }catch (Exception $e) {
+        } catch (Exception $e) {
             // TODO: Log message
             // TODO: Never fail on logout. Just delete cookie.
-        }
-        finally {
+        } finally {
             Cookie::queue(Cookie::forget('sessionKey'));
         }
 

+ 1 - 1
app/Lib/Backend.php

@@ -20,7 +20,7 @@ class Backend
 
     public function __construct()
     {
-        $this->url = env('BACKEND_URL');
+        $this->url = env('BACKEND_URL', "http://localhost:8080/api");
     }