Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 350626cfc3 | |||
| 8b8a1548e1 | |||
| b26dd7d574 | |||
| 3ef37b0b9e | |||
| d3d08f9892 | |||
| 618fbaf72e | |||
| 8d0c252900 | |||
| 37ef15c591 | |||
| 87e94ea6f3 | |||
| 3ba58286c0 |
@@ -2,7 +2,7 @@ PUBLIC_URL=http://localhost:3000/
|
||||
PORT=3000
|
||||
PRIMARY_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
||||
REACT_APP_BASE_LAYOUT_CONFIG_KEY='metronic-react-demo1-8150'
|
||||
REACT_APP_API_URL=https://preview.keenthemes.com/metronic8/laravel/api
|
||||
REACT_APP_API_URL=https://float-gat.dev.chiefsoft.net/en/fleetweb/api/v1/
|
||||
REACT_APP_VERSION=v8.1.5
|
||||
REACT_APP_THEME_NAME=WrenchBoard
|
||||
REACT_APP_THEME_DEMO=dashboard
|
||||
|
||||
@@ -1,10 +1,44 @@
|
||||
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||
import {useEffect} from 'react'
|
||||
import {useEffect, useState} from 'react'
|
||||
import {Outlet, Link} from 'react-router-dom'
|
||||
import {toAbsoluteUrl} from '../../../_res/helpers'
|
||||
|
||||
const AuthLayout = () => {
|
||||
|
||||
// INITIAL STATE FOR BACKGROUND IMAGE
|
||||
let [bgImage, setBgImage] = useState({
|
||||
filter: 'grayscale(0%)'
|
||||
})
|
||||
|
||||
// FUNCTION TO CHANGE BACKGROUND IMAGE
|
||||
let changeBg = () => {
|
||||
// let randomNum = Math.round(Math.random() * 3)
|
||||
let randomNum = Number(localStorage.getItem('bg-num'))
|
||||
if(randomNum){
|
||||
if(randomNum <= 1){
|
||||
setBgImage({
|
||||
filter: 'grayscale(0%)'
|
||||
})
|
||||
localStorage.setItem('bg-num', '2')
|
||||
}else if(randomNum <= 2){
|
||||
setBgImage({
|
||||
// filter: 'hue-rotate(90deg)'
|
||||
filter: 'grayscale(100%)'
|
||||
})
|
||||
localStorage.setItem('bg-num', '3')
|
||||
}else{
|
||||
setBgImage({
|
||||
filter: 'sepia(50%)'
|
||||
})
|
||||
localStorage.setItem('bg-num', '1')
|
||||
}
|
||||
}else{
|
||||
localStorage.setItem('bg-num', '2')
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
changeBg() // FUNCTION TO CHANGE BACKGROUND IMAGE
|
||||
const root = document.getElementById('root')
|
||||
if (root) {
|
||||
root.style.height = '100%'
|
||||
@@ -16,10 +50,11 @@ const AuthLayout = () => {
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className='d-flex flex-column flex-lg-row flex-column-fluid vh-100 overflow-auto' style={{backgroundImage: `url(${toAbsoluteUrl('/media/misc/float-sample.jpg')})`, backgroundSize: 'cover', backgroundPosition: 'center'}}>
|
||||
return (
|
||||
<div className='position-relative d-flex flex-column flex-lg-row flex-column-fluid overflow-hidden' style={{minHeight: '100vh'}}>
|
||||
<img src={toAbsoluteUrl('/media/misc/float-sample.jpg')} alt="" className='position-absolute top-0 left-0 w-auto h-100' style={{filter: bgImage.filter}}/>
|
||||
{/* begin::Body */}
|
||||
<div className='d-flex flex-column flex-lg-row-fluid w-lg-50 p-10 order-2 order-lg-1'>
|
||||
<div className='position-relative d-flex flex-column flex-lg-row-fluid w-lg-50 p-10 order-2 order-lg-1'>
|
||||
{/* begin::Form */}
|
||||
<div className='d-flex flex-center flex-column flex-lg-row-fluid'>
|
||||
{/* begin::Wrapper */}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {getUserByToken, login} from '../core/_requests'
|
||||
import {toAbsoluteUrl} from '../../../../_metronic/helpers'
|
||||
import {useAuth} from '../core/Auth'
|
||||
// import Logo from '../../../../../public/media/logos/favicon.ico'
|
||||
import {useNavigate} from 'react-router-dom'
|
||||
|
||||
const loginSchema = Yup.object().shape({
|
||||
email: Yup.string()
|
||||
@@ -22,8 +23,8 @@ const loginSchema = Yup.object().shape({
|
||||
})
|
||||
|
||||
const initialValues = {
|
||||
email: 'johndoe@email.com',
|
||||
password: '****',
|
||||
email: '',
|
||||
password: '',
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -33,6 +34,7 @@ const initialValues = {
|
||||
*/
|
||||
|
||||
export function Login() {
|
||||
const navigate = useNavigate()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const {saveAuth, setCurrentUser} = useAuth()
|
||||
|
||||
@@ -44,8 +46,10 @@ export function Login() {
|
||||
try {
|
||||
const {data: auth} = await login(values.email, values.password)
|
||||
saveAuth(auth)
|
||||
const {data: user} = await getUserByToken(auth.api_token)
|
||||
setCurrentUser(user)
|
||||
// const {data: user} = await getUserByToken(auth.api_token)
|
||||
// setCurrentUser(user)
|
||||
setCurrentUser(auth.profile)
|
||||
navigate('/dashboard')
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
saveAuth(undefined)
|
||||
@@ -121,11 +125,19 @@ export function Login() {
|
||||
</div>
|
||||
{/* end::Separator */}
|
||||
|
||||
{formik.status ? (
|
||||
<div className='mb-lg-15 alert alert-danger'>
|
||||
<div className='alert-text font-weight-bold'>{formik.status}</div>
|
||||
</div>
|
||||
) : (
|
||||
null
|
||||
)}
|
||||
|
||||
{/* begin::Form group */}
|
||||
<div className='fv-row mb-8'>
|
||||
<label className='form-label fs-6 fw-bolder text-dark'>Email</label>
|
||||
<input
|
||||
placeholder='Email'
|
||||
placeholder='floatuser@email.com'
|
||||
{...formik.getFieldProps('email')}
|
||||
className={clsx(
|
||||
'form-control bg-transparent',
|
||||
@@ -151,6 +163,7 @@ export function Login() {
|
||||
<label className='form-label fw-bolder text-dark fs-6 mb-0'>Password</label>
|
||||
<input
|
||||
type='password'
|
||||
placeHolder="●●●●●●"
|
||||
autoComplete='off'
|
||||
{...formik.getFieldProps('password')}
|
||||
className={clsx(
|
||||
|
||||
@@ -318,7 +318,7 @@ export function Registration() {
|
||||
<span>
|
||||
I Accept the{' '}
|
||||
<a
|
||||
href='https://keenthemes.com/metronic/?page=faq'
|
||||
href='#'
|
||||
target='_blank'
|
||||
className='ms-1 link-primary'
|
||||
>
|
||||
|
||||
@@ -69,9 +69,12 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
||||
const requestUser = async (apiToken: string) => {
|
||||
try {
|
||||
if (!didRequest.current) {
|
||||
const {data} = await getUserByToken(apiToken)
|
||||
if (data) {
|
||||
setCurrentUser(data)
|
||||
// const {data} = await getUserByToken(apiToken)
|
||||
// if (data) {
|
||||
// setCurrentUser(data)
|
||||
// }
|
||||
if(localStorage.getItem('kt-auth-react-v')){
|
||||
setCurrentUser(auth?.profile)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -86,8 +89,8 @@ const AuthInit: FC<WithChildren> = ({children}) => {
|
||||
return () => (didRequest.current = true)
|
||||
}
|
||||
|
||||
if (auth && auth.api_token) {
|
||||
requestUser(auth.api_token)
|
||||
if (auth && auth.session_token) {
|
||||
requestUser(auth.session_token)
|
||||
} else {
|
||||
logout()
|
||||
setShowSplashScreen(false)
|
||||
|
||||
@@ -52,8 +52,8 @@ export function setupAxios(axios: any) {
|
||||
axios.interceptors.request.use(
|
||||
(config: {headers: {Authorization: string}}) => {
|
||||
const auth = getAuth()
|
||||
if (auth && auth.api_token) {
|
||||
config.headers.Authorization = `Bearer ${auth.api_token}`
|
||||
if (auth && auth.session_token) {
|
||||
config.headers.Authorization = `Bearer ${auth.session_token}`
|
||||
}
|
||||
|
||||
return config
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface AuthModel {
|
||||
api_token: string
|
||||
session_token: string
|
||||
refreshToken?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ export const REQUEST_PASSWORD_URL = `${API_URL}/forgot_password`
|
||||
// Server should return AuthModel
|
||||
export function login(email: string, password: string) {
|
||||
return axios.post<AuthModel>(LOGIN_URL, {
|
||||
email,
|
||||
password,
|
||||
username: email,
|
||||
password: password,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ export function requestPassword(email: string) {
|
||||
}
|
||||
|
||||
export function getUserByToken(token: string) {
|
||||
return axios.post<UserModel>(GET_USER_BY_ACCESSTOKEN_URL, {
|
||||
api_token: token,
|
||||
return axios.get<UserModel>(GET_USER_BY_ACCESSTOKEN_URL, {
|
||||
session_token: token,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user