Exemplo n.º 1
0
        /**
     * @param PCRequest $request
     */
    public function profileAction($request) {

        $auth = $request->getAuthHandler();
        $auth->authorize();
         $params = $request->getParams();
        
       

        if (isset($params['id']) && $auth->isAuthorized() && (strcmp($params['id'], $auth->getUserIdentifier()) == 0)) {

            $result = array();
            $user = PCModelUser::getCurrentUser();

            $result['username'] = $user->getUsername();
            $result['name'] = $user->getName();
            $result['surname'] = $user->getSurname();
            $result['member_since'] = $user->getCreation_date()->format("Y-m-d");
            $result['user_id'] = $user->getIdentifier();
            $result['email'] = $user->getEmail();
            $result['title'] = "WebSherpa - " . $user->getUsername();
            return PCRendererHTML::rendererForView('user', $result);
        }


        return null;
    }
Exemplo n.º 2
0
 /**
  * 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);
     
 }
Exemplo n.º 3
0
 /**
  * 
  * @param PCRequest $request
  * @throws PCExceptionRedirection
  */
 public function logoutAction($request){
     
         $auth = $request->getAuthHandler(); 
         $auth->logout();
        
         throw new PCExceptionRedirection("/");
 }
Exemplo n.º 4
0
    /**
     * @param PCRequest $request
     */
    public function facebookCallbackAction($request) {
        PCAutoloader::importLibrary('facebook');
        $facebook = new Facebook(array(
            "appId" => FB_APP_ID,
            "secret" => FB_APP_SECRET,
            "cookie" => true
        ));
        $params = $request->getParams();
        $user_profile = NULL;
        
        try {
            $user = $facebook->getUser();
            if (isset($user)) {
                $user_profile = $facebook->api('/me');      
            }
        } catch (FacebookApiException $e) {
            c_dump($_GET);
            error_log("AAAA".$e);
            throw new PCExceptionRedirection("/page/register");
        }
        
        if (isset($params['reg_username'])){
            
            if (PCMapperUser::validateUsername($params['reg_username']) == FALSE) {
                $cont = array("title" => "WebSherpa - Insert Username", "text_error" => "Insert a valid Username; min 6 characters use only characters and numbers and \"_\"", "show_email" => TRUE);
                return PCRendererHTML::rendererForView('insertUname', $cont);
            }

            if (count(PCModelManager::fetchModelObjectInstances(PCModelUser::getMapper(), array("username" => $params['reg_username']))) != 0) {
                $cont = array("title" => "WebSherpa - Insert Username", "text_error" => "Username already used, please choose another username.", "show_email" => TRUE);
                return PCRendererHTML::rendererForView('insertUname', $cont);
            }
            
            $adapter = new PCHelperSocialAdapterFacebook($facebook, $user_profile, $params['reg_username']);
            if($request->getAuthHandler()->authorizeOauthUser($adapter)){
                throw new PCExceptionRedirection("/");
            }
            throw new PCExceptionRedirection("/page/register");
        }
        else{
            
            $adapter = new PCHelperSocialAdapterFacebook($facebook, $user_profile);
            if($request->getAuthHandler()->authorizeOauthUser($adapter) === FALSE){
                
                return PCRendererHTML::rendererForView('insertUname', array("title" => "WebSherpa - Insert Username"));
            }
            
            throw new PCExceptionRedirection("/");
        }
        
    }
Exemplo n.º 5
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);
 }