radivoje.milutinovic 3 лет назад
Родитель
Сommit
fa36fdd099

+ 3
- 0
src/AppRoutes.js Просмотреть файл

MY_OFFERS_PAGE, MY_OFFERS_PAGE,
// PRICES_PAGE, // PRICES_PAGE,
ABOUT_PAGE, ABOUT_PAGE,
ADMIN_HOME_PAGE,
// POLICY_PRIVACY_PAGE, // POLICY_PRIVACY_PAGE,
} from "./constants/pages"; } from "./constants/pages";
import LoginPage from "./pages/LoginPage/LoginPage"; import LoginPage from "./pages/LoginPage/LoginPage";
// import PricesPage from "./pages/Prices/PricesPage"; // import PricesPage from "./pages/Prices/PricesPage";
import AboutPage from "./pages/About/AboutPage"; import AboutPage from "./pages/About/AboutPage";
import AuthRoute from "./components/Router/AuthRoute"; import AuthRoute from "./components/Router/AuthRoute";
import AdminHomePage from "./pages/AdminHomePage/AdminHomePage";
// import PrivacyPolicyPage from "./pages/PrivacyPolicy/PrivacyPolicyPage"; // import PrivacyPolicyPage from "./pages/PrivacyPolicy/PrivacyPolicyPage";


const AppRoutes = () => { const AppRoutes = () => {
<Route exact path={BASE_PAGE} component={HomePage} /> <Route exact path={BASE_PAGE} component={HomePage} />
<AuthRoute exact path={LOGIN_PAGE} component={LoginPage} /> <AuthRoute exact path={LOGIN_PAGE} component={LoginPage} />
<AuthRoute exact path={ADMIN_LOGIN_PAGE} component={AdminLoginPage} /> <AuthRoute exact path={ADMIN_LOGIN_PAGE} component={AdminLoginPage} />
<Route path={ADMIN_HOME_PAGE} component={AdminHomePage} />
<Route path={NOT_FOUND_PAGE} component={NotFoundPage} /> <Route path={NOT_FOUND_PAGE} component={NotFoundPage} />
<Route path={ERROR_PAGE} component={ErrorPage} /> <Route path={ERROR_PAGE} component={ErrorPage} />
<AuthRoute path={REGISTER_SUCCESSFUL_PAGE} component={RegisterSuccessful} /> <AuthRoute path={REGISTER_SUCCESSFUL_PAGE} component={RegisterSuccessful} />

+ 8
- 1
src/components/Login/Login.js Просмотреть файл

fetchLogin, fetchLogin,
} from "../../store/actions/login/loginActions"; } from "../../store/actions/login/loginActions";
import { selectLoginError } from "../../store/selectors/loginSelectors"; import { selectLoginError } from "../../store/selectors/loginSelectors";
import { HOME_PAGE } from "../../constants/pages";
import { HOME_PAGE, ADMIN_HOME_PAGE } from "../../constants/pages";
import { ReactComponent as Logo } from "../../assets/images/svg/logo-vertical.svg"; import { ReactComponent as Logo } from "../../assets/images/svg/logo-vertical.svg";
import { ReactComponent as LogoAdmin } from "../../assets/images/svg/logo-vertical-admin.svg"; import { ReactComponent as LogoAdmin } from "../../assets/images/svg/logo-vertical-admin.svg";
import { LoginPageContainer, LoginFormContainer } from "./Login.styled"; import { LoginPageContainer, LoginFormContainer } from "./Login.styled";


// Api response callback function on success // Api response callback function on success
const handleApiResponseSuccess = () => { const handleApiResponseSuccess = () => {
props.isAdmin ? history.push({
pathname: ADMIN_HOME_PAGE,
state: {
from: history.location.pathname,
},
}) :
history.push({ history.push({
pathname: HOME_PAGE, pathname: HOME_PAGE,
state: { state: {
password, password,
handleApiResponseSuccess, handleApiResponseSuccess,
handleApiResponseError, handleApiResponseError,
isAdmin: props.isAdmin
}) })
); );
} }

+ 1
- 0
src/constants/pages.js Просмотреть файл

export const ABOUT_PAGE = "/about"; export const ABOUT_PAGE = "/about";
export const PRICES_PAGE = "/prices"; export const PRICES_PAGE = "/prices";
export const POLICY_PRIVACY_PAGE = "/policy"; export const POLICY_PRIVACY_PAGE = "/policy";
export const ADMIN_HOME_PAGE = "/admin/home";

+ 14
- 0
src/pages/AdminHomePage/AdminHomePage.js Просмотреть файл

import React from 'react'
import PropTypes from 'prop-types'

const AdminHomePage = () => {
return (
<div>Admin home page brateee</div>
)
}

AdminHomePage.propTypes = {
children: PropTypes.node,
}

export default AdminHomePage

+ 8
- 0
src/store/saga/loginSaga.js Просмотреть файл



function* fetchLogin({ payload }) { function* fetchLogin({ payload }) {
try { try {
const isAdmin = payload.isAdmin;
// delete payload.isAdmin
const { data } = yield call(attemptLogin, payload); const { data } = yield call(attemptLogin, payload);
if (data.token) { if (data.token) {
const token = data.token; const token = data.token;
const refresh = data.refresh; const refresh = data.refresh;
const tokenDecoded = jwt.decode(token); const tokenDecoded = jwt.decode(token);
const refreshDecoded = jwt.decode(refresh); const refreshDecoded = jwt.decode(refresh);
if(isAdmin && !tokenDecoded.roles.includes("Admin")){
throw Error("Not an admin login on /login");
}
const accessToken = { const accessToken = {
token: token, token: token,
exp: tokenDecoded.exp, exp: tokenDecoded.exp,
} }
} }
} catch (e) { } catch (e) {
if(e.message){
yield put(fetchUserError(e.message));
}
if (e.response && e.response.data) { if (e.response && e.response.data) {
if (payload.handleApiResponseError) { if (payload.handleApiResponseError) {
yield call(payload.handleApiResponseError, e.response.status); yield call(payload.handleApiResponseError, e.response.status);

+ 3
- 1
src/util/helpers/routeHelpers.js Просмотреть файл

import { import {
ADMIN_LOGIN_PAGE,
FORGOT_PASSWORD_MAIL_SENT, FORGOT_PASSWORD_MAIL_SENT,
FORGOT_PASSWORD_PAGE, FORGOT_PASSWORD_PAGE,
LOGIN_PAGE, LOGIN_PAGE,
routeMatches(REGISTER_SUCCESSFUL_PAGE) || routeMatches(REGISTER_SUCCESSFUL_PAGE) ||
routeMatches(FORGOT_PASSWORD_PAGE) || routeMatches(FORGOT_PASSWORD_PAGE) ||
routeMatches(FORGOT_PASSWORD_MAIL_SENT) || routeMatches(FORGOT_PASSWORD_MAIL_SENT) ||
routeMatches(RESET_PASSWORD_PAGE)
routeMatches(RESET_PASSWORD_PAGE) ||
routeMatches(ADMIN_LOGIN_PAGE)
) { ) {
return true; return true;
} }

Загрузка…
Отмена
Сохранить