Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRODDEV-219] Implement redirect after login #289

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/gated-content/dist/gated-content.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions js/gated-content/dist/gated-content.umd.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/gated-content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"qs": "^6.9.4",
"regenerator-runtime": "^0.13.7",
"vue": "^2.6.12",
"vue-cookies": "^1.7.4",
"vue-router": "^3.4.9",
"vue-video-wrapper": "^1.0.10",
"vuex": "^3.5.1",
Expand Down
9 changes: 9 additions & 0 deletions js/gated-content/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue';
import VueCookies from 'vue-cookies';
import { sync } from 'vuex-router-sync';
import updateLocale from 'dayjs/plugin/updateLocale';
import duration from 'dayjs/plugin/duration';
Expand All @@ -12,6 +13,8 @@ import Log from './plugins/log';
import 'core-js/stable';
import 'regenerator-runtime/runtime';

Vue.use(VueCookies);

Vue.use(Log);

Vue.config.productionTip = false;
Expand Down Expand Up @@ -45,6 +48,12 @@ new Vue({
mounted() {
const app = this;

const cookieName = 'openy_gc_auth_destination';
if (this.$cookies.isKey(cookieName)) {
window.location.hash = this.$cookies.get(cookieName);
this.$cookies.remove(cookieName);
}

if ('-ms-scroll-limit' in document.documentElement.style
&& '-ms-ime-align' in document.documentElement.style) {
window.addEventListener('hashchange',
Expand Down
14 changes: 14 additions & 0 deletions modules/openy_gc_auth/js/auth.behaviors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(function ($, Drupal) {
Drupal.behaviors.openy_gc_auth_store_hash = {
attach: function (context) {
// Only run this script on full documents, not ajax requests.
if (context !== document) {
return;
}
if (!window.location.hash || window.location.hash === '#') {
return;
}
$.cookie('openy_gc_auth_destination', window.location.hash);
}
}
})(jQuery, Drupal);
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta

$form['login_mode'] = [
'#title' => $this->t('Login mode'),
'#description' => $this->t('When "Redirect immediately" mode used, it is not possible to redirect user after login to his initially requested VY route.'),
'#type' => 'radios',
'#default_value' => $config['login_mode'],
'#required' => TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta

$form['login_mode'] = [
'#title' => $this->t('Login mode'),
'#description' => $this->t('When "Redirect immediately" mode used, it is not possible to redirect user after login to his initially requested VY route.'),
'#type' => 'radios',
'#default_value' => $config['login_mode'],
'#required' => TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta

$form['login_mode'] = [
'#title' => $this->t('Login mode'),
'#description' => $this->t('When "Redirect immediately" mode used, it is not possible to redirect user after login to his initially requested VY route.'),
'#type' => 'radios',
'#default_value' => $config['login_mode'],
'#required' => TRUE,
Expand Down
7 changes: 7 additions & 0 deletions modules/openy_gc_auth/openy_gc_auth.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
auth_destination:
version: 0.1
js:
js/auth.behaviors.js: {}
dependencies:
- core/jquery
- core/jquery.cookie
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function checkForRedirect(Event $event) {
$currentUser->isAuthenticated()
&& $this->authManager->checkIfParagraphAtNode($node, 'gated_content_login')
) {
if (!empty($config->get('virtual_y_login_url'))) {
if (!empty($config->get('virtual_y_url'))) {
$event->setResponse(new RedirectResponse($config->get('virtual_y_url')));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function build() {

$virtual_y_config = $this->configFactory->get('openy_gc_auth.settings');
$active_provider = $virtual_y_config->get('active_provider');
$plugin_definition = $this->identityProviderManager->getDefinition($virtual_y_config->get('active_provider'), FALSE);
Expand All @@ -103,6 +102,7 @@ public function build() {
}
// phpcs:enable

$form['#attached']['library'][] = 'openy_gc_auth/auth_destination';
return $form;
}

Expand Down