Ejemplo n.º 1
0
 /**
  * @param array $params
  * @param null $request
  * @return array
  */
 private function getParamsTwig($params = array(), $request = null)
 {
     if ($this->loginUrlOrGraphUser instanceof GraphUser) {
         $graphUser = $this->loginUrlOrGraphUser;
         // Create and update user
         $user = User::firstOrCreate(['facebook_id' => $graphUser->getId()]);
         if (!$user instanceof User) {
             $user = new User();
             $user->facebook_id = $graphUser->getId();
         }
         $user->gender = $graphUser->getGender() == 'male' ? 'M.' : 'Mme';
         $user->email = $graphUser->getEmail();
         $user->first_name = $graphUser->getFirstName();
         $user->last_name = $graphUser->getLastName();
         $user->save();
     }
     $configFacebook = $this->config['facebook'];
     return array_merge(['APP_ID' => $configFacebook['id'], 'URL_WEB_APP' => $configFacebook['url'], 'user' => isset($graphUser) ? $graphUser : null], $params);
 }
Ejemplo n.º 2
0
 public function loginPost(Request $request)
 {
     $username = $request->input('username');
     $request->session()->set('username', $username);
     $password = $request->input('password');
     $returnTo = url($request->input('return_to', ''));
     // Try to log in.
     if (Auth::attempt(['username' => $username, 'password' => $password])) {
         $this->alert('success', 'You are now logged in.', true);
         return redirect($returnTo);
     }
     // If that fails, try Adldap.
     $adldapConfig = config('adldap');
     if ($adldapConfig['enabled']) {
         $adldap = new \Adldap\Adldap($adldapConfig);
         if (empty($adldap->getConfiguration()->getAdminUsername())) {
             $adldap->getConfiguration()->setAdminUsername($username);
             $adldap->getConfiguration()->setAdminPassword($password);
         }
         try {
             $adldap->authenticate($username, $password);
             $user = User::firstOrCreate(['username' => $username]);
             $ldapUser = $adldap->users()->find($username);
             if ($ldapUser instanceof \Adldap\Models\User) {
                 $user->name = $ldapUser->getDisplayName();
                 $user->email = $ldapUser->getEmail();
                 $user->save();
                 Auth::login($user);
                 $this->alert('success', 'You are now logged in.', true);
                 return redirect($returnTo);
             }
         } catch (\Adldap\Exceptions\AdldapException $ex) {
             // Invalid credentials.
         }
     }
     // If we're still here, authentication has failed.
     $this->alert('warning', 'Athentication failed.');
     return redirect()->back()->withInput();
 }