Example #1
0
 /**
  * Checks if the current user may edit the brand
  *
  * @param User $user
  * @return bool
  */
 public function mayEdit(User $user)
 {
     $account = $user->account;
     // System admin may always edit
     if ($account->isSystemAccount() && $user->hasRole('admin')) {
         return true;
     }
     if ($account->brand->id == $this->id && $user->hasRole('admin')) {
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     $arr = $model->toArray();
     $arr['password'] = $this->password;
     $arr['password_confirmation'] = $this->password;
     return Validator::make($arr, User::createRules());
 }
Example #3
0
 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required']);
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = $this->isUsingThrottlesLoginsTrait();
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $this->getCredentials($request);
     $user = User::where('email', '=', $credentials['email'])->first();
     if ($user) {
         $messages = [];
         if (!$user->mayLogin($messages)) {
             return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $messages]);
         }
     }
     if (Auth::attempt($credentials, $request->has('remember'))) {
         return $this->handleUserWasAuthenticated($request, $throttles);
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
Example #4
0
 /**
  * Creates the application.
  *
  * @return \Illuminate\Foundation\Application
  */
 public function createApplication()
 {
     $app = (require __DIR__ . '/../bootstrap/app.php');
     $app->make('Illuminate\\Contracts\\Console\\Kernel')->bootstrap();
     $this->user = User::find($this->userId);
     return $app;
 }
Example #5
0
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     $user = $model->toArray();
     if ($this->updatedPassword) {
         $user['password'] = $this->updatedPassword;
         $user['password_confirmation'] = $this->updatedPassword;
     }
     return Validator::make($user, User::updateRules($model));
 }
Example #6
0
 /**
  * {@inheritdoc}.
  */
 protected function getModelFromRequest()
 {
     $netblock = new Netblock();
     $netblock->contact()->associate(User::find($this->argument('contact')));
     $netblock->first_ip = $this->argument('first_ip');
     $netblock->last_ip = $this->argument('last_ip');
     $netblock->description = $this->argument('description');
     $netblock->enabled = $this->argument('enabled') === 'true' ? true : false;
     return $netblock;
 }
Example #7
0
 /**
  * {@inheritdoc}.
  */
 protected function getObjectByArguments()
 {
     $user = false;
     if (!is_object($user)) {
         $user = User::where('email', $this->argument('user'))->first();
     }
     if (!is_object($user)) {
         $user = User::find($this->argument('user'));
     }
     return $user;
 }
Example #8
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     $generatedPassword = substr(md5(rand()), 0, 8);
     if (empty($this->option('password'))) {
         $this->info("Using auto generated password: {$generatedPassword}");
     }
     if (empty($this->option('account'))) {
         $account = Account::where('name', '=', 'default')->first();
     } else {
         $account = Account::where('name', '=', $this->option('account'))->first();
         if (!is_object($account)) {
             $this->error("The account named {$this->option('account')} was not found");
             return false;
         }
     }
     $user = new User();
     $user->email = empty($this->option('email')) ? false : $this->option('email');
     $user->password = empty($this->option('password')) ? $generatedPassword : $this->option('password');
     $user->first_name = $this->option('firstname');
     $user->last_name = $this->option('lastname');
     $user->locale = $this->option('language');
     $user->account_id = $account->id;
     $user->disabled = $this->option('disabled');
     $validation = Validator::make($user->toArray(), User::createRules($user));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the user due to validation warnings');
         return false;
     }
     if (!$user->save()) {
         $this->error('Failed to save the user into the database');
         return false;
     }
     $this->info("The user {$this->option('email')} has been created");
     return true;
 }
Example #9
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('user'))) {
         $this->warn('no email or id argument was passed, try --help');
         return false;
     }
     $user = false;
     if (!is_object($user)) {
         $user = User::where('email', $this->option('user'))->first();
     }
     if (!is_object($user)) {
         $user = User::find($this->option('user'));
     }
     if (!is_object($user)) {
         $this->error('Unable to find user with this criteria');
         return false;
     }
     $roleList = [];
     $roles = $user->roles()->get();
     foreach ($roles as $role) {
         if (is_object($role)) {
             $roleList[] = $role->description;
         }
     }
     $account = $user->account()->first();
     if (!is_object($account)) {
         $account = 'None';
     } else {
         $account = $account->name;
     }
     $table = [];
     $counter = 0;
     foreach (array_combine($this->headers, $this->fields) as $header => $field) {
         $counter++;
         $table[$counter][] = $header;
         if ($header == 'Disabled') {
             $table[$counter][] = (bool) $user->{$field} ? 'YES' : 'NO';
         } elseif ($header == 'Account') {
             $table[$counter][] = $account;
         } elseif ($header == 'Roles') {
             $table[$counter][] = implode(', ', $roleList);
         } else {
             $table[$counter][] = (string) $user->{$field};
         }
     }
     $userlist[] = $user;
     $this->table(['User Setting', 'User Value'], $table);
     return true;
 }
Example #10
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('role')) && empty($this->option('user'))) {
         $this->error('Missing options for role and/or user(e-mail) to select');
         return false;
     }
     /*
      * Detect the role->id and lookup the user if its thru a user assignment.
      */
     $role = false;
     $user = false;
     if (!empty($this->option('role'))) {
         if (!is_object($role)) {
             $role = Role::where('name', $this->option('role'))->first();
         }
         if (!is_object($role)) {
             $role = Role::find($this->option('role'));
         }
     }
     if (!empty($this->option('user'))) {
         if (!is_object($user)) {
             $user = User::where('email', $this->option('user'))->first();
         }
         if (!is_object($user)) {
             $user = Role::find($this->option('user'));
         }
     }
     if (!is_object($role) || !is_object($user)) {
         $this->error('Unable to find role with this criteria');
         return false;
     }
     $RoleUser = new RoleUser();
     $RoleUser->user_id = $user->id;
     $RoleUser->role_id = $role->id;
     $validation = Validator::make($RoleUser->toArray(), RoleUser::createRules($RoleUser));
     if ($validation->fails()) {
         $this->warn('The role has already been granted this permission');
         $this->error('Failed to create the permission due to validation warnings');
         return false;
     }
     if (!$RoleUser->save()) {
         $this->error('Failed to save the permission into the database');
         return false;
     }
     $this->info("The role {$role->name} has been granted to user {$user->email}");
     return true;
 }
Example #11
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
             break;
         case 'DELETE':
             break;
         case 'POST':
             return User::createRules();
         case 'PUT':
             break;
         case 'PATCH':
             return User::updateRules($this);
         default:
             break;
     }
     return [];
 }
Example #12
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
             break;
         case 'DELETE':
             break;
         case 'POST':
             return response('Unauthorized.', 401);
         case 'PUT':
             break;
         case 'PATCH':
             return User::updateRules($this);
         default:
             break;
     }
     return [];
 }
Example #13
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('role')) && empty($this->option('user'))) {
         $this->error('Missing options for role and/or user(e-mail) to select');
         return false;
     }
     /*
      * Detect the role->id and lookup the user if its thru a user assignment.
      */
     $role = false;
     $user = false;
     if (!empty($this->option('role'))) {
         if (!is_object($role)) {
             $role = Role::where('name', $this->option('role'))->first();
         }
         if (!is_object($role)) {
             $role = Role::find($this->option('role'));
         }
     }
     if (!empty($this->option('user'))) {
         if (!is_object($user)) {
             $user = User::where('email', $this->option('user'))->first();
         }
         if (!is_object($user)) {
             $user = Role::find($this->option('user'));
         }
     }
     if (!is_object($role) || !is_object($user)) {
         $this->error('Unable to find role with this criteria');
         return false;
     }
     $roleUser = RoleUser::all()->where('role_id', $role->id)->where('user_id', $user->id)->first();
     if (!is_object($roleUser)) {
         $this->error('Nothing to delete, this {$permission->name} permission is not linked to the role {$role->name}');
         return false;
     }
     if (!$roleUser->delete()) {
         $this->error('Failed to remove the permission into the database');
         return false;
     }
     $this->info("The role {$role->name} has been revoked from role {$user->email}");
     return true;
 }
Example #14
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('id'))) {
         $this->warn('The required id argument was not passed, try --help');
         return false;
     }
     /** @var Netblock|null $netblock */
     $netblock = Netblock::find($this->option('id'));
     if (null === $netblock) {
         $this->error('Unable to find netblock with this criteria');
         return false;
     }
     if (!empty($this->option("contact"))) {
         /** @var User|null $user */
         $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first();
         if (null === $user) {
             $this->error("Unable to find contact with this criteria");
             return false;
         }
         $netblock->contact()->associate($user);
     }
     $stringOptions = ["first_ip", "last_ip", "description"];
     foreach ($stringOptions as $option) {
         if (!empty($this->option($option))) {
             $netblock->{$option} = $this->option($option);
         }
     }
     if (!empty($this->option("enabled"))) {
         $netblock->enabled = castStringToBool($this->option("enabled"));
     }
     $validation = Validator::make($netblock->toArray(), Netblock::updateRules($netblock));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the netblock due to validation warnings');
         return false;
     }
     $netblock->save();
     $this->info("Netblock has been successfully updated");
     return true;
 }
Example #15
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('id'))) {
         $this->warn('The required id argument was not passed, try --help');
         return false;
     }
     /** @var Domain|null $domain */
     $domain = Domain::find($this->option('id'));
     if (null === $domain) {
         $this->error('Unable to find domain with this criteria');
         return false;
     }
     if (!empty($this->option("contact"))) {
         /** @var User|null $user */
         $user = User::find($this->option('contact')) ?: User::where('email', '=', $this->option("contact"))->first();
         if (null === $user) {
             $this->error("Unable to find contact with this criteria");
             return false;
         }
         $domain->contact()->associate($user);
     }
     if (!empty($this->option("name"))) {
         $domain->name = $this->option("name");
     }
     if (!empty($this->option("enabled"))) {
         $domain->enabled = castStringToBool($this->option("enabled"));
     }
     $validation = Validator::make($domain->toArray(), Domain::updateRules($domain));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the domain due to validation warnings');
         return false;
     }
     $domain->save();
     $this->info("Domain has been successfully updated");
     return true;
 }
Example #16
0
 /**
  * @return User|null
  */
 private function findUserByIdOrEmail($param)
 {
     $contact = User::find($param) ?: User::where('email', '=', $param)->first();
     return $contact;
 }
Example #17
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('user'))) {
         $this->warn('the required user argument was not passed, try --help');
         return false;
     }
     $user = false;
     if (!is_object($user)) {
         $user = User::where('email', $this->option('user'))->first();
     }
     if (!is_object($user)) {
         $user = User::find($this->option('user'));
     }
     if (!is_object($user)) {
         $this->error('Unable to find user with this criteria');
         return false;
     }
     // Apply changes to the user object
     if (!empty($this->option('email'))) {
         $user->email = $this->option('email');
     }
     if (!empty($this->option('password'))) {
         $user->password = $this->option('password');
     }
     if (!empty($this->option('autopassword'))) {
         $generatedPassword = substr(md5(rand()), 0, 8);
         $this->info("Using auto generated password: {$generatedPassword}");
         $user->password = $generatedPassword;
     }
     if (!empty($this->option('firstname'))) {
         $user->first_name = $this->option('firstname');
     }
     if (!empty($this->option('lastname'))) {
         $user->last_name = $this->option('lastname');
     }
     if (!empty($this->option('account'))) {
         $account = Account::where('name', '=', $this->option('account'))->first();
         if (!is_object($account)) {
             $this->error("The account named {$this->option('account')} was not found");
             return false;
         }
         $user->account_id = $account->id;
     }
     if (!empty($this->option('language'))) {
         $user->locale = $this->option('language');
     }
     if (!empty($this->option('disable'))) {
         $user->disabled = true;
     }
     if (!empty($this->option('enable'))) {
         $user->disabled = false;
     }
     // Validate the changes
     $validation = Validator::make($user->toArray(), User::updateRules($user));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the user due to validation warnings');
         return false;
     }
     // Save the object
     $user->save();
     $this->info("User has been successfully updated");
     return true;
 }
 protected function findUserWithOutput($output)
 {
     return User::find($this->returnIdFromSuccessOutput($output));
 }
Example #19
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
Example #20
0
 /**
  * {@inherit docs}.
  */
 protected function getCollectionWithArguments()
 {
     return User::where('id', $this->argument('user'));
 }
Example #21
0
 /**
  * {@inheritdoc }
  */
 protected function findAll()
 {
     $users = User::all($this->fields);
     return $this->hydrateWithRoles($users);
 }
Example #22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  User   $user
  * @return \Illuminate\Http\Response
  */
 public function destroy(User $user)
 {
     // Do not allow the default admin user account to be deleted.
     if ($user->id == 1) {
         return Redirect::back()->with('message', 'Not allowed to delete the default admin user.');
     }
     $user->delete();
     return Redirect::route('admin.users.index')->with('message', 'User has been deleted.');
 }
Example #23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param User $user
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy(User $user)
 {
     // Do not allow our own user to be destroyed.
     if ($user->id == $this->auth_user->id) {
         return Redirect::back()->with('message', 'Not allowed to delete current.');
     }
     $user->delete();
     return Redirect::route('admin.users.index')->with('message', 'User has been deleted.');
 }