public function postAuthenticate() { $serviceRequest = $this->GetObjectFromJsonRequest(Input::json()->all()); /*$serviceResponse = $this->securityDataProvider->postAuthenticate($serviceRequest->Data);*/ $serviceResponse = $this->securityDataProvider->AuthenticateUser($serviceRequest->Data); if (!empty($serviceResponse->Data)) { SessionHelper::setRoleID($serviceResponse->Data->userdeatil->RoleID); SessionHelper::setRoleName($serviceResponse->Data->userdeatil->RoleName); SessionHelper::setUserName($serviceResponse->Data->userdeatil->FirstName); } if ($serviceResponse->IsSuccess) { $userLoginChecked = Auth::User(); if (!empty($userLoginChecked)) { $sessionCheckURL = SessionHelper::getRedirectURL(); if (!empty($sessionCheckURL)) { $serviceResponse->Data->redirectURL = $sessionCheckURL; } else { $logInRoleData = Common::GetLoginRoleText($userLoginChecked->RoleID); $serviceResponse->Data->redirectURL = URL::to('/' . $logInRoleData->redirectURL); } } } return $this->GetJsonResponse($serviceResponse); }
public function AuthenticateUser($loginModel) { $response = new ServiceResponse(); $authModel = new StdClass(); $messages = array('required' => trans('messages.PropertyRequired')); $validator = Validator::make((array) $loginModel, array('Email' => 'required|email', 'Password' => 'required'), $messages); $validator->setAttributeNames(UserEntity::$niceNameArray); if ($validator->fails()) { $response->Message = Common::getValidationMessagesFormat($validator->messages()); return $response; } $hashedPassword = $loginModel->Password; //md5($loginModel->Password); $searchParams = array(); $searchValueData = new SearchValueModel(); $searchValueData->Name = "Email"; $searchValueData->Value = $loginModel->Email; $searchValueData->CheckStartWith = Constants::$CheckStartWith; array_push($searchParams, $searchValueData); $searchValueData = new SearchValueModel(); $searchValueData->Name = "Password"; $searchValueData->Value = $hashedPassword; array_push($searchParams, $searchValueData); $searchValueData = new SearchValueModel(); $searchValueData->Name = "IsEnable"; $searchValueData->Value = Constants::$IsEnableValue; array_push($searchParams, $searchValueData); $loggedUserResults = DB::table('users')->where('Email', $loginModel->Email)->where('Password', $loginModel->Password)->where('IsEnable', Constants::$IsEnableValue)->first(); if (!$loggedUserResults) { $loggedUserResults = DB::table('users')->where('Email', $loginModel->Email)->where('Password', md5($loginModel->Password))->where('IsEnable', Constants::$IsEnableValue)->first(); } if (is_null($loggedUserResults)) { $response->Message = trans('messages.InvalidUserNamePassword'); } else { $user = $this->GetEntityForUpdateByPrimaryKey(new UserEntity(), $loggedUserResults->UserID); $searchParams = array(); $searchValueData = new SearchValueModel(); $searchValueData->Name = "UserID"; $searchValueData->Value = $loggedUserResults->UserID; array_push($searchParams, $searchValueData); $role = $this->GetEntity(new vwUserRoleEntity(), $searchParams); if ($role->RoleID != Constants::$Value_True) { $response->Message = trans("messages.UnauthorizeAction"); return $response; } $userHistoryEntity = new UserHistoryEntity(); $dateTime = date(Constants::$DefaultDateTimeFormat); $userHistoryEntity->LoginTime = $dateTime; $userHistoryEntity->LogoutTime = '0000-00-00 00:00:00'; $userHistoryEntity->UserID = $loggedUserResults->UserID; $this->SaveEntity($userHistoryEntity); Auth::login($user); $authModel->userdeatil = $user; $authModel->userdeatil->RoleID = $role->RoleID; $authModel->userdeatil->RoleName = $role->RoleName; $authModel->getUserRoleID = $role->RoleID; $getRole = Common::GetLoginRoleText($authModel->getUserRoleID); $authModel->redirectURL = $getRole->redirectURL; $response->Data = $authModel; $response->Message = trans('messages.LoginSuccess'); $response->IsSuccess = true; } return $response; }
public static function CheckUserLogin() { $response = new ServiceResponse(); if (SessionHelper::getRoleID() || Auth::check()) { $roleDetails = Common::GetLoginRoleText(SessionHelper::getRoleID()); $response->IsSuccess = true; $response->Data = $roleDetails; } return $response; }