/**
  * 
  * @param PCRequest $request
  * @param PCModelApplication $application
  * @return bool
  */
 public function doLogin($request, $application)
 {
     $param = $request->getParams();
     $userName = $param['uname'];
     $pwd = $param['pwd'];
     $keys = array('username' => $userName, "account_type" => PCModelUser::$TYPE_DEFAULT);
     $user_array = PCModelManager::fetchModelObjectInstances(PCModelUser::getMapper(), $keys, NULL, TRUE);
     $user = $user_array[0];
     if (isset($user) && strcmp($pwd, $user->getPassword()) == 0) {
         $secret = $application->getAppSecret();
         $appId = $application->getIdentifier();
         $time = time();
         $cookieValue = PCAuth::computeHashForString($userName . $time . $secret);
         $distantFuture = PCResponseCookie::getDistantFuture();
         if (PCMapperToken::setTokenForUserWithIdentifier($user->getIdentifier(), $appId, $cookieValue, $distantFuture)) {
             $_SESSION['user'] = $this->user_id = $user->getIdentifier();
             $presence_cookie = PCResponseCookie::lifetimeCookie("presence_c", $cookieValue);
             //setcookie("presence_c", $cookieValue, $expirationTime,"/");
             $user_cookie = PCResponseCookie::lifetimeCookie("user", $user->getIdentifier());
             //setcookie("user",$user->getIdentifier(), $expirationTime,"/");
             $response = PCResponse::currentResponse();
             $response->addCookie($presence_cookie);
             $response->addCookie($user_cookie);
         } else {
             return FALSE;
         }
         return TRUE;
     }
     return FALSE;
 }
예제 #2
0
 /**
  * Returns the website with a specific domain
  * @param string $domain
  * @return PCModelWebsite
  */
 public static function getSiteWithDomain($domain)
 {
     $sites = PCModelManager::fetchModelObjectInstances(PCModelWebsite::getMapper(), array('domain' => $domain));
     if (count($sites) <= 0) {
         return NULL;
     }
     return $sites[0];
 }
예제 #3
0
     /**
     * Crea una nuova password(aggiorna il db) e la restituisce. restituisce false in caso negativo
     * @param PCModelUser $user_id l' id dell' utente
     * @param string $hash l' hash inviato dall'utente
     * @param PCModelUser
     * @return boolean|string
     */
    public static function handleRepassRequest($user_id, $hash, &$user_to_ret) {
        $keys = array('request_hash'=>$hash, 'user_id'=>$user_id);
        $items = PCModelManager::fetchModelObjectInstances(PCModelRepass::getMapper(), $keys, NULL, TRUE);
        if (count($items) <= 0) {
            return FALSE;
        }

        $item = $items[0];

        if ($item == NULL || $item->isExpired()) {
            c_dump("SCADUTA");
            return FALSE;
        }

        $bindigngs = array(":h" => $hash, ":user"=> $user_id);
        
        PCModelManager::deleteObject(PCModelRepass::getMapper(), "request_hash = :h AND user_id = :user", $bindigngs);
        
        $newPwd = PCMapperRepass::rand_password(8); 
        

        $model_user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $item->getUser_id(), NULL, TRUE);
        
        
        if($model_user == NULL){
            $id = $item->getUser_id();
            error_log("User non presente (user_id: $id )");
            return FALSE;
        }
        
        $newPwdHash = PCAuth::computeHashForString($newPwd);
        
        if(PCMapperUser::changePasswordForUser($model_user, $newPwdHash) == FALSE){
            return FALSE;
        }
        $user_to_ret = $model_user;
        return $newPwd;
        
    }
예제 #4
0
 public static function getAll(){
     $order = " name";
     return PCModelManager::fetchModelObjectInstances(PCModelCategory::getMapper(), array(), null, true, null, $order);
 }
예제 #5
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("/");
        }
        
    }
예제 #6
0
 /**
  * 
  * @param string $user
  * @param int $offset
  * @return array
  */
 public static function getReviewsWithUserIdentifier($user, $offset){
     $offset = (int)$offset;
     if($offset<0){
         return NULL;
     }
     $keys = array('user_identifier' => $user);
     //$elementsToReturn = 10;
     $elementsToReturn = PCConfigManager::sharedManager()->getIntegerValue('REVIEWS_PER_CALL');
     $limit = ($offset*$elementsToReturn)." , ".$elementsToReturn." ";
     $elements = PCModelManager::fetchModelObjectInstances(PCModelReview::getMapper(), $keys, NULL, FALSE, $limit);
     return $elements;
 }
예제 #7
0
 /**
  * @param $identifier string
  */
 public function withIdentifier($identifier, $optional_attributes = null, $use_cache = FALSE){
     return PCModelManager::fetchModelObjectInstances($this, array("identifier"=>$identifier), $optional_attributes, $use_cache);
 }
예제 #8
0
    /**
     * 
     * @param string $user_identifier
     * @param int $service il codice servizio (es Facebook o Twitter)
     * @return array
     */
    public static function getOauthConfig($user_identifier, $service ){
        $val = array(
            "user_identifier" => $user_identifier,
            "oauth_provider" => $service
        );

        $inst = PCModelManager::fetchModelObjectInstances(PCModelUserOauth::getMapper(), $val);
        if(count($inst) == 0 ) return NULL;
        return $inst[0];
    }