From 6653595553b86e297dc4043a370fad24cbd4e21d Mon Sep 17 00:00:00 2001 From: dragon1211 Date: Sat, 8 Jan 2022 04:22:42 -0800 Subject: [PATCH] add redirect --- backend/app/Http/Middleware/Authenticate.php | 2 +- backend/public/js/app.js | 14 +++++++++----- backend/resources/js/admin/login/index.jsx | 8 +++++++- backend/resources/js/child/auth/login/index.jsx | 5 ++++- backend/resources/js/parent/auth/login/index.jsx | 5 ++++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/backend/app/Http/Middleware/Authenticate.php b/backend/app/Http/Middleware/Authenticate.php index 0146cd80..05da9988 100644 --- a/backend/app/Http/Middleware/Authenticate.php +++ b/backend/app/Http/Middleware/Authenticate.php @@ -21,7 +21,7 @@ class Authenticate extends Middleware public function handle ($request, Closure $next, ...$guard) { if (!$request->session()->has($guard[0])) { - return redirect(route($guard[0].'login').'?redirect_from=/'.$request->path()); + return redirect(route($guard[0].'login').'?redirect_to=/'.$request->path()); } return $next($request); diff --git a/backend/public/js/app.js b/backend/public/js/app.js index 2f9c6fd3..a98d2a48 100644 --- a/backend/public/js/app.js +++ b/backend/public/js/app.js @@ -27499,7 +27499,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react */ "./node_modules/react/index.js"); -/* harmony import */ var _material_ui_lab__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @material-ui/lab */ "./node_modules/@material-ui/lab/LoadingButton/LoadingButton.js"); +/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! react-router-dom */ "./node_modules/react-router/index.js"); +/* harmony import */ var _material_ui_lab__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @material-ui/lab */ "./node_modules/@material-ui/lab/LoadingButton/LoadingButton.js"); /* harmony import */ var react_cookie__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! react-cookie */ "./node_modules/react-cookie/es6/useCookies.js"); /* harmony import */ var _component_alert__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../component/alert */ "./resources/js/component/alert.jsx"); /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react/jsx-runtime */ "./node_modules/react/jsx-runtime.js"); @@ -27528,12 +27529,15 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } + var AdminLogin = function AdminLogin() { var _useCookies = (0,react_cookie__WEBPACK_IMPORTED_MODULE_4__["default"])(['user']), _useCookies2 = _slicedToArray(_useCookies, 2), cookies = _useCookies2[0], setCookie = _useCookies2[1]; + var location = (0,react_router_dom__WEBPACK_IMPORTED_MODULE_5__.useLocation)(); + var _useState = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(''), _useState2 = _slicedToArray(_useState, 2), email = _useState2[0], @@ -27599,7 +27603,7 @@ var AdminLogin = function AdminLogin() { localStorage.setItem('kiki_login_flag', true); localStorage.setItem('kiki_acc_type', 'admin'); setCookie('logged', 'success'); - window.location.href = "/admin/meeting"; + if (location.search == '') window.location.href = "/admin/meeting";else window.location.href = location.search.replace('?redirect_to=', ''); break; } @@ -27694,7 +27698,7 @@ var AdminLogin = function AdminLogin() { })] }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)("div", { className: "mt-5", - children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_material_ui_lab__WEBPACK_IMPORTED_MODULE_5__["default"], { + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)(_material_ui_lab__WEBPACK_IMPORTED_MODULE_6__["default"], { type: "submit", loading: submit, fullWidth: true, @@ -31562,7 +31566,7 @@ var ChildLogin = function ChildLogin() { localStorage.setItem('kiki_acc_type', 'c-account'); localStorage.setItem('kiki_acc_id', response.data.params.id); setCookie('logged', 'success'); - window.location.href = '/c-account/meeting'; + if (location.search == '') window.location.href = "/c-account/meeting";else window.location.href = location.search.replace('?redirect_to=', ''); break; } @@ -38571,7 +38575,7 @@ var ParentLogin = function ParentLogin() { localStorage.setItem('kiki_acc_type', 'p-account'); localStorage.setItem('kiki_acc_id', response.data.params.id); setCookie('logged', 'success'); - window.location.href = '/p-account/meeting'; + if (location.search == '') window.location.href = "/p-account/meeting";else window.location.href = location.search.replace('?redirect_to=', ''); break; } diff --git a/backend/resources/js/admin/login/index.jsx b/backend/resources/js/admin/login/index.jsx index a6083282..1aaa4763 100644 --- a/backend/resources/js/admin/login/index.jsx +++ b/backend/resources/js/admin/login/index.jsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { useLocation } from 'react-router-dom'; import { LoadingButton } from '@material-ui/lab'; import { useCookies } from 'react-cookie'; @@ -7,6 +8,7 @@ import Alert from '../../component/alert'; const AdminLogin = () => { const [cookies, setCookie] = useCookies(['user']); + const location = useLocation(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); @@ -39,7 +41,11 @@ const AdminLogin = () => { localStorage.setItem('kiki_login_flag', true); localStorage.setItem('kiki_acc_type', 'admin'); setCookie('logged', 'success'); - window.location.href = "/admin/meeting"; + if(location.search == '') + window.location.href = "/admin/meeting"; + else + window.location.href = location.search.replace('?redirect_to=', ''); + break; } case 422: { diff --git a/backend/resources/js/child/auth/login/index.jsx b/backend/resources/js/child/auth/login/index.jsx index 04a98a78..d57a9106 100644 --- a/backend/resources/js/child/auth/login/index.jsx +++ b/backend/resources/js/child/auth/login/index.jsx @@ -37,7 +37,10 @@ const ChildLogin = () => { localStorage.setItem('kiki_acc_type', 'c-account'); localStorage.setItem('kiki_acc_id', response.data.params.id); setCookie('logged', 'success'); - window.location.href = '/c-account/meeting'; + if(location.search == '') + window.location.href = "/c-account/meeting"; + else + window.location.href = location.search.replace('?redirect_to=', ''); break; } case 400: set400Error(response.data.error_message); break; diff --git a/backend/resources/js/parent/auth/login/index.jsx b/backend/resources/js/parent/auth/login/index.jsx index a11896be..525cd237 100644 --- a/backend/resources/js/parent/auth/login/index.jsx +++ b/backend/resources/js/parent/auth/login/index.jsx @@ -38,7 +38,10 @@ const ParentLogin = () => { localStorage.setItem('kiki_acc_type', 'p-account'); localStorage.setItem('kiki_acc_id', response.data.params.id); setCookie('logged', 'success'); - window.location.href = '/p-account/meeting'; + if(location.search == '') + window.location.href = "/p-account/meeting"; + else + window.location.href = location.search.replace('?redirect_to=', ''); break; } case 400: set400Error(response.data.error_message); break;