Exemplo n.º 1
0
 /**
  * Login the user with credentials past in POST
  */
 public static function login()
 {
     $app = \Slim\Slim::getInstance();
     AppUtils::logout();
     try {
         // get and decode JSON request body
         $request = $app->request();
         $response = $app->response();
         $body = $request->getBody();
         $login = (array) json_decode($body);
         $loginOK = false;
         // AppUtils::logDebug("attempting login
         // ".$login['userId'].'/'.$login['password']);
         if (!isset($login['userId'])) {
             AppUtils::sendError(0, "Login Error", "User ID was not specified.", 401);
             return;
         }
         if (!isset($login['password'])) {
             AppUtils::sendError(0, "Login Error", "Password was not specified.", 401);
             return;
         }
         $userService = new UserServicePDO();
         if ($userService->validateUser($login['userId'], $login['password'])) {
             // AppUtils::logDebug($login['userId'].' Successfully logged in.');
             $access = $userService->getAccess($login['userId']);
             AppUtils::setLoginValid($login['userId'], $access);
             $rsp = array('userId' => $login['userId'], 'accessLevel' => $access);
             AppUtils::sendResponse($rsp);
         } else {
             // AppUtils::logDebug($login['userId'].' Failed login!');
             AppUtils::sendError(0, "Login Error", "User ID/Password combination is invalid.", 401);
         }
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error Authenticating User", $e->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @see UserServicePDO::setUserSetting()
  */
 public static function setUserSetting($id, $domain, $settingKey)
 {
     $app = \Slim\Slim::getInstance();
     try {
         $pdo = new UserServicePDO();
         // get and decode JSON request body
         $request = $app->request();
         //         $body = $request->getBody();
         //         $settingData = (array) json_decode($body);
         $settingValue = $request->params('settingValue');
         $pdo->setUserSetting($id, $domain, $settingKey, $settingValue);
         AppUtils::sendResponse($settingValue);
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error setting value for user {$id} setting {$domain}/{$settingKey}", $e->getMessage());
     }
 }