コード例 #1
0
 public function login(sfAuthUser $user, $remember = false)
 {
     $context = sfContext::getInstance();
     $sfUser = $context->getUser();
     $request = $context->getRequest();
     $response = $context->getResponse();
     $credentials = $user->getAllCredentials();
     $sfUser->setAttribute('user_id', $user->getId(), 'sfAuthUser');
     $sfUser->setAuthenticated(true);
     $sfUser->clearCredentials();
     $sfUser->addCredentials($user->getAllCredentials());
     if ($remember) {
         //generate a hash for the remember_me_hash column
         $user->setRememberMeHash(sfAuthUtil::getHashedPasswordBySaltAndString($user->getUsername(), 'cookie'));
         //Configuration vars
         $expire = sfConfig::get('app_sf_auth_plugin_cookie_expire', 1209600) + time();
         $cookie_name = sfConfig::get('app_sf_auth_plugin_cookie_name', 'sfAuthUserCookie');
         //if the cookie already exists destroy it.
         if ($request->getCookie($cookie_name)) {
             $response->setCookie($cookie_name, '', time() - 3600);
         }
         $response->setCookie($cookie_name, $user->getRememberMeHash(), $expire);
         $user->save();
     }
     //Event dispatcher the user have logged in... Useful for setting Culture
     //etc when a user have logged in that may recide in another table
     $this->dispatcher->notify(new sfEvent($this, 'sf_auth.login'));
 }
コード例 #2
0
 public function getAllByUser(sfAuthUser $user)
 {
     $q = $this->createQuery('c');
     $q->leftjoin('c.sfAuthUserCredential uc');
     $q->leftjoin('c.sfAuthGroup g');
     $q->leftjoin('g.sfAuthGroupCredential cg');
     $q->leftjoin('cg.sfAuthGroup cgg');
     $q->leftjoin('cgg.sfAuthUserGroup ugg');
     $q->addWhere('ugg.sf_auth_user_id = ? OR uc.sf_auth_user_id = ?', array($user->getId(), $user->getId()));
     $q->groupby('c.id');
     //Aggregate
     $credentials = array();
     foreach ($q->execute(array(), Doctrine::HYDRATE_ARRAY) as $credential) {
         $credentials[] = $credential['name'];
     }
     return $credentials;
 }