private function auth() { $input = Input::all(); $auth = new AuthClass(); $loggedIn = $auth->isAuthenticated($input['user_id']); return $loggedIn; }
/** * Dashboard login function which takes email/password as input and return 1/2/0 on success/no account found/input field blank respectively. * @return json value */ public function postSignIn() { $email = trim(Input::get('email')); $password = Input::get('password'); try { if ($email && $password) { $admin_sess = array(); $admin = array(); $response = array(); $admin = Administrator::where('email', '=', $email)->where(function ($query) { $query->where('employee_role_id', '=', '2'); $query->orWhere('employee_role_id', '=', '3'); $query->orWhere('employee_role_id', '=', '1'); })->first(); if (isset($admin) && $admin != "") { if (password_verify($password, $admin->password)) { #if match is found $emp_market_office = EmployeeMarketOffice::where('employee_id', '=', $admin->id)->first(); $admin_info = array(); $authClass = new \App\Libraries\ApiAuth\AuthClass(); if ($emp_market_office) { $filter_by_state_office = $authClass->isfilterByStateOffice($admin->admin_role_id); $admin_info = array('admin_role_id', $admin->admin_role_id, 'state_code' => $emp_market_office->state_code, 'market_office_id' => $emp_market_office->market_office_id, 'filter_by_state_office' => $filter_by_state_office); Session::put("current_state_database", $emp_market_office->state_code); Session::put("admin_market_ofc", $emp_market_office->market_office_id); } else { throw new Exception('The employee credentials given does not have a market office assigned to it.'); } Session::put('id', $admin->id); Session::put('admin_info', $admin_info); $encryptData = $authClass->encryption($admin->id); Session::put('iv', $encryptData[1]); Session::save(); $response['status'] = '1'; $response['user_id'] = base64_encode($encryptData[0]); $response['username'] = $admin->name; $response['email'] = $admin->email; $response['image'] = ""; $response['datetime'] = $admin->updated_at; } else { // if no match is found $response['status'] = '2'; } } else { // if no match is found $response['status'] = '2'; } } else { // if email and password is blank $response['status'] = '0'; } } catch (Exception $e) { Log::error($e); $response['status'] = '0'; $msg = (array) $e->getMessage(); $response['msg'] = $msg[0]; } return Response::json($response); }