/** * @test delete */ public function testDeleteUserConfig() { $userConfig = $this->makeUserConfig(); $resp = $this->userConfigRepo->delete($userConfig->id); $this->assertTrue($resp); $this->assertNull(UserConfig::find($userConfig->id), 'UserConfig should not exist in DB'); }
public function checkGoogle($force = false) { if (is_null($client = $this->getGoogleClient($force))) { return null; } if (!isset($_GET['code']) || isset($_GET['state'])) { return null; } $this->debug($_GET['code']); $client->authenticate($_GET['code']); $user = $this->googleOauth->userinfo->get(); $details = ['id' => $user['id'], 'name' => filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS), 'email' => filter_var($user['email'], FILTER_SANITIZE_EMAIL), 'profile_url' => filter_var($user['link'], FILTER_VALIDATE_URL), 'image_url' => filter_var($user['picture'], FILTER_VALIDATE_URL)]; if ($force) { $user = User::findByPk($this->id); $user->google_id = $details['id']; UserConfig::set('GOOGLE_NAME', $details['name']); UserConfig::set('GOOGLE_EMAIL', $details['email']); UserConfig::set('GOOGLE_PROFILE', $details['profile_url']); UserConfig::set('GOOGLE_IMAGE', $details['image_url']); return $user->save(false); } if (!is_null($user = User::findByAttributes(['google_id' => $details['id']]))) { return $user; } return User::googleRegister($details); }
/** * Before deleting user delete every other tables connected to it. * @return bool|void */ public function beforeDelete() { App::get()->sql()->table('users2groups')->where("user_id = :id")->setParam(':id', $this->id)->delete(); UserHistory::deleteAllByAttributes(['user_id' => $this->id]); UserConfig::deleteAllByAttributes(['user_id' => $this->id]); return parent::beforeDelete(); }