Esempio n. 1
0
 public function onAuthSuccess($client)
 {
     $attributes = $client->getUserAttributes();
     $user = new User();
     foreach ($user->attributes() as $k) {
         if (isset($attributes[$k])) {
             $user->{$k} = $attributes[$k];
         }
     }
     $user->save();
     Yii::$app->user->login($user, Yii::$app->params['login_duration'] ?: 3600 * 24 * 30);
 }
Esempio n. 2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->save();
         return $user;
     }
     return null;
 }