本文整理汇总了PHP中sfGuardUser::fromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP sfGuardUser::fromArray方法的具体用法?PHP sfGuardUser::fromArray怎么用?PHP sfGuardUser::fromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfGuardUser
的用法示例。
在下文中一共展示了sfGuardUser::fromArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
}
}
示例2: executeSignup
/**
* Личные данные
*/
public function executeSignup()
{
$loginzaData = $this->getUser()->getAttribute('loginza.identity', false, 'loginza');
$this->forward404Unless($loginzaData);
$user = new sfGuardUser();
$user->fromArray($loginzaData);
$this->form = new sfGuardUserForm($user);
}
示例3: executeRegister
/**
* This is only example of what you can do.
*
* You should write your own method to handle the business logic required
* for your app and specify it in the sfCacophonyFilter in the filters.yml
*
* @param sfRequest $request
*/
public function executeRegister(sfRequest $request)
{
$provider = $request->getParameter('provider');
// You might want to get user info from the provider like this
$result = sfCacophonyOAuth::getMe($provider, $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $provider)));
// You might want to check if user exists like this:
if ($this->getUser()->isAuthenticated()) {
$sf_guard_user = $this->getUser()->getGuardUser();
} else {
$sf_guard_user = sfGuardUserTable::getInstance()->createQuery('u')->innerJoin('u.Tokens t')->where('t.providers_user_id = ? AND provider = ?', array($result['normalized']['providers_user_id'], $provider))->fetchOne();
}
if (!$sf_guard_user) {
// If user doesn't exist, you might want to add them, like this:
$token = new Token();
$token->fromArray($result['normalized']);
$accessToken = $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $provider));
$token->setContent($accessToken);
if (isset($accessToken['expires_at'])) {
$token->setExpiresAt($accessToken['expires_at']);
}
$token->setProvider($provider);
$sf_guard_user = new sfGuardUser();
$sf_guard_user->fromArray($result['normalized']);
$sf_guard_user['Tokens']->add($token);
$sf_guard_user->save();
$this->postCreateHook($sf_guard_user, $token);
} else {
$hasToken = false;
// Or if the user exists, update it's tokens
foreach ($sf_guard_user['Tokens'] as $token) {
if ($token['provider'] == $provider) {
$accessToken = $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $provider));
$token->setContent($accessToken);
if (isset($accessToken['expires_at'])) {
$token->setExpiresAt($accessToken['expires_at']);
}
$token->save();
$hasToken = true;
break;
}
}
// If it's a new token - add it
if (!$hasToken) {
$token = new Token();
$token->fromArray($result['normalized']);
$accessToken = $this->getUser()->getAttribute('accessToken', null, sprintf('sfCacophonyPlugin/%s', $provider));
$token->setContent($accessToken);
if (isset($accessToken['expires_at'])) {
$token->setExpiresAt($accessToken['expires_at']);
}
$token->setProvider($provider);
$sf_guard_user['Tokens']->add($token);
$sf_guard_user->save();
$this->postUpdateHook($sf_guard_user, $token);
}
}
// At the end, you might want to log in user like this:
$this->getUser()->signin($sf_guard_user);
// and redirect to homepage, or wherever you want
$this->redirect('@homepage');
}
示例4: filterForEngine
//.........这里部分代码省略.........
$endDay = '31';
}
$events = isset($options['byEventDateRange']) && $options['byEventDateRange'];
if ($events && $startYear === '0000') {
list($startYear, $startMonth, $startDay) = preg_split('/-/', date('Y-m-d'));
}
if ($events) {
// The event's start and end dates are part of the blog item table
$q .= ' inner join a_blog_item bi on bi.page_id = p.id ';
$q .= "and bi.start_date <= :end_date ";
$params['end_date'] = "{$endYear}-{$endMonth}-{$endDay}";
$q .= "and bi.end_date >= :start_date ";
$params['start_date'] = "{$startYear}-{$startMonth}-{$startDay}";
}
$hasAuthor = isset($options['author']) && strlen($options['author']);
// If we're filtering events by date range then the join with the blog item has
// already been added and we don't have to do it again to get author information
if (!$events) {
$q .= 'left join a_blog_item bi on bi.page_id = p.id ';
}
// Now join with sf_guard_user so we can get usernames & full names and also
// limit to a specific username where desired (we do that with a where clause
// at the end so we can exempt the query for authors from it easily)
$q .= 'left join sf_guard_user au on bi.author_id = au.id ';
// Criteria for the pages themselves (only pages for the right engine)
$q .= 'where p.slug like :slug_pattern ';
// We often filter posts (not events) by a range of publication dates
if (isset($options['byPublishedAt']) && $options['byPublishedAt']) {
// Include time portion - published_at is a full timestamp
$q .= "and p.published_at <= :p_end_date ";
$params['p_end_date'] = "{$endYear}-{$endMonth}-{$endDay} 23:59:59";
$q .= "and p.published_at >= :p_start_date ";
$params['p_start_date'] = "{$startYear}-{$startMonth}-{$startDay} 00:00:00";
}
// In no case do we show unpublished material
$q .= 'and p.published_at <= NOW() and (p.archived IS NULL or p.archived IS FALSE) ';
// ... But only those matching the Lucene search that already gave us specific IDs.
// NOTE: if pageIds is not null and is empty, NOTHING should be returned
// (someone searched for something that doesn't appear in the system)
if (isset($pageIds)) {
if (count($pageIds)) {
$q .= 'and p.id in :pageIds ';
$params['pageIds'] = $pageIds;
} else {
$q .= 'and 0 <> 0 ';
}
}
if ($alphaSort) {
$pagesOrderBy = 's.value asc';
} elseif ($events) {
$pagesOrderBy = 'bi.start_date asc, bi.start_time asc';
} else {
// Oops: blog presentation is typically descending, not ascending
$pagesOrderBy = 'p.published_at desc';
}
// Separate queries, but quite fast because we're not bogged down in Doctrineland
$c_q = $q;
$t_q = $q;
$p_q = $q;
$a_q = $q;
// We are filtering by this specific category
if ($hasCategorySlug) {
// Limit tags and pages by this specific category, but don't limit
// categories by it, otherwise we can't present a choice of categories
// meeting the other criteria
$p_q .= "and c.slug = :category_slug ";
$t_q .= "and c.slug = :category_slug ";
$a_q .= "and c.slug = :category_slug ";
$params['category_slug'] = $options['categorySlug'];
}
if ($hasTag) {
// Limit pages and categories by this specific tag, but don't limit
// tags by it, otherwise we can't present a choice of tags
// meeting the other criteria
$p_q .= 'and t.name = :tag_name ';
$c_q .= 'and t.name = :tag_name ';
$a_q .= 'and t.name = :tag_name ';
$params['tag_name'] = $options['tag'];
}
if ($hasAuthor) {
$p_q .= 'and au.username = :username ';
$c_q .= 'and au.username = :username ';
$t_q .= 'and au.username = :username ';
$params['username'] = $options['author'];
}
// In the cases where we are looking for categories or tags, be sure to
// discard the null rows from the LEFT JOINs. This is simpler than
// determining when to switch them to INNER JOINs
// Hydrate real Doctrine objects for authors. It ensures we can stringify them consistently,
// and the number of authors tends to have reasonable constraints
$authorsInfo = $mysql->query('select distinct au.username, au.id, au.first_name, au.last_name ' . $a_q . ' and au.id is not null order by au.last_name asc, au.first_name asc', $params);
$authors = array();
foreach ($authorsInfo as $authorInfo) {
$author = new sfGuardUser();
$author->fromArray($authorInfo);
$authors[] = $author;
}
$result = array('categoriesInfo' => $mysql->query('select distinct c.slug, c.name ' . $c_q . 'and c.slug is not null order by c.name', $params), 'tagsByName' => $mysql->query('select t.name, count(distinct p.id) as t_count ' . $t_q . 'and t.name is not null group by t.name order by t.name', $params), 'tagsByPopularity' => $mysql->query('select t.name, count(distinct p.id) as t_count ' . $t_q . 'and t.name is not null group by t.name order by t_count desc limit 10', $params), 'pageIds' => $mysql->queryScalar('select distinct p.id ' . $p_q . ' order by ' . $pagesOrderBy, $params), 'authors' => $authors);
return $result;
}