Beispiel #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('UlibierPermission')->delete();
     DB::table('Ulibier')->delete();
     DB::table('UlibierProfile')->delete();
     \App\UlibierPermission::create(array('permission_name' => 'admin'));
     \App\UlibierPermission::create(array('permission_name' => 'user'));
     $csv = new CSV();
     $ulibiers = $csv->fromFile(dirname(__FILE__) . '/csv/Ulibier.csv')->toArray();
     $profiles = $csv->fromFile(dirname(__FILE__) . '/csv/UlibierProfile.csv')->toArray();
     for ($i = 0; $i < count($ulibiers); $i++) {
         $k = $ulibiers[$i];
         $v = $profiles[$i];
         $ulibier = new Ulibier();
         $ulibier->fill($k)->setAttribute('password', bcrypt($k['password']))->save();
         $ulibier->profile()->create($v);
     }
 }
Beispiel #2
0
 /**
  * Redirect to Facebook/Google OAuth login authentication
  * Kiểm tra xem Email gắn liền với tài khoản mạng xã hội đã được đăng ký
  *  trong CSDL của Ulibi hay chưa
  * Nếu chưa, redirect tới trang đăng ký Ulibier (yêu cầu sử dụng username, điền sắn
  *  một số field đã có sẵn như email, avatar, ...)
  * Nếu đã có, redirect tới postLogin luôn
  * @param string $provider
  * @return Response
  */
 public function socialAuthCallback($provider)
 {
     /** @var \Laravel\Socialite\AbstractUser $p */
     $p = Socialite::with($provider);
     switch ($provider) {
         case 'facebook':
             $p->fields($this->facebookRequiredScopes());
             break;
     }
     if ($user = Socialite::with($provider)->user()) {
         /** @var \App\Ulibier $dbUser */
         $dbUser = Ulibier::whereEmail($user->email)->first();
         if ($dbUser === null) {
             $dbUser = UlibierPermission::getUsers()->members()->create(['username' => $user->id, 'firstname' => $this->getSocialField($provider, $user, 'firstName'), 'lastname' => $this->getSocialField($provider, $user, 'lastName'), 'email' => $this->getSocialField($provider, $user, 'email'), 'password' => bcrypt('123456'), 'registered_with_social_account' => true]);
             $dbUser->profile()->create(['sex' => $this->getSocialField($provider, $user, 'gender'), 'birthday' => new DateTime($this->getSocialField($provider, $user, 'birthday')), 'phonenumber' => '+841667578431']);
             $dbUser->avatar_url = $this->getSocialField($provider, $user, 'avatar');
         }
         return \View::make('pages.auth.redirect', ['form' => ['method' => 'POST', 'action' => '/ulibier/login', 'fields' => ['email' => $dbUser->email, 'via' => $provider]]]);
     } else {
         return 'something went wrong';
     }
 }