本文整理汇总了PHP中sfGuardUser::save方法的典型用法代码示例。如果您正苦于以下问题:PHP sfGuardUser::save方法的具体用法?PHP sfGuardUser::save怎么用?PHP sfGuardUser::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfGuardUser
的用法示例。
在下文中一共展示了sfGuardUser::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->asfGuardUser !== null) {
if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
$affectedRows += $this->asfGuardUser->save($con);
}
$this->setsfGuardUser($this->asfGuardUser);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$criteria = $this->buildCriteria();
$pk = BasePeer::doInsert($criteria, $con);
$affectedRows += 1;
$this->setNew(false);
} else {
$affectedRows += sfGuardRememberKeyPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例2: executeRegister
/**
* executeRegister
*
* @access public
* @return void
*/
public function executeRegister(sfWebRequest $request)
{
$this->form = new sfGuardFormRegister();
if ($request->isMethod(sfRequest::POST)) {
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid()) {
$values = $this->form->getValues();
$sfGuardUser = new sfGuardUser();
$sfGuardUser->fromArray($values, BasePeer::TYPE_FIELDNAME);
if (isset($values['email'])) {
$sfGuardUser->setEmail($values['email']);
}
$sfGuardUser->setIsActive(false);
$sfGuardUser->save();
$messageParams = array('sfGuardUser' => $sfGuardUser, 'password' => $values['password']);
$body = $this->getComponent($this->getModuleName(), 'send_request_confirm', $messageParams);
$from = sfConfig::get('app_sf_guard_extra_plugin_mail_from', 'noreply@example.org');
$fromName = sfConfig::get('app_sf_guard_extra_plugin_name_from', 'noreply');
$to = $sfGuardUser->getEmail();
$toName = $sfGuardUser->getUsername();
$subject = sfConfig::get('app_sf_guard_extra_plugin_subject_confirm', 'Confirm Registration');
$mailer = $this->getMailer();
$message = $mailer->compose(array($from => $fromName), array($to => $toName), $subject, $body);
$mailer->send($message);
$this->getUser()->setFlash('values', $values);
$this->getUser()->setFlash('sfGuardUser', $sfGuardUser);
return $this->redirect('@sf_guard_do_register');
}
}
}
示例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: 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')));
}
示例5: executeSignin
public function executeSignin($request)
{
$this->form = new sfGuardFormSignin();
if ($request->isMethod('post')) {
$data = $request->getParameter('signin');
$adldap = new adLDAP(array('account_suffix' => '@sch.bme.hu', 'domain_controllers' => array('152.66.208.42'), 'ad_username' => $data['username'], 'ad_password' => $data['password']));
try {
$authUser = $adldap->authenticate($data['username'], $data['password']);
if ($authUser === true) {
$userData = $adldap->user_info($data['username']);
$user = Doctrine::getTable('sfGuardUser')->findOneBy('username', $data['username']);
$save = false;
if ($user) {
if ($user->Profile->full_name != $userData[0]["displayname"][0] || $user->Profile->email != $userData[0]["mail"][0]) {
$save = true;
}
} else {
$user = new sfGuardUser();
$save = true;
}
if ($save) {
$user->username = $data['username'];
$user->password = $data['password'];
$user->Profile->full_name = $userData[0]["displayname"][0];
$user->Profile->email = $userData[0]["mail"][0];
$user->save();
}
}
} catch (Exception $e) {
echo $e;
}
}
parent::executeSignin($request);
}
示例6: 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;
}
示例7: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->asfGuardUser !== null) {
if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
$affectedRows += $this->asfGuardUser->save($con);
}
$this->setsfGuardUser($this->asfGuardUser);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
} else {
$this->doUpdate($con);
}
$affectedRows += 1;
$this->resetModified();
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例8: populateFromFacebook
public function populateFromFacebook($doSave = true)
{
$fb = $this->getFacebook();
if (!($sfGuardUser = $this->getGuardUser())) {
if ($email = $fb->getEmail()) {
//-- Emails must be uniqe so start there
$sfGuardUser = Doctrine::getTable('sfGuardUser')->findOneByEmailAddress($email);
}
if (!$sfGuardUser && ($fb_uid = $fb->getId())) {
$sfGuardUser = Doctrine::getTable('sfGuardUser')->findOneByFacebookUid($fb_uid);
}
if (!$sfGuardUser) {
$sfGuardUser = new sfGuardUser();
}
}
//-- If it is in the session but not the guard User, add it to the guard user
if (!$sfGuardUser->getFacebookAuthCode() && $this->getAttribute('facebook_auth_code')) {
if (sfConfig::get('sf_logging_enabled')) {
sfContext::getInstance()->getLogger()->info('--- DEBUG --- FB AUTH CODE in session but not the guard User');
}
$sfGuardUser->setFacebookAuthCode($this->getAttribute('facebook_auth_code'));
}
$sfGuardUser->populateWithFacebook($fb);
if ($doSave) {
$sfGuardUser->save();
$this->signin($sfGuardUser);
}
//-- NOTE: The $sfGuardUser MAY NOT be saved yet!
$dispatcher = sfContext::getInstance()->getEventDispatcher();
$dispatcher->notify(new sfEvent($sfGuardUser, 'm14tFacebook.connect', array()));
return $sfGuardUser;
}
示例9: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->asfGuardUser !== null) {
if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
$affectedRows += $this->asfGuardUser->save($con);
}
$this->setsfGuardUser($this->asfGuardUser);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = sfGuardRememberKeyPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setNew(false);
} else {
$affectedRows += sfGuardRememberKeyPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例10: 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']));
}
示例11: 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();
}
示例12: getOrCreateUserByEmail
/**
* Gets or creates an sfGuardUser record by email
*
* The password and any other information is auto-generated in sfGuardUser
*/
public function getOrCreateUserByEmail($email)
{
$guardUser = $this->findOneByEmailAddress($email);
if (!$guardUser) {
$guardUser = new sfGuardUser();
$guardUser->username = $email;
$guardUser->save();
}
return $guardUser;
}
示例13: 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);
}
示例14: 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']));
}
示例15: executeCreateUser
public function executeCreateUser(sfWebRequest $request)
{
$data = $request->getPostParameter('data');
$user = new sfGuardUser();
$user->username = $data['username'];
$user->password = $data['password'];
$user->save();
$this->setTemplate('showUsers');
// $this->settings = Doctrine_Core::getTable('Settings')->findOneById(1);
// echo $this->getUser()->getGuardUser()->getUsername();
// $this->forward404Unless($this->settings);
}