/**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
         $query->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
         flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     if ($role->users()->detach($user)) {
         flash()->success('Success!', 'Successfully removed user.');
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     flash()->error('Error!', 'There was an issue removing this user. Please try again.');
     return redirect()->route('admin.roles.show', [$roleId]);
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Role::whereName('administrator')->delete();
     // Delete Welcome Permission
     Permission::whereName('admin.welcome.index')->delete();
     // Delete User Permissions
     Permission::whereName('admin.users.index')->delete();
     Permission::whereName('admin.users.create')->delete();
     Permission::whereName('admin.users.edit')->delete();
     Permission::whereName('admin.users.show')->delete();
     Permission::whereName('admin.users.destroy')->delete();
     // Delete Role Permissions
     Permission::whereName('admin.roles.index')->delete();
     Permission::whereName('admin.roles.create')->delete();
     Permission::whereName('admin.roles.edit')->delete();
     Permission::whereName('admin.roles.show')->delete();
     Permission::whereName('admin.roles.destroy')->delete();
     // Delete Permission Permissions
     Permission::whereName('admin.permissions.index')->delete();
     Permission::whereName('admin.permissions.create')->delete();
     Permission::whereName('admin.permissions.edit')->delete();
     Permission::whereName('admin.permissions.show')->delete();
     Permission::whereName('admin.permissions.destroy')->delete();
     // Delete User Permission Permissions
     Permission::whereName('admin.users.permissions.store')->delete();
     Permission::whereName('admin.users.permissions.destroy')->delete();
     // Delete Role Permission Permissions
     Permission::whereName('admin.roles.permissions.store')->delete();
     Permission::whereName('admin.roles.permissions.destroy')->delete();
     // Delete Role User Permissions
     Permission::whereName('admin.roles.users.destroy')->delete();
     Permission::whereName('admin.roles.users.destroy')->delete();
 }
 /**
  * Handle an incoming request.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     // Retrieve the administrator role.
     $administrator = $this->role->whereName(Role::getAdministratorName())->first();
     // Retrieve the count of users.
     $users = $this->user->count();
     if ($administrator instanceof Role && !$request->user() && $users === 0) {
         // If the administrator role has been created, no user
         // is logged in, and no users exist,
         // we'll allow the setup request.
         return $next($request);
     }
     // If the administrator role hasn't already been created,
     // we'll throw an Unauthorized Exception.
     throw new HttpException(403, 'Unauthorized.');
 }
 public function store(LoginAlternativeRequest $request)
 {
     try {
         $credentials['password'] = $request->input('idfacebook');
         $credentials['email'] = $request->input('email');
         $data['tokendevice'] = $request->input('tokendevice');
         $data['typedevice'] = $request->input('typedevice');
         $datauser = User::whereEmail($credentials['email'])->get()->first();
         if (isset($datauser)) {
             if ($datauser->flagactive == User::STATE_USER_INACTIVE) {
                 $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], 'usuario Inactivo');
                 $this->_responseWS->response();
             }
         } else {
             $data = $request->all();
             $data['password'] = Hash::make($data['idfacebook']);
             $obj = User::create($data);
             $datosRol = Role::whereName('user_app')->first();
             $daoUserRol['role_id'] = (int) $datosRol->id;
             $daoUserRol['user_id'] = $obj->id;
             RoleUser::create($daoUserRol);
         }
         $this->login($request->all());
     } catch (\Exception $exc) {
         dd($exc->getMessage());
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], '');
     }
     $this->_responseWS->response();
 }
Exemple #5
0
 public function postForm(FormAdminRequest $request)
 {
     try {
         $dataAdmin = $request->all();
         $password = $request->get('password', null);
         if (isset($dataAdmin['id']) && $dataAdmin['id'] != '') {
             $data = $request->except(array('password'));
             $runtime = User::find($dataAdmin['id']);
             $runtime->fill($data);
             $runtime->password = $runtime->password;
             if (!empty($password)) {
                 $runtime->password = Hash::make($password);
             }
             $runtime->save();
             $msg = 'Usuario Editado!';
         } else {
             $role = Role::whereName(User::ROL_CONTENIDO_ADMIN)->first();
             $dataAdmin['password'] = Hash::make($password);
             $NewUser = User::create($dataAdmin);
             $msg = 'Usuario Guardado!';
             RoleUser::create(['user_id' => $NewUser->id, 'role_id' => $role->id]);
         }
         return redirect(action('Admin\\AdminController@getIndex'))->with('messageSuccess', $msg);
     } catch (Exception $exc) {
         dd($exc->getMessage());
     }
 }
 public function revokeRole($role)
 {
     if (is_string($role)) {
         return $this->roles()->detach(Role::whereName($role)->firstOrFail());
     }
     return $this->roles()->detach($role);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param AdduserRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(AdduserRequest $request)
 {
     //        $input = $request->all();                               // get all data
     //        $input['confirmed'] = 1;                                // set confirmed to 1
     //        $input['password'] = Hash::make($input['password']);    // hash password
     //
     //        $user       =   User::create($input);                   // save above details
     $user = User::create(['first_name' => $request->first_name, 'last_name' => $request->last_name, 'email' => $request->email, 'confirmed' => 1, 'password' => Hash::make($request->password)]);
     //        $profile    =   $user->profile()->save(new Profile);    // also create new profile
     //        $profile->apartment_id  =   Auth::user()->profile->defaultApartment; // get current defaultApartment
     //        $profile->save();                                       // save details on profile
     $profile = Profile::create(['user_id' => $user->id, 'apartment_id' => Auth::user()->profile->defaultApartment]);
     dd(Auth::user()->profile->defaultApartment);
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
     //Assign Role
     $block_no = $request->blockno;
     // get block_no from profileform
     $floor_no = $request->floorno;
     // get floor_no from profileform
     $profile->apartments()->attach($profile->defaultApartment, ['approved' => '1', 'block_no' => $block_no, 'floor_no' => $floor_no]);
     // attach this profile with default apartment, with approved = 1, and block_no, floor_no according to profileform in apartment_profile pivot table.
     Crm_account::create(['account' => $user->first_name . $user->last_name, 'fname' => $user->first_name, 'lname' => $user->last_name, 'company' => 'Company Name', 'email' => $user->email, 'address' => 'Current Address', 'city' => 'Nagpur', 'state' => 'Maharashtra', 'zip' => '440012', 'country' => 'India']);
     return redirect()->back()->withMessage('User has been Added')->withStatus('success');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = Role::whereName(Role::getAdministratorName())->firstOrFail();
     Permission::all()->map(function ($permission) use($role) {
         $role->grant($permission);
     });
 }
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Admin', 'last_name' => 'Terra', 'email' => '*****@*****.**', 'password' => Hash::make('password')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'password' => Hash::make('password')));
     $user->assignRole($userRole);
 }
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'password' => Hash::make('password')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Jane', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'password' => Hash::make('janesPassword')));
     $user->assignRole($userRole);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('customer')->first();
     $user = User::create(array('name' => 'hendri', 'email' => '*****@*****.**', 'password' => Hash::make('password')));
     $user->assignRole($adminRole);
     $user = User::create(array('name' => 'han', 'email' => '*****@*****.**', 'password' => Hash::make('admin123')));
     $user->assignRole($userRole);
 }
 /**
  * @param $role mixed
  * @return $this|Model
  */
 public function removeRole($role)
 {
     if (is_string($role)) {
         return $this->roles()->detach(Role::whereName($role)->firstOrfail());
     }
     if ($role instanceof Role) {
         return $this->roles()->detach($role);
     }
     return $this;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $author = factory(\App\Models\User::class)->create(['name' => 'Author da Silva', 'email' => '*****@*****.**', 'password' => bcrypt(123456)]);
     $author2 = factory(\App\Models\User::class)->create(['name' => 'Author 2 da Silva', 'email' => '*****@*****.**', 'password' => bcrypt(123456)]);
     factory(\App\Models\Book::class, 2)->create(['user_id' => $author->id]);
     factory(\App\Models\Book::class, 2)->create(['user_id' => $author2->id]);
     $book_manage = factory(\App\Models\Permission::class)->create(['name' => 'book_manage_all', 'description' => 'Can Manage All books']);
     $roleManager = \App\Models\Role::whereName('Manager')->first();
     $roleManager->addPermission($book_manage);
 }
Exemple #14
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Administrator', 'last_name' => 'Account', 'email' => '*****@*****.**', 'password' => Hash::make('123456')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Some', 'last_name' => 'User', 'email' => '*****@*****.**', 'password' => Hash::make('weeeeee')));
     $user->assignRole($userRole);
 }
Exemple #15
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::find(1);
     $user->assignRole($adminRole);
     $user = User::find(2);
     $user->assignRole($userRole);
 }
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Hector Raul', 'last_name' => 'Zapana Condori', 'email' => '*****@*****.**', 'password' => Hash::make('123456')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Wilber', 'last_name' => 'Zapana Condori', 'email' => '*****@*****.**', 'password' => Hash::make('123456')));
     $user->assignRole($userRole);
 }
Exemple #17
0
 public function run()
 {
     DB::statement("SET foreign_key_checks = 0");
     User::truncate();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Suchay', 'last_name' => 'Janbandhu', 'email' => '*****@*****.**', 'password' => Hash::make('password'), 'confirmed' => 1));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Viplove', 'last_name' => 'Wahane', 'email' => '*****@*****.**', 'password' => Hash::make('password'), 'confirmed' => 1));
     $user->assignRole($userRole);
 }
Exemple #18
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name');
     $this->user->email = $this->request->input('email');
     $this->user->password = bcrypt($this->request->input('password'));
     $role = Role::whereName(Role::getAdministratorName())->firstOrFail();
     if ($this->user->save()) {
         $this->user->assignRole($role);
         return true;
     }
     return false;
 }
 public function postRegister()
 {
     $user = new User();
     $user->name = Input::get('name');
     $user->email = Input::get('email');
     $user->password = Hash::make(Input::get('password'));
     $user->save();
     //Assign Role
     $role = Role::whereName('customer')->first();
     $user->assignRole($role);
     return redirect('auth/login');
 }
 public function register($data)
 {
     $user = new User();
     $user->email = $data['email'];
     $user->first_name = ucfirst($data['first_name']);
     $user->last_name = ucfirst($data['last_name']);
     $user->password = Hash::make($data['password']);
     $user->save();
     //Assign Role
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
 }
Exemple #21
0
 /**
  * Attaches roles depending on the users active directory group.
  *
  * @param User       $user
  * @param AdldapUser $adldapUser
  *
  * @return void
  */
 protected function handleLdapUserWasAuthenticated(User $user, AdldapUser $adldapUser)
 {
     if ($adldapUser->inGroup('Help Desk')) {
         $admin = Role::whereName(Role::getAdministratorName())->first();
         // If we have the administrator role and the user isn't
         // already a member, then we'll assign them the role.
         if ($admin instanceof Role && !$user->hasRole($admin)) {
             $user->assignRole($admin);
         }
     }
     $user->from_ad = true;
     $user->save();
 }
Exemple #22
0
 public function store(RegisterUserRequest $request)
 {
     try {
         $data = $request->all();
         $data['password'] = Hash::make($data['idfacebook']);
         $obj = User::create($data);
         $datosRol = Role::whereName('user_app')->first();
         $daoUserRol['role_id'] = (int) $datosRol->id;
         $daoUserRol['user_id'] = $obj->id;
         RoleUser::create($daoUserRol);
         $this->_responseWS->setDataResponse(Response::HTTP_CREATED, [['id' => $obj->id]], [], 'ok');
     } catch (\Exception $exc) {
         dd($exc->getMessage());
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, array(), array(), '');
     }
     $this->_responseWS->response();
 }
Exemple #23
0
 public function register($data)
 {
     $confirmation_code = sha1(mt_rand());
     $user = new User();
     $user->email = $data['email'];
     $user->first_name = ucfirst($data['first_name']);
     $user->last_name = ucfirst($data['last_name']);
     $user->password = Hash::make($data['password']);
     $user->confirmation_code = $confirmation_code;
     $user->save();
     //Save Profile
     $user->profile()->save(new Profile());
     //Assign Role
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
     //Data
     $data = ['first_name' => $user->first_name, 'confirmation_code' => $confirmation_code, 'subject' => 'Please Verify Email Address', 'email' => $user->email];
     //Send Verification Email
     //        $this->userMailer->verify($user->email, $data);
 }
 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @throws CannotRemoveRolesException
  *
  * @return int
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) {
         $builder->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role from this user. You're the only administrator.");
     }
     return $role->users()->detach($user);
 }
Exemple #25
0
 /**
  * Execute the job.
  *
  * @throws CannotRemoveRolesException
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name', $this->user->name);
     $this->user->email = $this->request->input('email');
     $password = $this->request->input('password');
     // Verify before changing the users password that it's not empty.
     if (!empty($password)) {
         // If the user doesn't have a set password mutator,
         // we'll encrypt the password.
         if (!$this->user->hasSetMutator('password')) {
             $password = bcrypt($password);
         }
         $this->user->password = $password;
     }
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     $roles = $this->request->input('roles', []);
     // Retrieve all administrator users.
     $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) {
         $builder->whereName($adminName);
     })->get();
     // Retrieve the administrator role.
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if (count($roles) === 0 && $this->user->hasRole($admin) && $this->user->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role. You're the only administrator.");
     }
     if ($this->user->save()) {
         $this->user->roles()->sync($roles);
         return true;
     }
     return false;
 }
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $social_user = null;
     //CHECK IF USERS EMAIL ADDRESS IS ALREADY IN DATABASE
     $user_check = User::where('email', '=', $user->email)->first();
     if (!empty($user_check)) {
         $social_user = $user_check;
     } else {
         $same_social_id = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         // CHECK IF NEW SOCIAL MEDIA USER
         if (empty($same_social_id)) {
             $new_social_user = new User();
             $new_social_user->email = $user->email;
             $name = explode(' ', $user->name);
             if ($user->email) {
                 $new_social_user->name = $user->email;
             } else {
                 $new_social_user->name = $name[0];
             }
             $new_social_user->first_name = $name[0];
             // CHECK FOR LAST NAME
             if (isset($name[1])) {
                 $new_social_user->last_name = $name[1];
             }
             $new_social_user->active = '1';
             $the_activation_code = str_random(60) . $user->email;
             $new_social_user->activation_code = $the_activation_code;
             // GET IP ADDRESS
             $userIpAddress = new CaptureIp();
             $new_social_user->signup_sm_ip_address = $userIpAddress->getClientIp();
             // SAVE THE USER
             $new_social_user->save();
             // GET SOCIAL MEDIA LOGIN DATA
             $social_data = new Social();
             $social_data->social_id = $user->id;
             $social_data->provider = $provider;
             $new_social_user->social()->save($social_data);
             // GET GRAVATAR
             $new_social_user->gravatar = Gravatar::get($user->email);
             // ADD ROLE
             $role = Role::whereName('user')->first();
             $new_social_user->assignRole($role);
             $social_user = $new_social_user;
             // LINK TO PROFILE TABLE
             $profile = new Profile();
             $social_user->profile()->save($profile);
         } else {
             //Load this existing social user
             $social_user = $same_social_id->user;
         }
     }
     $this->auth->login($social_user, true);
     if ($this->auth->user()->hasRole('user')) {
         //return redirect()->route('user.home');
         return redirect('dashboard');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('dashboard');
         //return redirect()->route('admin.home');
     }
     return \App::abort(500);
 }
 /**
  * Obtain the user information from the social media site.
  *
  * @return Response
  */
 public function Callback($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $name = explode(' ', $user->name);
             $data = ['first_name' => $name[0], 'last_name' => $name[1], 'email' => $email];
             $this->userRepository->SocialRegister($newSocialUser);
             $socialData['social_id'] = $user->id;
             $socialData['provider'] = $provider;
             $socialRepository->saveSocial($socialData);
             $role = Role::whereName('user')->first();
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         $this->checkFutureList();
         return redirect('check');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('adminHome');
     }
 }
Exemple #28
0
 public function assign($role)
 {
     if (is_string($role)) {
         return $this->roles()->save(Role::whereName($role)->firstOrFail());
     }
     return $this->roles()->save($role);
 }
Exemple #29
0
 /**
  * Assign the given role to the user.
  *
  * @param  string $role
  * @return mixed
  */
 public function assignRole($role)
 {
     return $this->roles()->save(Role::whereName($role)->firstOrFail());
 }
 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $user->email;
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = $name[0];
             $newSocialUser->last_name = $name[1];
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             $role = Role::whereName('user')->first();
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         return redirect()->route('user.home');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect()->route('admin.home');
     }
     return \App::abort(500);
 }