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

[VYMCA-64] CSV Security Enhancement #68

Merged
merged 9 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ For videos, protected from embed by "Specific domains" you can have an issue
with thumbnails download to drupal media. In this case - apply a patch
for drupal core:

* _patches/OEmbed\_vimeo\_private\_videos.patch_
* _patches/OEmbed\_vimeo\_private\_videos.patch_ - in case of using core media
* _patches/video\_embed\_field\_vimeo\_private\_videos.patch_ - in case of
using video_embed_field module


### JSON API patch required for Drupal 8.7
Expand Down
2 changes: 1 addition & 1 deletion js/gated-content/dist/gated-content.css

Large diffs are not rendered by default.

4,208 changes: 18 additions & 4,190 deletions js/gated-content/dist/gated-content.umd.min.js

Large diffs are not rendered by default.

42 changes: 29 additions & 13 deletions js/gated-content/src/components/auth/CustomAuth.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<template>
<div>
<div class="container">
<div v-if="message" class="alert alert-info">
<span v-html="message"></span>
</div>
<div v-if="loading" class="spinner-center">
<Spinner></Spinner>
</div>
<form v-else class="plugin-custom">
<div v-if="this.error" class="alert alert-danger">
<span>{{ this.error }}</span>
<div v-if="error" class="alert alert-danger">
<span>{{ error }}</span>
</div>
<div class="form-group">
<label for="auth-email">Email Address</label>
<input
v-model="form.email"
placeholder="jondoe@example.com"
placeholder="johndoe@example.com"
type="email"
id="auth-email"
class="form-control"
Expand Down Expand Up @@ -42,8 +45,10 @@ export default {
form: {
email: '',
recaptchaToken: '',
path: '',
},
error: '',
message: '',
};
},
computed: {
Expand All @@ -55,27 +60,38 @@ export default {
async login() {
this.loading = true;
this.error = '';
const appUrl = this.$store.getters.getAppUrl;
if (appUrl !== undefined && appUrl.length > 0) {
this.form.path = appUrl;
} else {
this.form.path = window.location.pathname;
}
await this.$store
.dispatch('customAuthorize', this.form)
.then(() => {
const appUrl = this.$store.getters.getAppUrl;
.then((response) => {
if (response.status === 202) {
this.message = response.data.message;
this.form.email = '';
if (this.config.enableRecaptcha) {
this.$refs.recaptcha.reset();
}
this.loading = false;
return;
}
if (appUrl !== undefined && appUrl.length > 0) {
window.location = appUrl;
} else {
this.$router.push({ name: 'Home' }).catch(() => {});
}
})
.catch((error) => {
this.loading = false;
this.error = error.response ? error.response.data.message : 'Something went wrong!';
console.log(this.$refs);
this.$refs.recaptcha.reset();
if (this.config.enableRecaptcha) {
this.$refs.recaptcha.reset();
}
this.loading = false;
});
},
},
};
</script>

<style scoped>

</style>
68 changes: 68 additions & 0 deletions js/gated-content/src/components/auth/CustomAuthEmailConfirm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<div class="container">
<div v-if="error" class="error-wrapper">
<div class="alert alert-danger">
<span>{{ error }}</span>
</div>

<p class="text-center">
<router-link :to="{ name: 'Login' }" class="btn btn-lg btn-primary">Sign In</router-link>
</p>
</div>
<div v-if="loading" class="spinner-center">
<Spinner></Spinner>
</div>
</div>
</template>

<script>
import Spinner from '@/components/Spinner.vue';

export default {
name: 'CustomAuthEmailConfirm',
components: {
Spinner,
},
props: {
id: {
type: String,
required: true,
},
token: {
type: String,
required: true,
},
},
data() {
return {
loading: true,
error: '',
};
},
computed: {
config() {
return this.$store.getters.getCustomConfig;
},
},
mounted() {
this.confirmEmail();
},
methods: {
async confirmEmail() {
this.loading = true;
await this.$store
.dispatch('customEmailConfirmation', {
id: this.id,
token: this.token,
})
.then(() => {
this.$router.push({ name: 'Home' }).catch(() => {});
})
.catch((error) => {
this.error = error.response ? error.response.data.message : 'Something went wrong!';
this.loading = false;
});
},
},
};
</script>
8 changes: 8 additions & 0 deletions js/gated-content/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VueRouter from 'vue-router';
import Store from '@/store';
import Home from '@/views/Home.vue';
import Login from '@/views/Login.vue';
import CustomAuthEmailConfirm from '@/components/auth/CustomAuthEmailConfirm.vue';
import NotFound from '@/views/NotFound.vue';
import VideoPage from '@/views/VideoPage.vue';
import BlogPage from '@/views/BlogPage.vue';
Expand All @@ -29,6 +30,13 @@ const routes = [
component: Login,
meta: { requiresGuest: true },
},
{
path: '/login/:id/:token/confirm',
name: 'CustomAuthEmailConfirm',
component: CustomAuthEmailConfirm,
props: true,
meta: { requiresGuest: true },
},
{
path: '/categories',
name: 'CategoryListing',
Expand Down
6 changes: 6 additions & 0 deletions js/gated-content/src/scss/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@
}
}
}

.openy_carnation {
#gated-content {
padding-top: 30px;
}
}
32 changes: 32 additions & 0 deletions js/gated-content/src/store/modules/auth/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,43 @@ export default {
data: {
recaptchaToken: data.recaptchaToken,
email: data.email,
path: data.path,
},
})
.then((response2) => {
if (response2.status === 200) {
// Call the base auth authorize action.
context.dispatch('authorize', response2.data.user);
}
return response2;
})
.catch((error) => {
console.error(error);
throw error;
}))
.catch((error) => {
throw error;
});
},
async customEmailConfirmation(context, data) {
return client
.get('session/token')
.then((response) => client({
url: context.getters.getCustomConfig.emailVerificationApiEndpoint,
method: 'post',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': response.data,
},
params: {
_format: 'json',
},
data,
})
.then((response2) => {
// Call the base auth authorize action.
context.dispatch('authorize', response2.data.user);
return response2;
})
.catch((error) => {
console.error(error);
Expand Down
2 changes: 0 additions & 2 deletions js/gated-content/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export default {
return this.$store.getters.authPlugin;
},
},
mounted() {
},
methods: {
loginSuccess() {
this.$router.push({ name: 'Home' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
enable_recaptcha: 1
enable_recaptcha: 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we going to disable captcha for current sites via hood_update_N?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case ReCaptcha disabled for builds, without sitekey it not works

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So users would need to enable it manually after installation, right?
I guess instead of changing defaults to 'no captcha' it's better to tune build system to disable captcha via config set . Defaults should be production ready, not build ready

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, reverted this to the previous state. By default on builds we have dummy plugin, so I think no need to tune the build system now.

api_endpoint: /openy-gc-auth/provider/custom/login
enable_email_verification: 1
email_verification_api_endpoint: /openy-gc-auth/provider/custom/login-by-link
email_verification_link_life_time: '14400'
email_verification_text: 'Hello! <br> You’re just one step away from accessing your Virtual YMCA. Please open the link below to begin enjoying YMCA content made exclusively for members like you.'
verification_message: 'We have sent a verification link to the email address you provided. Please open this link and activate your account. If you do not receive an email, please try again or contact us at XXX-XXX-XXXX to ensure we have the correct email on file for your membership.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
langcode: en
status: true
dependencies:
module:
- openy_gc_auth_custom
- serialization
- user
id: openy_gc_auth_custom_confirm
plugin_id: openy_gc_auth_custom_confirm
granularity: resource
configuration:
methods:
- POST
formats:
- json
authentication:
- cookie
Loading