本文整理汇总了PHP中sfGuardUser::setUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP sfGuardUser::setUsername方法的具体用法?PHP sfGuardUser::setUsername怎么用?PHP sfGuardUser::setUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfGuardUser
的用法示例。
在下文中一共展示了sfGuardUser::setUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerUser
private function registerUser($username, $data = NULL)
{
try {
$gingerKey = sfConfig::get('app_portail_ginger_key');
if ($gingerKey != "abc") {
$ginger = new \Ginger\Client\GingerClient(sfConfig::get('app_portail_ginger_key'));
$cotisants = $ginger->getUser($username);
} else {
$cotisants = new stdClass();
$cotisants->mail = $username . "@etu.utc.fr";
$cotisants->prenom = "Le";
$cotisants->nom = "Testeur";
$cotisants->type = "etu";
}
if (!$data) {
$data = new sfGuardUser();
}
$data->setUsername($username);
$data->setEmailAddress($cotisants->mail);
$data->setFirstName($cotisants->prenom);
$data->setLastName($cotisants->nom);
$data->setIsActive(true);
$data->save();
$profile = new Profile();
$profile->setUser($data);
$profile->setDomain($cotisants->type);
$profile->save();
return $data;
} catch (\Ginger\Client\ApiException $ex) {
$this->setFlash('error', "Il n'a pas été possible de vous identifier. Merci de contacter simde@assos.utc.fr en précisant votre login et le code d'erreur " . $ex->getCode() . ".");
}
return false;
}
示例2: doClean
protected function doClean($values)
{
$username = isset($values[$this->getOption('username_field')]) ? $values[$this->getOption('username_field')] : '';
bhLDAP::debug('######## Username: ' . $username);
$password = isset($values[$this->getOption('password_field')]) ? $values[$this->getOption('password_field')] : '';
bhLDAP::debug('######## User exists?');
$user = Doctrine::getTable('sfGuardUser')->findOneByUsername($username);
// bhLDAP::debugDump($user, "user:");
if (!$user) {
if (bhLDAP::checkPassword($username, $password)) {
// pretend the user exists, then check AD password
bhLDAP::debug('######## User does not exist. Creating dummy user.');
$user = new sfGuardUser();
$user->setUsername($username);
$user->setSalt('unused');
$user->setPassword('unused');
$user->setUserProfile(new UserProfile());
$user->save();
}
return array_merge($values, array('user' => $user));
}
// password is ok?
bhLDAP::debug('######## Checking Password...');
if ($user->checkPassword($password)) {
bhLDAP::debug('######## Check Password successful...');
return array_merge($values, array('user' => $user));
}
bhLDAP::debug('######## Check Password failed...');
if ($this->getOption('throw_global_error')) {
throw new sfValidatorError($this, 'invalid');
}
throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid')));
}
示例3: doClean
/**
* @see sfValidatorBase
*/
protected function doClean($values)
{
// only validate if username and password are both present
if (isset($values[$this->getOption('username_field')]) && isset($values[$this->getOption('password_field')])) {
$username = $values[$this->getOption('username_field')];
$password = $values[$this->getOption('password_field')];
// user exists?
if ($user = sfGuardUserPeer::retrieveByUsername($username)) {
// password is ok?
if ($user->getIsActive()) {
if (Configuration::get('ldap_enabled', false)) {
if (authLDAP::checkPassword($username, $password)) {
return array_merge($values, array('user' => $user));
}
} elseif ($user->checkPassword($password)) {
return array_merge($values, array('user' => $user));
}
}
} elseif (Configuration::get('ldap_enabled', false) && Configuration::get('ldap_create_user', false) && authLDAP::checkPassword($username, $password)) {
$user = new sfGuardUser();
$user->setUsername($username);
$user->save();
$profile = new Profile();
$profile->setSfGuardUserId($user->getId());
$profile->save();
return array_merge($values, array('user' => $user));
}
if ($this->getOption('throw_global_error')) {
throw new sfValidatorError($this, 'invalid');
}
throw new sfValidatorErrorSchema($this, array($this->getOption('username_field') => new sfValidatorError($this, 'invalid')));
}
// assume a required error has already been thrown, skip validation
return $values;
}
示例4: testSavingBlockedUser
/**
* Tests saving a sfGuardUserSubredditMembership that identifies a User as
* "blocked" for a particular Subreddit. When this occurs, all existing
* future EpisodeAssignments should be deleted because blocked users cannot
* participate with the Subreddit.
*/
public function testSavingBlockedUser()
{
// Establish fake Subreddit
$subreddit = new Subreddit();
$subreddit->setName(rand(0, 1000));
$subreddit->setDomain(rand(0, 1000));
$subreddit->save();
// Establish User
$user = new sfGuardUser();
$user->setEmailAddress(rand(0, 100000));
$user->setUsername(rand(0, 10000));
$user->setIsValidated(1);
$user->save();
$user_id = $user->getIncremented();
$this->assertNotEquals(0, $user_id);
// Establish Episode for Subreddit
$episode = new Episode();
$episode->setSubreddit($subreddit);
$episode->setReleaseDate(date('Y-m-d H:i:s', time() + 34000));
$episode->save();
$author_type = AuthorTypeTable::getInstance()->findOneBy('type', 'squid');
$deadline = new Deadline();
$deadline->setSubreddit($subreddit);
$deadline->setAuthorType($author_type);
$deadline->setSeconds(0);
$deadline->save();
$episode_assignment = new EpisodeAssignment();
$episode_assignment->setSfGuardUser($user);
$episode_assignment->setEpisode($episode);
$episode_assignment->setAuthorType($author_type);
$episode_assignment->save();
$number_of_episodes = EpisodeAssignmentTable::getInstance()->createQuery()->select('COUNT(EpisodeAssignment.id)')->leftJoin('Episode')->where('subreddit_id = ?', $subreddit->getIncremented())->andWhere('EpisodeAssignment.sf_guard_user_id = ?', $user_id)->andWhere('Episode.release_date > NOW()')->groupBy('EpisodeAssignment.id')->count();
$this->assertEquals(1, $number_of_episodes);
// Establish User Membership as Blocked
$blocked = MembershipTable::getInstance()->findOneBy('type', 'blocked');
$user_membership = new sfGuardUserSubredditMembership();
$user_membership->setSubreddit($subreddit);
$user_membership->setSfGuardUser($user);
$user_membership->setMembership($blocked);
// Save Membership
$user_membership->save();
// Asert that User has zero Episodes
$number_of_episodes = EpisodeAssignmentTable::getInstance()->createQuery()->select('COUNT(EpisodeAssignment.id)')->leftJoin('Episode')->where('subreddit_id = ?', $subreddit->getIncremented())->andWhere('EpisodeAssignment.sf_guard_user_id = ?', $user_id)->andWhere('Episode.release_date > NOW()')->groupBy('EpisodeAssignment.id');
$sql = $number_of_episodes->getSqlQuery();
$number_of_episodes = $number_of_episodes->count();
$this->assertTrue(0 == $number_of_episodes, $sql . "\n" . $subreddit->getIncremented() . "\n" . $user_id);
// Remove User Membership
$user_membership->delete();
// Delete User
$user->delete();
// Delete Episode
$episode->delete();
// Delete Deadline
$deadline->delete();
// Delete Subreddit
$subreddit->delete();
}
示例5: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$user = new sfGuardUser();
$user->setUsername($arguments['username']);
$user->setPassword($arguments['password']);
$user->save();
$this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
}
示例6: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
$databaseManager = new sfDatabaseManager($configuration);
$user = new sfGuardUser();
$user->setUsername($arguments['username']);
$user->setPassword($arguments['password']);
$user->setIsActive(true);
$user->save();
$this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
}
示例7: doSave
public function doSave($con = null)
{
$user = new sfGuardUser();
$user->setUsername($this->getValue('username'));
$user->setPassword($this->getValue('password'));
// They must confirm their account first
$user->setIsActive(false);
$user->save();
$this->userId = $user->getId();
return parent::doSave($con);
}
示例8: executeFacebookLogin
/**
* Accepts proof of identity from the client side Facebook SDK.
* https://developers.facebook.com/docs/howtos/login/signed-request/#step2
* This will not work if your site doesn't have a proper
* domain name (it will not work in dev, in most cases).
*/
public function executeFacebookLogin(sfWebRequest $request)
{
$fb = sfConfig::get('app_sfApplyPlugin_facebook');
$secret = isset($fb['secret']) ? $fb['secret'] : null;
if (!$secret) {
throw new sfException('app_sfApplyPlugin_facebook not configured, secret missing');
}
$signed_request = $request->getParameter('signed_request');
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = $this->base64UrlDecode($encoded_sig);
$data = json_decode($this->base64UrlDecode($payload), true);
// Contrary to FB docs we're not done yet, we have to
// trade the 'code' in for an access token and then we
// can query for information about the user
$code = $data['code'];
$url = "https://graph.facebook.com/oauth/access_token?" . http_build_query(array('client_id' => $fb['id'], 'redirect_uri' => '', 'client_secret' => $secret, 'code' => $code));
$accessToken = file_get_contents($url);
parse_str($accessToken, $result);
$accessToken = $result['access_token'];
$me = json_decode(file_get_contents("https://graph.facebook.com/me?" . http_build_query(array('access_token' => $accessToken))), true);
if (!isset($me['email'])) {
$this->forward404();
}
$email = $me['email'];
$first_name = $me['first_name'];
$last_name = $me['last_name'];
$username = 'fb_' . (isset($me['username']) ? $me['username'] : $me['id']);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
$this->forward404();
}
// Adding the verification of the signed_request below
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
$this->forward404();
}
$user = Doctrine::getTable('sfGuardUser')->findOneByEmailAddress($email);
if (!$user) {
$user = new sfGuardUser();
$user->setIsActive(true);
$user->setPassword(aGuid::generate());
$user->setEmailAddress($email);
$user->setUsername($username);
}
$user->setFirstName($firstName);
$user->setLastName($lastName);
$user->setEmailAddress($email);
$user->save();
$this->getUser()->signIn($user);
return $this->renderText('OK');
}
示例9: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$user = new sfGuardUser();
$user->setUsername($arguments['username']);
$user->setPassword($arguments['password']);
$user->save();
$profile = new Profile();
$profile->setNickname($arguments['nickname']);
$profile->setEmail($arguments['email']);
$profile->setSfGuardUserId($user->getId());
$profile->save();
$this->logSection('crew', sprintf('Create user "%s"', $arguments['username']));
}
示例10: createUser
public function createUser(array $guard_tab, $ei_user_tab)
{
$new_guard = new sfGuardUser();
$new_guard->setId($guard_tab['id']);
$new_guard->setUsername($guard_tab['username']);
$new_guard->setFirstName($guard_tab['first_name']);
$new_guard->setLastName($guard_tab['last_name']);
$new_guard->setEmailAddress($guard_tab['email_address']);
$new_guard->setPassword($guard_tab['password']);
$new_guard->save();
/* Création du EiUser */
EiUserTable::createUser($ei_user_tab, $new_guard->getId());
return $new_guard;
}
示例11: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$user = new sfGuardUser();
$user->setEmailAddress($arguments['email_address']);
$user->setUsername($arguments['username']);
$user->setPassword($arguments['password']);
$user->setFirstName($arguments['first_name']);
$user->setLastName($arguments['last_name']);
$user->setIsActive(true);
$user->setIsSuperAdmin($options['is-super-admin']);
$user->save();
$this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
}
示例12: doSave
public function doSave($con = null)
{
if ($this->isNew) {
$user = new sfGuardUser();
$user->setUsername($this->getValue('username'));
$user->setPassword($this->getValue('password'));
$user->setEmailAddress($this->getValue('email'));
$user->addGroupByName(sfConfig::get('app_user_default_group'));
// They must confirm their account first
$user->setIsActive(false);
$user->save();
$this->getObject()->setUserId($user->getId());
}
return parent::doSave($con);
}
示例13: executeApply
public function executeApply()
{
$request = $this->getRequest();
$this->form = new RegisterForm();
if ($this->getRequest()->getMethod() == sfRequest::POST) {
$this->form->bind($request->getParameter('register'));
if ($this->form->isValid()) {
mysfLog::log($this, "DEBUG: " . print_r($this->form->getValues(), TRUE));
$this->form_ref =& $this->form;
$username = $this->form->getValue('email');
$password = $this->form->getValue('password');
$sfGuardUser = new sfGuardUser();
$sfGuardUser->setUsername($username);
$sfGuardUser->setPassword($password);
// Not until confirmed
$sfGuardUser->setIsActive(false);
$profile = $sfGuardUser->getProfile();
$sfGuardUser->save();
// save sfGuardUser before we populate the user profile because we need the user id
$this->myPopulateProfileSettings($profile, $sfGuardUser);
$profile->save();
// Email start
$opts = array();
$opts['from_name'] = sfConfig::get('app_mail_fromname', "Spectralmind");
$opts['from_email'] = sfConfig::get('app_mail_from', "office@spectralmind.com");
$opts['parameters'] = array('validate' => $profile->getValidate());
$opts['body_is_partial'] = true;
$opts['to_name'] = $profile->getName();
$opts['to_email'] = $profile->getEmail();
$opts['subject'] = sfConfig::get('app_mail_subjectconfirmmail', "Confirm your registration");
//$opts['html'] = "sendValidateNew";
$opts['text'] = "sendValidateNew";
/*
// Or to use the Echo Logger
$logger = new Swift_Plugins_Loggers_EchoLogger();
$this->getMailer()->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
* */
$numSent = smintMailHelper::mail($opts);
// not sent? react accordingly
if ($numSent != 1) {
mysfLog::log($this, "ERROR: confirmation email not sent. Return value was {$numSent}");
return 'Error';
}
mysfLog::log($this, "DEBUG: Confirm link:" . url_for("sfApply/confirm?validate=" . $profile->getValidate(), true));
return 'After';
}
}
}
示例14: createUser
/**
* Create a user for a Facebook account
*
* Based on and borrowed heavily from
* sfFacebookGuardAdapter::createSfGuardUserWithFacebookUidAndCon in
* sfFacebookConnectPlugin by Fabrice Bernhard
*
* @param int $facebookUid
* @param string $accessToken
* @param int $accessTokenExpiry
* @param array $facebookUserInfo
* @return sfGuardUser
*/
public static function createUser($facebookUid, $accessToken, $accessTokenExpiry, array $facebookUserInfo)
{
$sfGuardUser = new sfGuardUser();
$sfGuardUser->setUsername(self::generateFacebookUsername($facebookUid));
$connection = Doctrine::getConnectionByTableName('sfGuardUser');
try {
$connection->beginTransaction();
$sfGuardUser->save();
$sfGuardUser->getProfile()->setFacebookOnlyAccount(true)->_connectToFacebook($facebookUid, $accessToken, $accessTokenExpiry, $facebookUserInfo, $sfGuardUser);
$connection->commit();
} catch (Exception $e) {
$connection->rollback();
throw $e;
}
return $sfGuardUser;
}
开发者ID:passkey1510,项目名称:sfFacebookGraphPlugin,代码行数:29,代码来源:PluginsfFacebookGraphUserProfile.class.php
示例15: getTaskUser
/**
* DOCUMENT ME
* @return mixed
*/
public static function getTaskUser()
{
$user = Doctrine::getTable('sfGuardUser')->findOneByUsername('ataskuser');
if (!$user) {
$user = new sfGuardUser();
$user->setUsername('ataskuser');
// Set a good unique password just in case someone cluelessly sets the active flag.
// This further ensures that no one can ever log in with this account
$user->setPassword(aGuid::generate());
// Prevents normal login
$user->setIsActive(false);
$user->setIsSuperAdmin(true);
$user->save();
}
return $user;
}