Browse Source

user role added

master
kris@sentientgeeks.com 3 years ago
parent
commit
70ed1e2a65
14 changed files with 64 additions and 19 deletions
  1. +1
    -1
      src/@core/auth/utils.js
  2. +0
    -4
      src/@core/layouts/components/footer/index.js
  3. +1
    -1
      src/@core/layouts/components/menu/horizontal-menu/index.js
  4. +3
    -2
      src/@core/layouts/components/navbar/UserDropdown.js
  5. +9
    -1
      src/auth/utils.js
  6. +10
    -0
      src/navigation/horizontal/clientHome.js
  7. +8
    -1
      src/navigation/horizontal/index.js
  8. +4
    -3
      src/navigation/vertical/index.js
  9. +2
    -4
      src/router/Router.js
  10. +5
    -0
      src/router/routes/Pages.js
  11. +8
    -1
      src/utility/Utils.js
  12. +12
    -0
      src/views/apps/client/dashboard/index.js
  13. +1
    -0
      src/views/apps/todo/index.js
  14. +0
    -1
      src/views/pages/authentication/Login.js

+ 1
- 1
src/@core/auth/utils.js View File

@ -22,6 +22,6 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
*/ */
export const getHomeRouteForLoggedInUser = userRole => { export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/' if (userRole === 'admin') return '/'
if (userRole === 'client') return { name: 'access-control' }
if (userRole === 'client') return '/'
return { name: 'auth-login' } return { name: 'auth-login' }
} }

+ 0
- 4
src/@core/layouts/components/footer/index.js View File

@ -11,10 +11,6 @@ const Footer = () => {
</a> </a>
<span className='d-none d-sm-inline-block'>, All rights Reserved</span> <span className='d-none d-sm-inline-block'>, All rights Reserved</span>
</span> </span>
<span className='float-md-right d-none d-md-block'>
Hand-crafted & Made with
<Heart size={14} />
</span>
</p> </p>
) )
} }


+ 1
- 1
src/@core/layouts/components/menu/horizontal-menu/index.js View File

@ -1,5 +1,5 @@
// ** React Imports // ** React Imports
import { useState } from 'react'
import React, { useState, useEffect, lazy } from 'react'
// ** Horizontal Menu Array // ** Horizontal Menu Array
import navigation from '@src/navigation/horizontal' import navigation from '@src/navigation/horizontal'


+ 3
- 2
src/@core/layouts/components/navbar/UserDropdown.js View File

@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
import Avatar from '@components/avatar' import Avatar from '@components/avatar'
// ** Utils // ** Utils
import { isUserLoggedIn } from '@utils'
import { isUserLoggedIn, getUserData } from '@utils'
// ** Store & Actions // ** Store & Actions
import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux'
@ -50,11 +50,12 @@ const UserDropdown = () => {
<User size={14} className='mr-75' /> <User size={14} className='mr-75' />
<span className='align-middle'>Profile</span> <span className='align-middle'>Profile</span>
</DropdownItem> </DropdownItem>
{getUserData.role === "admin" &&
<DropdownItem tag={Link} to='/apps/todo'> <DropdownItem tag={Link} to='/apps/todo'>
<CheckSquare size={14} className='mr-75' /> <CheckSquare size={14} className='mr-75' />
<span className='align-middle'>Tasks</span> <span className='align-middle'>Tasks</span>
</DropdownItem> </DropdownItem>
}
<DropdownItem divider /> <DropdownItem divider />
<DropdownItem tag={Link} to='/pages/account-settings'> <DropdownItem tag={Link} to='/pages/account-settings'>
<Settings size={14} className='mr-75' /> <Settings size={14} className='mr-75' />


+ 9
- 1
src/auth/utils.js View File

@ -1,4 +1,5 @@
import useJwt from '@src/@core/auth/jwt/useJwt' import useJwt from '@src/@core/auth/jwt/useJwt'
import { DefaultRoute } from '../router/routes'
/** /**
* Return if user is logged in * Return if user is logged in
@ -10,6 +11,13 @@ export const isUserLoggedIn = () => {
return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName) return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName)
} }
export const getDefaultRoute = () => {
const userdata = JSON.parse(localStorage.getItem("userData"))
const userrole = userdata === null ? '' : userdata.role
const redirect = (userrole === "admin") ? DefaultRoute : ((userrole === "client") ? '/client' : '/home')
return redirect
}
export const getUserData = () => JSON.parse(localStorage.getItem('userData')) export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
/** /**
@ -22,6 +30,6 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
*/ */
export const getHomeRouteForLoggedInUser = userRole => { export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/' if (userRole === 'admin') return '/'
if (userRole === 'client') return { name: 'access-control' }
if (userRole === 'client') return '/'
return { name: 'auth-login' } return { name: 'auth-login' }
} }

+ 10
- 0
src/navigation/horizontal/clientHome.js View File

@ -0,0 +1,10 @@
import { Home, Activity, ShoppingCart } from 'react-feather'
export default [
{
id: 'client',
title: 'Dashboard',
icon: <Home />,
navLink: '/client'
}
]

+ 8
- 1
src/navigation/horizontal/index.js View File

@ -1,7 +1,14 @@
// ** Navigation sections imports // ** Navigation sections imports
import apps from './apps' import apps from './apps'
import dashboards from './dashboards' import dashboards from './dashboards'
import clientHome from './clientHome'
const userdata = JSON.parse(localStorage.getItem("userData"))
const userrole = userdata === null ? '' : userdata.role
// ** Merge & Export // ** Merge & Export
export default [...dashboards, ...apps]
const navarr = (userrole === "admin") ? [...dashboards, ...apps] : ((userrole === "client") ? [...clientHome] : [])
console.log(userrole)
console.log(navarr)
export default navarr

+ 4
- 3
src/navigation/vertical/index.js View File

@ -1,8 +1,9 @@
// ** Navigation sections imports // ** Navigation sections imports
import apps from './apps' import apps from './apps'
import dashboards from './dashboards' import dashboards from './dashboards'
const userdata = JSON.parse(localStorage.getItem("userData"))
const userrole = userdata === null ? '' : userdata.role
// ** Merge & Export // ** Merge & Export
export default [...dashboards, ...apps]
const navarr = (userrole === "admin") ? [...dashboards, ...apps] : ((userrole === "client") ? [...dashboards] : [])
export default navarr

+ 2
- 4
src/router/Router.js View File

@ -2,7 +2,7 @@
import { Suspense, useContext, lazy } from 'react' import { Suspense, useContext, lazy } from 'react'
// ** Utils // ** Utils
import { isUserLoggedIn } from '@utils'
import { isUserLoggedIn, getDefaultRoute } from '@utils'
import { useLayout } from '@hooks/useLayout' import { useLayout } from '@hooks/useLayout'
import { AbilityContext } from '@src/utility/context/Can' import { AbilityContext } from '@src/utility/context/Can'
import { useRouterTransition } from '@hooks/useRouterTransition' import { useRouterTransition } from '@hooks/useRouterTransition'
@ -85,11 +85,9 @@ const Router = () => {
** If user is not Logged in & route.meta.authRoute, !route.meta.publicRoute are undefined ** If user is not Logged in & route.meta.authRoute, !route.meta.publicRoute are undefined
** Then redirect user to login ** Then redirect user to login
*/ */
return <Redirect to='/login' /> return <Redirect to='/login' />
} else if (route.meta && route.meta.authRoute && isUserLoggedIn()) { } else if (route.meta && route.meta.authRoute && isUserLoggedIn()) {
// ** If route has meta and authRole and user is Logged in then redirect user to home page (DefaultRoute) // ** If route has meta and authRole and user is Logged in then redirect user to home page (DefaultRoute)
return <Redirect to='/' /> return <Redirect to='/' />
// } else if (isUserLoggedIn() && !ability.can(action || 'read', resource)) { // } else if (isUserLoggedIn() && !ability.can(action || 'read', resource)) {
// // ** If user is Logged in and doesn't have ability to visit the page redirect the user to Not Authorized // // ** If user is Logged in and doesn't have ability to visit the page redirect the user to Not Authorized
@ -197,7 +195,7 @@ const Router = () => {
exact exact
path='/' path='/'
render={() => { render={() => {
return isUserLoggedIn() ? <Redirect to={DefaultRoute} /> : <Redirect to='/login' />
return isUserLoggedIn() ? <Redirect to={getDefaultRoute()} /> : <Redirect to='/login' />
}} }}
/> />
{/* Not Auth Route */} {/* Not Auth Route */}


+ 5
- 0
src/router/routes/Pages.js View File

@ -130,6 +130,11 @@ const PagesRoutes = [
meta: { meta: {
navLink: '/account/view' navLink: '/account/view'
} }
},
{
path: '/client',
exact: true,
component: lazy(() => import('../../views/apps/client/dashboard'))
} }
] ]


+ 8
- 1
src/utility/Utils.js View File

@ -1,3 +1,4 @@
import { DefaultRoute } from '../router/routes'
// ** Checks if an object is empty (returns boolean) // ** Checks if an object is empty (returns boolean)
export const isObjEmpty = obj => Object.keys(obj).length === 0 export const isObjEmpty = obj => Object.keys(obj).length === 0
@ -50,6 +51,12 @@ export const formatDateToMonthShort = (value, toTimeForCurrentDay = true) => {
*/ */
export const isUserLoggedIn = () => localStorage.getItem('userData') export const isUserLoggedIn = () => localStorage.getItem('userData')
export const getUserData = () => JSON.parse(localStorage.getItem('userData')) export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
export const getDefaultRoute = () => {
const userdata = JSON.parse(localStorage.getItem("userData"))
const userrole = userdata === null ? '' : userdata.role
const redirect = (userrole === "admin") ? DefaultRoute : ((userrole === "client") ? '/client' : '/home')
return redirect
}
/** /**
** This function is used for demo purpose route navigation ** This function is used for demo purpose route navigation
@ -61,7 +68,7 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
*/ */
export const getHomeRouteForLoggedInUser = userRole => { export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/' if (userRole === 'admin') return '/'
if (userRole === 'client') return '/access-control'
if (userRole === 'client') return '/'
return '/login' return '/login'
} }


+ 12
- 0
src/views/apps/client/dashboard/index.js View File

@ -0,0 +1,12 @@
import { Fragment } from "react"
const clientDashboard = () => {
return (
<Fragment>
<h3>CLIENT DASHBOARD</h3>
</Fragment>
)
}
export default clientDashboard

+ 1
- 0
src/views/apps/todo/index.js View File

@ -53,6 +53,7 @@ const TODO = () => {
) )
}, [store.tasks.length, paramsURL.filter, paramsURL.tag, query, sort]) }, [store.tasks.length, paramsURL.filter, paramsURL.tag, query, sort])
return ( return (
<Fragment> <Fragment>
<Sidebar <Sidebar


+ 0
- 1
src/views/pages/authentication/Login.js View File

@ -85,7 +85,6 @@ const Login = props => {
</Col> </Col>
<Col className='d-flex align-items-center auth-bg px-2 p-lg-5' lg='4' sm='12'> <Col className='d-flex align-items-center auth-bg px-2 p-lg-5' lg='4' sm='12'>
<Col className='px-xl-2 mx-auto' sm='8' md='6' lg='12'> <Col className='px-xl-2 mx-auto' sm='8' md='6' lg='12'>
<CardText className='mb-2'>Please sign-in to your account and start the adventure</CardText> <CardText className='mb-2'>Please sign-in to your account and start the adventure</CardText>
<Alert color='primary'> <Alert color='primary'>
<div className='alert-body font-small-2'> <div className='alert-body font-small-2'>


Loading…
Cancel
Save