From ebb7b6de9bcd2b8df73e1d5f2d4c27782f2cb673 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 2 Jun 2018 15:54:52 -0700 Subject: [PATCH 1/3] Let gulp build the necessary core files using artisan --- gulpfile.js | 32 +++++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index a7bcf73ce..b843f890a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,7 @@ const babel = require('gulp-babel'); const concat = require('gulp-concat'); const cssmin = require('gulp-cssmin'); const del = require('del'); +const exec = require('child_process').exec; const gulp = require('gulp'); const gulpif = require('gulp-if'); const postcss = require('gulp-postcss'); @@ -74,6 +75,32 @@ function watch() { }, scripts)); } +/** + * Generate the language files to be consumed by front end. + * + * @returns {Promise} + */ +function i18n() { + return new Promise((resolve, reject) => { + exec('php artisan vue-i18n:generate', {}, (err, stdout, stderr) => { + return err ? reject(err) : resolve({ stdout, stderr }); + }) + }) +} + +/** + * Generate the routes file to be used in Vue files. + * + * @returns {Promise} + */ +function routes() { + return new Promise((resolve, reject) => { + exec('php artisan ziggy:generate resources/assets/scripts/helpers/ziggy.js', {}, (err, stdout, stderr) => { + return err ? reject(err) : resolve({ stdout, stderr }); + }); + }) +} + /** * Cleanup unused versions of hashed assets. */ @@ -82,9 +109,12 @@ function clean() { } exports.clean = clean; +exports.i18n = i18n; +exports.routes = routes; exports.styles = styles; exports.scripts = scripts; exports.watch = watch; +gulp.task('components', gulp.parallel(i18n, routes)); gulp.task('scripts', gulp.series(clean, scripts)); -gulp.task('default', gulp.series(clean, styles, scripts)); +gulp.task('default', gulp.series(clean, i18n, routes, styles, scripts)); diff --git a/package.json b/package.json index a790e437f..1eea87689 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "build:filemanager": "./node_modules/babel-cli/bin/babel.js public/themes/pterodactyl/js/frontend/files/src --source-maps --out-file public/themes/pterodactyl/js/frontend/files/filemanager.min.js", "watch": "./node_modules/gulp-cli/bin/gulp.js watch", "build": "./node_modules/gulp-cli/bin/gulp.js default", + "build:components": "./node_modules/gulp-cli/bin/gulp.js components", "build:styles": "./node_modules/gulp-cli/bin/gulp.js styles", "build:scripts": "./node_modules/gulp-cli/bin/gulp.js scripts" }, From 4209be021e0c74623a2f723308bc806e9f14a635 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 2 Jun 2018 16:59:16 -0700 Subject: [PATCH 2/3] Add handlers for non-successful responses from the panel --- resources/assets/scripts/bootstrap.js | 2 +- .../assets/scripts/components/auth/ForgotPassword.vue | 4 ++++ resources/assets/scripts/components/auth/LoginForm.vue | 9 ++++++++- .../assets/scripts/components/auth/ResetPassword.vue | 4 ++++ .../assets/scripts/components/auth/TwoFactorForm.vue | 4 ++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/resources/assets/scripts/bootstrap.js b/resources/assets/scripts/bootstrap.js index 8d2009067..f29ff0528 100644 --- a/resources/assets/scripts/bootstrap.js +++ b/resources/assets/scripts/bootstrap.js @@ -17,8 +17,8 @@ try { */ window.axios = require('axios'); - window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; +window.axios.defaults.headers.common['Accept'] = 'application/json'; /** * Next we will register the CSRF Token as a common header with Axios so that diff --git a/resources/assets/scripts/components/auth/ForgotPassword.vue b/resources/assets/scripts/components/auth/ForgotPassword.vue index e06fa40b4..0c72b884c 100644 --- a/resources/assets/scripts/components/auth/ForgotPassword.vue +++ b/resources/assets/scripts/components/auth/ForgotPassword.vue @@ -68,6 +68,10 @@ email: this.$props.email, }) .then(function (response) { + if (!(response.data instanceof Object)) { + throw new Error('An error was encountered while processing this request.'); + } + self.$data.submitDisabled = false; self.$data.showSpinner = false; self.success(response.data.status); diff --git a/resources/assets/scripts/components/auth/LoginForm.vue b/resources/assets/scripts/components/auth/LoginForm.vue index 07236d550..0028db4e2 100644 --- a/resources/assets/scripts/components/auth/LoginForm.vue +++ b/resources/assets/scripts/components/auth/LoginForm.vue @@ -81,6 +81,12 @@ password: this.$props.user.password, }) .then(function (response) { + // If there is a 302 redirect or some other odd behavior (basically, response that isnt + // in JSON format) throw an error and don't try to continue with the login. + if (!(response.data instanceof Object)) { + throw new Error('An error was encountered while processing this request.'); + } + if (response.data.complete) { return window.location = '/'; } @@ -92,6 +98,8 @@ .catch(function (err) { self.$props.user.password = ''; self.$data.showSpinner = false; + self.$refs.password.focus(); + if (!err.response) { return console.error(err); } @@ -101,7 +109,6 @@ response.data.errors.forEach(function (error) { self.error(error.detail); }); - self.$refs.password.focus(); } }); }, diff --git a/resources/assets/scripts/components/auth/ResetPassword.vue b/resources/assets/scripts/components/auth/ResetPassword.vue index 2a7cf17a6..cda6716ac 100644 --- a/resources/assets/scripts/components/auth/ResetPassword.vue +++ b/resources/assets/scripts/components/auth/ResetPassword.vue @@ -93,6 +93,10 @@ token: this.$props.token, }) .then(function (response) { + if (!(response.data instanceof Object)) { + throw new Error('An error was encountered while processing this login.'); + } + return window.location = response.data.redirect_to; }) .catch(function (err) { diff --git a/resources/assets/scripts/components/auth/TwoFactorForm.vue b/resources/assets/scripts/components/auth/TwoFactorForm.vue index 27d2b2282..fb51090f3 100644 --- a/resources/assets/scripts/components/auth/TwoFactorForm.vue +++ b/resources/assets/scripts/components/auth/TwoFactorForm.vue @@ -49,6 +49,10 @@ authentication_code: this.$data.code, }) .then(function (response) { + if (!(response.data instanceof Object)) { + throw new Error('An error was encountered while processing this login.'); + } + window.location = response.data.intended; }) .catch(function (err) { From dec969bf9f6e1d4b28904923be44e0f965bdb8c4 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 2 Jun 2018 17:01:54 -0700 Subject: [PATCH 3/3] Fix checkpoint behavior to only work when a token is provided --- resources/assets/scripts/app.js | 2 +- resources/assets/scripts/components/auth/TwoFactorForm.vue | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/assets/scripts/app.js b/resources/assets/scripts/app.js index 180df2a40..1a6b9476c 100644 --- a/resources/assets/scripts/app.js +++ b/resources/assets/scripts/app.js @@ -35,7 +35,7 @@ const router = new VueRouter({ routes: [ { name: 'login', path: '/auth/login', component: Login }, { name: 'forgot-password', path: '/auth/password', component: Login }, - { name: 'checkpoint', path: '/checkpoint', component: Login }, + { name: 'checkpoint', path: '/auth/checkpoint', component: Login }, { name: 'reset-password', path: '/auth/password/reset/:token', diff --git a/resources/assets/scripts/components/auth/TwoFactorForm.vue b/resources/assets/scripts/components/auth/TwoFactorForm.vue index fb51090f3..84a0461d5 100644 --- a/resources/assets/scripts/components/auth/TwoFactorForm.vue +++ b/resources/assets/scripts/components/auth/TwoFactorForm.vue @@ -37,6 +37,10 @@ }; }, mounted: function () { + if ((this.$route.query.token || '').length < 1) { + return this.$router.push({ name: 'login' }); + } + this.$refs.code.focus(); }, methods: {