public function testAuthState_authStateAccurateForLoggedInStateWithActing() { $role = UserRole::where('name', '=', UserRole::ACTOR_ROLE)->first(); $user = factory(App\Models\User::class, 1)->create(); $user->password = '******'; $user->save(); $user2 = factory(App\Models\User::class, 1)->create(); $user2->password = '******'; $user2->save(); $user->roles()->attach($role); App::bindShared('oauth2-server.authorizer', function () use($user) { $mock = Mockery::mock(\LucaDegasperi\OAuth2Server\Authorizer::class); $mock->shouldReceive('getResourceOwnerId')->andReturn($user->id); $mock->shouldReceive('getResourceOwnerType')->andReturn("user"); return $mock; }); Input::merge(array('access_token' => 'random_token')); Input::merge(array('act_as' => $user2->id)); $adapter = App::make(APIAdapter::class); $state = $adapter->getAuthState(); $this->assertFalse($state->rememberMe); $this->assertEquals($user->id, $state->userId); $this->assertEquals($user2->id, $state->actingUserId); $this->assertEquals(APIAdapter::AUTH_MECHANISM, $state->authMechanism); }
public function testAuthState_authStateAccurateForLoggedInStateWithActing() { $role = UserRole::where('name', '=', UserRole::ACTOR_ROLE)->first(); $user = factory(App\Models\User::class, 1)->create(); $user->password = '******'; $user->save(); $user2 = factory(App\Models\User::class, 1)->create(); $user2->password = '******'; $user2->save(); $user->roles()->attach($role); Auth::attempt(['username' => $user->username, 'password' => 'password']); Acting::asUser($user2); $adapter = new WebsiteAdapter(); $state = $adapter->getAuthState(); $this->assertFalse($state->rememberMe); $this->assertEquals($user->id, $state->userId); $this->assertEquals($user2->id, $state->actingUserId); $this->assertEquals(WebsiteAdapter::AUTH_MECHANISM, $state->authMechanism); }
/** * Handles user edit * * @param EditUserRequest $request * @param int $id User id * @return \Illuminate\Http\RedirectResponse */ public function putEdit(EditUserRequest $request, $id) { $user = User::find($id); $user->changeProfile($request); if ($user->hasRole('admin') && count($user->getAdmins(false, true)) <= 1 && (!in_array(1, $request->input('roles')) || !$request->input('active'))) { flash()->error(trans('users.can_not_edit')); return redirect()->back(); } else { UserRole::where('user_id', $user->id)->delete(); $user->roles()->attach($request->input('roles')); $user->changeSettings($request); } if ($request->file('avatar')) { $user->changeAvatar($request); } $user->save(); User::flushCache($user); flash()->success(trans('users.edit_success')); return redirect()->back(); }
public function _indexAudittrail() { $userRole = UserRole::where(['ACTIVE' => 1])->get(['ID', 'NAME']); $filterGroups = array('productionFilterGroup' => [], 'dateFilterGroup' => array(['id' => 'date_begin', 'name' => 'From Date'], ['id' => 'date_end', 'name' => 'To Date']), 'frequenceFilterGroup' => [['name' => 'IntObjectType', 'default' => ['ID' => 0, 'NAME' => 'All']]], 'enableSaveButton' => false); return view('admin.audittrail', ['filters' => $filterGroups, 'userRole' => $userRole]); }