Ejemplo n.º 1
0
 /**
  * Tests the update function in the UserController
  * @param  void
  * @return void
  */
 public function testDelete()
 {
     $this->call('POST', '/user', $this->userData);
     $this->call('DELETE', '/user/1/delete', $this->userData);
     $usersSaved = User::withTrashed()->find(1);
     $this->assertNotNull($usersSaved->deleted_at);
 }
Ejemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $cats = \App\Models\Category::lists('id');
     foreach (\App\Models\User::withTrashed()->get() as $user) {
         $user->categories = $cats;
         $user->save();
     }
 }
Ejemplo n.º 3
0
 /**
  * @param $id
  * @param bool $withRoles
  * @return mixed
  * @throws GeneralException
  */
 public function findOrThrowException($id, $withRoles = false)
 {
     if ($withRoles) {
         $user = User::with('roles')->withTrashed()->find($id);
     } else {
         $user = User::withTrashed()->find($id);
     }
     if (!is_null($user)) {
         return $user;
     }
     throw new GeneralException('That user does not exist.');
 }
Ejemplo n.º 4
0
 /**
  * get user by id
  * @param            $id
  * @param bool|false $withRoles
  * @return array|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
  */
 public function find($id, $withRoles = false)
 {
     if ($withRoles) {
         $user = User::with('roles')->withTrashed()->find($id);
     } else {
         $user = User::withTrashed()->find($id);
     }
     if (!is_null($user)) {
         return $user;
     }
     return array();
 }
Ejemplo n.º 5
0
 public static function setupCompleted()
 {
     $users_table_exists = Schema::hasTable('users');
     $settings_table_exists = Schema::hasTable('settings');
     if ($users_table_exists && $settings_table_exists) {
         $usercount = User::withTrashed()->count();
         if ($usercount > 0) {
             return true;
         }
         return false;
     } else {
         return false;
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * @param SocialiteUser $oauthUserData
  * @param string        $provider
  *
  * @return Authenticatable|bool
  */
 public function registerViaOAuth(SocialiteUser $oauthUserData, $provider)
 {
     if (!($ownerAccount = User::withTrashed()->whereEmail($oauthUserData->email)->first())) {
         $ownerAccount = \Eloquent::unguarded(function () use($oauthUserData) {
             return User::create(['name' => $oauthUserData->name, 'email' => $oauthUserData->email, 'password' => \Hash::make(uniqid("", true))]);
         });
     }
     # If user account is soft-deleted, restore it.
     $ownerAccount->trashed() && $ownerAccount->restore();
     # Update missing user name.
     if (!$ownerAccount->name) {
         $ownerAccount->name = $oauthUserData->name;
         $ownerAccount->save();
     }
     # Event
     \Event::fire(new Registered($ownerAccount, $provider));
     ($doLinkOAuthAccount = $this->linkOAuthAccount($oauthUserData, $provider, $ownerAccount)) && $this->auth->login($ownerAccount, true);
     \Event::fire(new LoggedIn($ownerAccount, $provider));
     return $doLinkOAuthAccount;
 }
Ejemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Videos
     echo 'UPDATING VIDEOS', PHP_EOL, '===============', PHP_EOL;
     $count = 0;
     Video::withTrashed()->with('category')->chunk(200, function ($videos) use($count) {
         foreach ($videos as $v) {
             echo 'Updating Video with ID: ', $v->id, PHP_EOL;
             $v->detag();
             // quick and dirty. not 100% correct though.
             if ($v->category->shortname === 'pr0n') {
                 $v->tag('nsfw');
             } else {
                 $v->tag('sfw');
             }
             $v->tag(array_filter([$v->category->shortname, $v->category->name, $v->interpret, $v->songtitle, $v->imgsource], function ($elem) {
                 return !empty(trim($elem));
             }));
             $count++;
         }
     });
     echo PHP_EOL, PHP_EOL, 'Updated ', $count, ' Videos.', PHP_EOL, PHP_EOL, PHP_EOL;
     // User filters
     echo 'UPDATING USERS', PHP_EOL, '==============', PHP_EOL;
     $count = 0;
     $categories = Category::withTrashed()->get()->keyBy('id');
     User::withTrashed()->chunk(200, function ($users) use(&$count, $categories) {
         foreach ($users as $u) {
             echo 'Updating User: '******'Updated ', $count, ' Users.', PHP_EOL, PHP_EOL, PHP_EOL;
 }
 /**
  * @return string
  */
 public function checkEmail()
 {
     $email = User::withTrashed()->where('email', '=', Input::get('email'))->where('id', '<>', Auth::user()->id)->first();
     if ($email) {
         return 'taken';
     } else {
         return 'available';
     }
 }
Ejemplo n.º 9
0
 /**
  * Stores new account
  *
  */
 public function save($userPublicId = false)
 {
     if (Auth::user()->account->isPro()) {
         $rules = ['first_name' => 'required', 'last_name' => 'required'];
         if ($userPublicId) {
             $user = User::where('account_id', '=', Auth::user()->account_id)->where('public_id', '=', $userPublicId)->firstOrFail();
             $rules['email'] = 'required|email|unique:users,email,' . $user->id . ',id';
         } else {
             $rules['email'] = 'required|email|unique:users';
         }
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return Redirect::to($userPublicId ? 'users/edit' : 'users/create')->withInput()->withErrors($validator);
         }
         if ($userPublicId) {
             $user->first_name = trim(Input::get('first_name'));
             $user->last_name = trim(Input::get('last_name'));
             $user->username = trim(Input::get('email'));
             $user->email = trim(Input::get('email'));
         } else {
             $lastUser = User::withTrashed()->where('account_id', '=', Auth::user()->account_id)->orderBy('public_id', 'DESC')->first();
             $user = new User();
             $user->account_id = Auth::user()->account_id;
             $user->first_name = trim(Input::get('first_name'));
             $user->last_name = trim(Input::get('last_name'));
             $user->username = trim(Input::get('email'));
             $user->email = trim(Input::get('email'));
             $user->registered = true;
             $user->password = str_random(RANDOM_KEY_LENGTH);
             $user->confirmation_code = str_random(RANDOM_KEY_LENGTH);
             $user->public_id = $lastUser->public_id + 1;
         }
         $user->save();
         if (!$user->confirmed) {
             $this->userMailer->sendConfirmation($user, Auth::user());
             $message = trans('texts.sent_invite');
         } else {
             $message = trans('texts.updated_user');
         }
         Session::flash('message', $message);
     }
     return Redirect::to('company/advanced_settings/user_management');
 }
Ejemplo n.º 10
0
 /**
  * Return a view containing a pre-populated new user form,
  * populated with some fields from an existing user.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.0]
  * @param  int  $id
  * @return Redirect
  */
 public function getClone($id = null)
 {
     // We need to reverse the UI specific logic for our
     // permissions here before we update the user.
     $permissions = Input::get('permissions', array());
     //$this->decodePermissions($permissions);
     app('request')->request->set('permissions', $permissions);
     try {
         // Get the user information
         $user_to_clone = User::withTrashed()->find($id);
         $user = clone $user_to_clone;
         $user->first_name = '';
         $user->last_name = '';
         $user->email = substr($user->email, ($pos = strpos($user->email, '@')) !== false ? $pos : 0);
         $user->id = null;
         // Get this user groups
         $userGroups = $user_to_clone->groups()->lists('name', 'id');
         // Get a list of all the available groups
         $groups = Group::pluck('name', 'id');
         // Get all the available permissions
         $permissions = config('permissions');
         $clonedPermissions = $user_to_clone->decodePermissions();
         $userPermissions = Helper::selectedPermissionsArray($permissions, $clonedPermissions);
         //$this->encodeAllPermissions($permissions);
         $location_list = Helper::locationsList();
         $company_list = Helper::companyList();
         $manager_list = Helper::managerList();
         // Show the page
         return View::make('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions'))->with('location_list', $location_list)->with('company_list', $company_list)->with('manager_list', $manager_list)->with('user', $user)->with('groups', $groups)->with('userGroups', $userGroups)->with('clone_user', $user_to_clone);
     } catch (UserNotFoundException $e) {
         // Prepare the error message
         $error = trans('admin/users/message.user_not_found', compact('id'));
         // Redirect to the user management page
         return redirect()->route('users')->with('error', $error);
     }
 }
Ejemplo n.º 11
0
 /**
  * @param SocialiteUser $oauthUserData
  * @param string        $provider
  *
  * @return \Illuminate\Contracts\Auth\Authenticatable|bool
  */
 protected function registerViaOAuth(SocialiteUser $oauthUserData, $provider)
 {
     /** @var \App\Models\User $ownerAccount */
     if (!($ownerAccount = User::withTrashed()->whereEmail($oauthUserData->email)->first())) {
         $ownerAccount = User::create(['name' => $oauthUserData->name, 'email' => $oauthUserData->email, 'password' => app('hash')->make(uniqid("", true))]);
         event(new Registered($ownerAccount, $provider));
     }
     # If user account is soft-deleted, restore it.
     $ownerAccount->trashed() && $ownerAccount->restore();
     # Update missing user name.
     if (!$ownerAccount->name) {
         $ownerAccount->name = $oauthUserData->name;
         $ownerAccount->save();
     }
     ($doLinkOAuthAccount = $this->linkOAuthAccount($oauthUserData, $provider, $ownerAccount)) && app('auth.driver')->login($ownerAccount, true);
     event(new LoggedIn($ownerAccount, $provider));
     return $doLinkOAuthAccount;
 }
Ejemplo n.º 12
0
 public function getComprobarusername($username)
 {
     $users = User::withTrashed()->where('username', '=', $username)->get();
     if (count($users) > 0) {
         return [array('existe' => true)];
     } else {
         return [array('existe' => false)];
     }
 }