Ejemplo n.º 1
0
 /**
  * 
  * @param PCModelWebsite $site
  * @param PCModelUser $user
  * @param string $comment
  * @param string $usability
  * @param string $contents
  * @param string $reliability
  * @param string $language
  * @param string $error
  * @return bool
  */
 public static function addReviewForSite($site, $user, $comment, $usability, $contents, $reliability, $language, &$error) {
     if (!isset($site) || !isset($site)){
         die("Internal Inconsistency");
     }
     
     if(!PCHelperValidator::validateLanguageCode($language)){
         $error = "Invalid language code";
         return FALSE;
     }
     $language = strtoupper($language);
     $commentLen = strlen($comment);
     if ($commentLen < 5 || $commentLen > PCModelReview::maxCommentLength) {
         
         $error = "Invalid comment length, ".( ($commentLen < 5) ? " minumum length is 6 characters" : "maximum length is 200 characters");
         return FALSE;
     }
     
     $usa = floatval($usability);
     $cont = floatval($contents);
     $rel = floatval($reliability);
     
     if($usa < PCModelReview::minVote ||$usa > PCModelReview::maxVote){
         $error = "usability is not valid";
         return FALSE;
     }
     if($cont < PCModelReview::minVote ||$cont > PCModelReview::maxVote){
          $error = "contents is not valid";
         return FALSE;
     }
     if($rel < PCModelReview::minVote ||$rel > PCModelReview::maxVote){
          $error = "reliability is not valid";
         return FALSE;
     }
     
     $date_added = new DateTime('now', new DateTimeZone('UTC'));
     $date_added_mysql = $date_added->format('Y-m-d H:i:s');
     
     $values = array(
         'site_identifier' => $site->getIdentifier(),
         'user_identifier' => $user->getIdentifier(),
         'comment' => $comment,
         'usability' => $usa,
         'reliability' => $rel,
         'contents' => $cont,
         'language_code' => $language,
         'date_added' => $date_added_mysql
     );
     
     if($user->getAccountType() !== PCModelUser::$TYPE_DEFAULT && PCConfigManager::sharedManager()->getBoolValue('SOCIAL_POST_ON_REVIEW') ){
         $user->postReviewToTimeline($values,$site);
     }
     
     $dupUpdate = array('language_code','date_added','contents','reliability','usability','comment');
     
     if(PCModelManager::insertObject(PCModelReview::getMapper(), $values, $dupUpdate)){
         return TRUE;
     }
     $error = "Error adding review please try later";
     return FALSE;
 }
Ejemplo n.º 2
0
 public static function validatePassword($password) {
     return PCHelperValidator::validatePassword($password);
 }
Ejemplo n.º 3
0
 /**
  * 
  * @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);
 }