/** * @param PCHelperSocialAdapter $adapter * @return PCModelUserOauth */ public static function createUserForOauthServiceWithAdapter($adapter){ $values = $adapter->getValuesForCreatingUser(); $mapper = PCModelUser::getMapper(); //creo il 'vero' utente nel db if (PCModelManager::insertObject($mapper, $values) == FALSE) return NULL; $instances = PCModelManager::fetchModelObjectInstances($mapper, $values); if(count($instances) == 0) return NULL; $user = $instances[0]; $user_identifier = $user->getIdentifier(); $token = $adapter->getTokenValue(); $secret = $adapter->getSecretValue(); $service_u_id = $adapter->getServiceUserIdentifier(); $service_type = $adapter->getServiceType(); if(PCMapperUserOauth::insertUserOauth($service_type, $service_u_id, $token, $secret, $user_identifier)){ $adapter->addOauthInfoToUser($user); if (PCConfigManager::sharedManager()->getBoolValue('NOTIF_ON_REGISTER')) { $email = $values['email']; $surname = $values['surname']; $name = $values['name']; $username = $values['username']; $serv = $adapter->getServiceName(); PCHelperNotificationSender::sendPushNotificationToAdmin("User Registered", "uname: $username Name: $name Sur: $surname mail: $email service_id: $service_u_id via: $serv"); } return $user; } return NULL; }
/** * * @param PCRequest $request */ public function registerAction($request) { require_once __EXTERNAL_LIBRARIES__ . '/recaptcha/recaptchalib.php'; $auth = $request->getAuthHandler(); if ($auth->isAuthorized()) { return new PCRendererJSON(array("error" => "you can't register a new user while logged"), 400); } $attributes = $request->getParams(); $privatekey = "6Lfm39cSAAAAAFpyN0tQr4TYNt1zqiaHn9E22lYb"; $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $attributes["recaptcha_challenge_field"], $attributes["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly error_log($resp->error); return new PCRendererJSON(array("captcha_error" => "Incorrect Captcha")); } if (!isset($attributes['username']) || !isset($attributes['name']) || !isset($attributes['surname']) || !isset($attributes['email']) || !isset($attributes['password'])) { throw new PCExceptionAuth("Missing param", 400); } $inputError = NULL; if (PCHelperValidator::validatePassword($attributes['password'], $inputError) == FALSE) { return new PCRendererJSON(array("error" => $inputError), 400); } if (PCHelperValidator::validateUsername($attributes['username'], $inputError) == FALSE) { return new PCRendererJSON(array("error" => $inputError), 400); } if (PCHelperValidator::validateName($attributes['name'], $inputError) == FALSE) { return new PCRendererJSON(array("error" => $inputError), 400); } if (PCHelperValidator::validateSurname($attributes['surname'], $inputError) == FALSE) { return new PCRendererJSON(array("error" => $inputError), 400); } if (PCHelperValidator::validateEmail($attributes['email'], $inputError) == FALSE) { return new PCRendererJSON(array("error" => $inputError), 400); } $username = $attributes['username']; $name = $attributes['name']; $surname = $attributes['surname']; $email = $attributes['email']; $password = $attributes['password']; $store = array(); $store['username'] = $username; $store['name'] = $name; $store['surname'] = $surname; $store['email'] = $email; $store['password'] = PCAuth::computeHashForString($password); $error = NULL; if (PCMapperUser::createUserWithAttributes($store, $error)) { if (PCConfigManager::sharedManager()->getBoolValue('NOTIF_ON_REGISTER')) { PCHelperNotificationSender::sendPushNotificationToAdmin("User Registered", "uname: {$username} Name: {$name} Sur: {$surname} mail: {$email}"); } return new PCRendererJSON(array("OK" => "User added")); } return new PCRendererJSON(array("error" => $error), 400); }
/** * Aggiunge una recensione * @param PCRequest $request */ public function addReviewAction($request){ $auth = $request->getAuthHandler(); if($auth->isAuthorized() == FALSE){ throw new PCExceptionAuth("Auth Required", 401); } $params = $request->getParams(); $url = PCHelperInputCleaner::cleanInputString($params['siteUrl']); $comment = PCHelperInputCleaner::cleanInputString($params['comment']); $contents = PCHelperInputCleaner::cleanInputString($params['contents']); $reliability = PCHelperInputCleaner::cleanInputString($params['reliability']); $usability = PCHelperInputCleaner::cleanInputString( $params['usability']); $category = PCHelperInputCleaner::cleanInputString($params['category']); $language = PCHelperInputCleaner::cleanInputString($params['language_code']); $siteIdentifier = PCHelperInputCleaner::cleanInputString($params['site_identifier']); if((!empty($url) || !empty($siteIdentifier)) && isset($comment) && isset($contents) && isset($reliability) && isset($usability) && isset($category) && isset($language)){ $error = NULL; $user = PCModelUser::getCurrentUser(); $result = PCMapperWebsite::addSiteWithReview($url, $user, $comment, $usability, $contents, $reliability, $category, $language, $error, $siteIdentifier); if($result){ if(PCConfigManager::sharedManager()->getBoolValue('SOCIAL_POST_ON_REVIEW')){ $userName = $user->getUsername(); PCHelperNotificationSender::sendPushNotificationToAdmin("Aggiunta Recensione", "User: $userName r($reliability) u($usability) c($contents) url: $url"); } return new PCRendererJSON(array("OK"=>"Site Added")); } else{ error_log($error); return new PCRendererJSON(array("error"=>$error),401); } } return new PCRendererJSON("Error adding site", 400); }