public function setupDatabases() { $name = $this->call('migrate', array('--path' => 'app/database/migrations/setup/')); $name = $this->call('migrate'); // create the roles $roles = ['Admin', 'Writer', 'Reader']; foreach ($roles as $r) { $role = Role::whereName($r)->first(); if ($role == null) { $role = new Role(); $role->name = $r; $role->display_name = $r; $role->save(); $this->info("{$role->id} Creating Role:{$r}"); } } foreach (User::all() as $u) { $this->info("{$u->id} : user: {$u->username}"); } // add core assets $m = Asset::findFromTag('missing-user-image'); if ($m == NULL) { $m = new Asset(); $m->path = "assets/content/uploads"; $m->saveLocalFile(public_path('assets/content/common/missing/profile-default.png'), 'profile-default.png'); $m->tag = 'missing-user-image'; $m->shared = 1; $m->type = Asset::ASSET_TYPE_IMAGE; $m->save(); } $this->comment("****\tAll Databases for Halp have been setup :-) \t****"); return; }
public function run() { DB::table('permission_role')->truncate(); // Assign permissions for Admin role $admin_role = Role::whereName('admin')->get()->first(); $admin_role->assignPermissions([1, 2, 3, 4, 5, 6, 7]); // Assign permissions for Member role $member_role = Role::whereName('member')->get()->first(); $member_role->assignPermissions([2, 3, 4, 5, 6, 7]); }
/** * Assign the given role to the user. * * @param string $role * @return mixed */ public function assignRole($role) { return $this->roles()->save(Role::whereName($role)->firstOrFail()); }
/** * Update the specified user in storage. * * @param int $id * @return Response */ public function updateRolePermissions() { $input = Input::all(); foreach ($input['permissions'] as $role => $permissions) { Role::whereName($role)->first()->perms()->sync($permissions); } return Redirect::route('role.permissions.edit')->with('message', 'Successfully updated role permissions')->with('alert-class', 'success'); }
public function getSocialHandle($provider) { $user = Socialite::with($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('/'); } if ($this->auth->user()->hasRole('administrator')) { return redirect()->route('/backoffice'); } return \App::abort(500); }
public function storeMiniAdmin() { $user = $this->user; $data = Input::only('email', 'password'); if (!$user->is_valid($data)) { return Redirect::back()->withInput()->withErrors(User::$errors); } $user->email = Input::get('email'); $user->password = Hash::make(Input::get('password')); $user->save(); $role = Role::whereName('miniadmin')->first(); $user->roles()->attach($role->id); return Redirect::to('/admin/miniadmin'); }
public function editUserRoles($id) { $user = User::findOrFail($id); if ($user) { $current_roles = $user->roles; $spotter_role = Role::whereName('Writer')->first(); $has_spotter_role = false; $rolesToAttach = []; foreach (Input::get('roles') as $key => $value) { $role = Role::where('id', '=', $key)->first(); if ($key == $spotter_role->id) { $has_spotter_role = true; } if ($role) { array_push($rolesToAttach, $key); } } if (count($rolesToAttach) > 0) { $user->roles()->sync($rolesToAttach); } $had_spotter_role_already = false; foreach ($current_roles as $role) { if ($role->id == $spotter_role->id) { $had_spotter_role_already = true; } } if ($has_spotter_role && $had_spotter_role_already == false) { // Activity::createActivityAndFire([ // 'name'=>Activity::ACTIVITY_USER_SPOTTER, // 'timestamp'=>Carbon\Carbon::now(), // 'parent'=>$user, // 'user_id'=>$user->id // ]); } return Redirect::back()->with('notice', 'User updated'); } return Redirect::back()->with('error', 'Could not find user'); }
private function saveUser() { $user = new User(); $role = Input::get('role') ? Role::whereName(strtolower(Input::get('role')))->first() : Role::whereName('member')->first(); $user->name = Input::get('name'); $user->username = Input::get('username'); $user->password = Hash::make(Input::get('password')); $user->email = Input::get('email'); $user->address = Input::get('address'); $user->telephone = Input::get('telephone'); $user->city = Input::get('city'); $user->role_id = $role->id; $user->active = Input::get('active') ?: 1; $user->save(); }