Last active
August 29, 2015 14:12
-
-
Save beatcode/94dafc9f157a45d6406c to your computer and use it in GitHub Desktop.
Yii2 Google OpenId SuccessCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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