示例#1
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     Email::sendWelcomeEmail($user);
     return $user;
 }
示例#2
0
 /**
  * Return user if exists; create and create if not
  *
  * @param $facebookUser
  *
  * @return User
  */
 private function findOrCreateUser($facebookUser)
 {
     $user = User::where('sns_acc_id', $facebookUser->id)->first();
     //check if the facebook id already exists
     if ($user) {
         return $user;
     }
     //get the profile picture contents
     /*$contents = file_get_contents('http://graph.facebook.com/' . $facebookUser->id . '/picture?type=large&redirect=false');
       $contents = json_decode($contents, true);*/
     //check if the email exists, update the facebook id
     if ($user = User::where('email', $facebookUser->email)->first()) {
         User::whereId($user->id)->update(['sns_acc_id' => $facebookUser->id]);
         $user->userDetail->update(['gender' => strtoupper(substr($facebookUser['gender'], 0, 1)), 'first_name' => $facebookUser['first_name'], 'last_name' => $facebookUser['last_name'], 'confirmed' => $facebookUser['verified']]);
         /*if (empty($user->userDetail->avatar->location)) {
               $user->userDetail->avatar->update(['location' => $contents['data']['url']]);
           }*/
         return $user;
     }
     //continue adding a new user
     $name = $this->generateUsername($facebookUser->name);
     $user_id = User::insertGetId(['username' => $name, 'slug' => str_slug($name), 'email' => $facebookUser->email, 'sns_acc_id' => $facebookUser->id]);
     $details_id = UserDetail::insertGetId(['user_id' => $user_id, 'first_name' => $facebookUser['first_name'], 'last_name' => $facebookUser['last_name'], 'gender' => strtoupper(substr($facebookUser['gender'], 0, 1)), 'confirmed' => $facebookUser['verified']]);
     //UserAvatar::insert(['user_detail_id' => $details_id, 'location' => $contents['data']['url']]);
     $user = User::find($user_id);
     Email::sendWelcomeEmail($user);
     return $user;
 }