Skip to content

Commit

Permalink
- ADD: OpenID creation for existing users
Browse files Browse the repository at this point in the history
  • Loading branch information
Harald Kirschner committed Oct 1, 2008
1 parent c1fdabd commit 9546a66
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion www/app/lib/user/OurUser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function login(UserModel $user)
$this->setAttribute('login_at', new DateTime($this->user['login_at']), 'our.user');

$this->user['login_at'] = date('Y-m-d H:i:s');
$this->user->save();
$this->user->trySave();

$this->setAttribute('id', $this->user['id'], 'our.user');

Expand Down
12 changes: 12 additions & 0 deletions www/app/models/UserModelTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public function findOneByOpenId($url)
return $q->fetchOne();
}

public function findOneEmail($email)
{
$q = new Doctrine_Query();

$q->from('UserModel u')
->select('u.*, i.*')
->innerJoin('u.user_ids i')
->where('u.email = ?', array($email) );

return $q->fetchOne();
}

public function findOneByToken($token)
{
$q = new Doctrine_Query();
Expand Down
22 changes: 18 additions & 4 deletions www/app/modules/Account/actions/LoginResponseAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ public function executeRead(AgaviRequestDataHolder $rd)

if (!$user)
{
$user = $this->context->getModel('User');

$user_id = new UserIdModel();
$user_id['url'] = $url;
if (isset($params['openid_sreg_email']) )
{
$user = $table->findOneEmail($params['openid_sreg_email']);
}
if (!$user)
{
$user = $this->context->getModel('User');
}

$user_id = new UserIdModel();
$user_id['url'] = $url;

$user['user_ids'][0] = $user_id;
}
Expand Down Expand Up @@ -75,6 +82,13 @@ public function executeRead(AgaviRequestDataHolder $rd)
if (isset($params['openid_sreg_timezone']) )
{
$user['timezone'] = $params['openid_sreg_timezone'];
}

if (!$user->isValid() )
{
$this->us->addFlash('Could not update the user. If you are already registered, use your original OpenID or contact a moderator.', 'error');

return $this->handleError($rd);
}

if (!$user->exists() )
Expand Down

0 comments on commit 9546a66

Please sign in to comment.