public function storeInvite()
 {
     try {
         $this->userRepo->validator();
         $inputs = $this->request->all();
         $user = User::where('email', $inputs['email'])->first();
         if (!empty($user)) {
             $user->remember_token = str_random(30);
             $user->save();
             $this->sendEmailInvite($user->id);
             return $this->redirect->to('invite')->with('message', Lang::get('general.invitesucessfullresend'));
         } else {
             $user = new User();
             $user->name = explode("@", $inputs['email'])[0];
             $user->email = $inputs['email'];
             $user->pending_company_id = Auth::user()['company_id'];
             $user->remember_token = str_random(30);
             $user->save();
             $user->assignRole('staff');
             $user->createContact($user->name, $user->company_id);
             $this->sendEmailInvite($user->id);
             return $this->redirect->to('invite')->with('message', Lang::get('general.succefullcreate', ['table' => Lang::get('general.InviteUser')]));
         }
     } catch (ValidatorException $e) {
         return $this->redirect->back()->withInput()->with('errors', $e->getMessageBag());
     }
 }
 public function checkUserExists($email)
 {
     $user = User::where('email', $email)->first();
     if (!empty($user)) {
         return true;
     } else {
         return false;
     }
 }
 public function testInviteExistingUser()
 {
     $lastUserId = User::all()->last()['id'];
     $lastRememberToken = User::where('email', '*****@*****.**')->first()['remember_token'];
     $this->visit('/')->see('invite user');
     $this->visit('/invite')->type('*****@*****.**', 'email')->press('Enviar')->seePageIs('/invite')->see('reenviado com sucesso');
     $this->assertEquals($lastUserId, User::all()->last()['id']);
     $this->assertNotEquals($lastRememberToken, User::all()->last()['remember_token']);
 }
Esempio n. 4
0
 public function getUser($search)
 {
     $reult = array();
     $user = User::where('name', 'LIKE', '%' . $search . '%')->orWhere('first_name', 'LIKE', '%' . $search . '%')->orWhere('last_name', 'LIKE', '%' . $search . '%')->get();
     foreach ($user as $data) {
         $reult[] = array('id' => $data->id, 'name' => $data->name . ' ' . $data->first_name . ' ' . $data->last_name);
     }
     return $reult;
 }
 private function findOrCreateUser($user)
 {
     $authUser = User::where('email', $user->email)->first();
     if ($authUser) {
         return $authUser;
     }
     $newUser = new User(['name' => isset($user->name) ? $user->name : $user->nickname, 'email' => $user->email, 'contact_id' => 1]);
     $newUser->save();
     $newUser->setUp();
     return $newUser;
 }
 /**
  * Boot the authentication services for the application.
  *
  * @return void
  */
 public function boot()
 {
     // Here you may define how you wish users to be authenticated for your Lumen
     // application. The callback which receives the incoming request instance
     // should return either a User instance or null. You're free to obtain
     // the User instance via an API token or any other method necessary.
     Auth::viaRequest('api', function (Request $request) {
         $authorization_header = explode(' ', $request->header('Authorization'));
         if (count($authorization_header) != 2 || strpos($authorization_header[0], 'Bearer')) {
             throw new Exception('Authorization header not set or invalid.');
         }
         $user = User::where('api_token', $authorization_header[1])->first();
         if (is_null($user)) {
             throw new Exception('Invalid access token.');
         }
         return $user;
     });
     // Event Authorization
     Gate::define('create-event', function (User $user) {
         return $user->hasPermission('create-event');
     });
     Gate::define('update-event', function (User $user, Event $event) {
         return $user->hasPermission('update-event') && $user->id === $event->user_id;
     });
     Gate::define('delete-event', function (User $user, Event $event) {
         return $user->hasPermission('delete-event') && $user->id === $event->user_id;
     });
     Gate::define('view-event', function (User $user, Event $event) {
         return $user->hasPermission('view-event');
     });
     Gate::define('list-event', function (User $user) {
         return $user->hasPermission('list-event');
     });
     // User Authorization
     Gate::define('list-user', function (User $user) {
         return $user->hasPermission('list-user');
     });
     Gate::define('view-user', function (User $user, User $user_check) {
         return $user->hasPermission('view-user');
     });
     // User Location Authorization
     Gate::define('list-user-location', function (User $user) {
         return $user->hasPermission('list-user-location');
     });
     Gate::define('update-user-location', function (User $user, User $user_check) {
         return $user->hasPermission('update-user-location') && $user->id === $user_check->id;
     });
 }
 public function createAccount(Request $request, $token)
 {
     try {
         $userPending = User::where('remember_token', $token)->first();
         $inputs = $request->all();
         if (empty($userPending) || $userPending->email != $inputs['email']) {
             return redirect('/create-account/' . $token)->with('error', Lang::get("general.usernotfound"));
         } elseif (strlen($inputs['password']) < 6) {
             return redirect('/create-account/' . $token)->with('error', Lang::get("general.invalidpassword"));
         }
         $userPending->password = Hash::make($inputs['password']);
         $userPending->pending_company_id = null;
         $userPending->save();
         Auth::login($userPending, true);
         return redirect('/');
     } catch (ValidatorException $e) {
         return $this->redirect->back()->withInput()->with('errors', $e->getMessageBag());
     }
 }
Esempio n. 8
0
 public function getCursante()
 {
     $cursante = User::where('role', 'cursante');
     return $cursante;
 }
Esempio n. 9
0
 /**
  * @return string
  */
 public function handleProviderCallback()
 {
     $socialize_user = Socialite::with('facebook')->user();
     $provider_id = $socialize_user->getId();
     // unique facebook user id
     $user = User::where('provider_id', $provider_id)->first();
     // register (if no user)
     if (!$user) {
         $user = new User();
         $user->name = $socialize_user->getName();
         $user->email = $socialize_user->getEmail();
         $user->active = 1;
         $user->confirmation_token = null;
         $user->provider_id = $provider_id;
         $user->save();
     }
     // login
     Auth::loginUsingId($user->id);
     return redirect('/');
     //        return '<h2>'.$user->getName().'<h2>' . '<img src="'.$user->getAvatar().'">';
     //        exit();
 }