Skip to content

Commit

Permalink
Centralize user file name lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Feb 10, 2016
1 parent c31f8b5 commit ca4d915
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ public function oauthTwitter()
}, 'oauth1');
}

/**
* Get the user identifier
*
* @param string $id The user ID on the service
*
* @return string
*/
private function getUsername($id)
{
$service_identifier = $this->action;
$user_identifier = $this->grav['inflector']->underscorize($id);

return strtolower("$service_identifier.$user_identifier");
}

/**
* Authenticate user.
*
Expand All @@ -276,14 +291,13 @@ public function oauthTwitter()
*/
protected function authenticateOAuth($username, $id, $email, $language = '')
{
$accountFile = $this->grav['inflector']->underscorize($username);
$user = User::load(strtolower("$accountFile.{$this->action}"));
if ($user->exists()) {
// Update username (hide OAuth from user)
$user->set('username', $username);
$password = md5($id);
$authenticated = $user->authenticate($password);
} else {
$user = User::load($this->getUsername($id));
/** @var User $user */
$user = $this->grav['user'];
// Check user rights
Expand Down

0 comments on commit ca4d915

Please sign in to comment.