diff --git a/behaviors/ManyToManyBehavior.php b/behaviors/ManyToManyBehavior.php new file mode 100755 index 0000000..26480d2 --- /dev/null +++ b/behaviors/ManyToManyBehavior.php @@ -0,0 +1,33 @@ +owner; + + $owner->unlinkAll($name, true); + + foreach ($models as $model) { + $owner->link($name, $model, $extraColumns); + } + } + } \ No newline at end of file diff --git a/models/Customer.php b/models/Customer.php index d602459..6f8512a 100755 --- a/models/Customer.php +++ b/models/Customer.php @@ -97,6 +97,7 @@ ], 'unique' ], + [['social_type', 'social_id'], 'safe'], [ [ 'gender', @@ -171,6 +172,9 @@ ] ); } + public function loginSocial(){ + return Yii::$app->user->login($this, 3600 * 24 * 30); + } /** * Get full name @@ -215,6 +219,28 @@ { return false; } - - + + public static function Social($user, $type) + { + $customer = static::findOne( + [ + 'status' => self::STATUS_ACTIVE, + 'email'=> $user['email'], + 'social_type' => $type + ] + ); + if ($customer == null){ + $customer = new Customer(); + $customer->email = $user['email']; + $customer->username = (isset($user['name'])) ? $user['name'] : $user['email']; + $customer->social_id = $user['id']; + $customer->social_type = $type; + $customer->setPassword($user['id']); + $customer->generateAuthKey(); + $customer->status = self::STATUS_ACTIVE; + return $customer->save() ? $customer : null; + }else{ + return $customer; + } + } } -- libgit2 0.21.4