Esempio n. 1
0
 public function facebookCallback()
 {
     try {
         $facebook = Socialite::driver('facebook')->scopes(['email'])->user();
         // 確認使用者有提供 Email
         if (null === $facebook->getEmail()) {
             throw new OAuthException();
         }
         // 如果 Email 不存在,創見帳號,如 Email 已存在,則略過此步驟
         if (null === ($account = Account::where('email', '=', $facebook->getEmail())->first(['id']))) {
             $account = Account::create(['email' => $facebook->getEmail(), 'password' => str_random(32)]);
             if (!$account->exists) {
                 throw new ModelNotFoundException();
             }
             $account->load(['user'])->getRelation('user')->update(['nickname' => $facebook->getName() . '@facebook']);
         }
         \Auth::loginUsingId($account->getAttribute('id'), true);
         return redirect()->route('home');
     } catch (ClientException $e) {
         $data = ['您似乎並未允許本網站存取您的資料', false];
     } catch (InvalidStateException $e) {
         $data = ['似乎出了點狀況,請嘗試重新登入', false];
     } catch (ModelNotFoundException $e) {
         $data = ['網站似乎出了點狀況,請稍候再嘗試', false];
     } catch (OAuthException $e) {
         $data = ['您似乎並未允許本網站存取您的信箱', true];
     } catch (\Exception $e) {
         $data = ['網站似乎出了點狀況,請稍候再嘗試', false];
         \Log::error('Non-catch exception.', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
     }
     return view('errors.oauthFailed', ['message' => $data[0], 'invalidEmail' => $data[1]]);
 }
Esempio n. 2
0
 /**
  * Handle a registration request for the application.
  *
  * @param Requests\RegisterRequest $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function register(Requests\RegisterRequest $request)
 {
     $account = Account::create($request->only(['email', 'password']));
     if (!$account->exists) {
         return response()->json(['message' => ['註冊失敗,請稍候再嘗試']], 500);
     }
     Auth::loginUsingId($account->getAttribute('id'), true);
     event(new Register($account));
     return response()->json();
 }
Esempio n. 3
0
 protected function make()
 {
     $this->expireOldTokens($this->category, $this->account->getAttribute('id'));
     $verify = Verify::create(['token' => str_random(100), 'category_id' => $this->category, 'account_id' => $this->account->getAttribute('id'), 'created_at' => Carbon::now()]);
     $this->data = ['token' => $verify->getAttribute('token')];
 }
Esempio n. 4
0
 /**
  * Update user's profile picture path;
  *
  * @param \App\Ccu\Image\Image $image
  */
 protected function updateProfilePicture($image)
 {
     $oldId = $this->account->getRelation('user')->getAttribute('profile_picture_id');
     $this->account->getRelation('user')->update(['profile_picture_id' => $image->getAttribute('id')]);
     $this->deleteOldProfilePicture($oldId);
 }
Esempio n. 5
0
 /**
  * @param string $categoryName
  * @param \App\Ccu\Member\Account $account
  * @param string $action
  * @param mixed|null $detail
  * @return Event
  */
 public static function _create($categoryName, $account, $action, $detail = null)
 {
     return static::create(['category_id' => Category::getCategories($categoryName, true), 'account_id' => $account->getAttribute('id'), 'action' => $action, 'detail' => $detail]);
 }