Skip to content

Instantly share code, notes, and snippets.

@beatcode
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatcode/94dafc9f157a45d6406c to your computer and use it in GitHub Desktop.
Save beatcode/94dafc9f157a45d6406c to your computer and use it in GitHub Desktop.
Yii2 Google OpenId SuccessCallback
public function successCallback($client)
{
$attributes = $client->getUserAttributes();
if (isset($attributes)) {
$login = new LoginForm();
$login->username = $attributes['contact/email'];
$login->password = $attributes['contact/email'];
if ($login->login()) {
$this->Welcome();
} else {
/* Registrieren*/
$model = new \app\models\User;
$model->username = $attributes['contact/email'];
$model->password = sha1($attributes['contact/email']);
if ($model->save()) {
// automatisch einloggen nach der Anmeldung
$login = new LoginForm();
$login->username = $attributes['contact/email'];
$login->password = $attributes['contact/email'];
if ($login->login()) {
$this->Welcome();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment