public static function auth($response, $creds) { if (count($creds) != 2) { return putError('invalid request parameters', Users::ERROR_FORMAT, $response); } $creds[Users::EMAIL_KEY] = Validator::filterEmail($creds, Users::EMAIL_KEY); $creds[Users::PASSWORD_KEY] = Validator::filterPassword($creds, Users::PASSWORD_KEY); $creds[Users::REMOTE_ADDR_KEY] = $_SERVER['REMOTE_ADDR']; if (!$creds[Users::EMAIL_KEY]) { return putError('invalid email parameter', Users::ERROR_EMAIL_FORMAT, $response); } else { if (!$creds[Users::PASSWORD_KEY]) { return putError('invalid password parameter', Users::ERROR_PASSWORD_FORMAT, $response); } } $creds = UsersDB::auth($creds); if ($creds === FALSE) { return putError('invalid user credentials', Users::ERROR_AUTH_INVALID, $response); } return putJsonBody(array('error' => false, 'result' => array('user_id' => $creds[Users::ID_KEY], 'token' => $creds[Users::TOKEN_KEY])), 200, $response); }