-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from SamKomesarook/staging
Staging
- Loading branch information
Showing
43 changed files
with
822 additions
and
940 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,65 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useState, useRef } from 'react'; | ||
import bcrypt from 'bcryptjs'; | ||
import Cookies from 'js-cookie'; | ||
import App from './App'; | ||
import './#Screen.css'; | ||
|
||
const data = require('./hash/hash.json'); | ||
|
||
// read from json | ||
// Read from json | ||
const hashValue = data.find((hash) => hash.id === 1); | ||
|
||
function LoginScreen() { | ||
// password | ||
const [password, setPassword] = useState(''); | ||
const setInput = (e) => setPassword(e.target.value); | ||
const LoginScreen = () => { | ||
const passwordRef = useRef(); | ||
const [isLoggedIn, setLoggedIn] = useState(false); | ||
const [isInvalidInput, setInvalidInput] = useState(false); | ||
|
||
// login button | ||
// set the state to false | ||
const [log, setLog] = React.useState(false); | ||
const [popUp, setPopUp] = React.useState(false); | ||
// read from cookie | ||
const readCookie = () => { | ||
const user = Cookies.get('user'); | ||
if (user) { | ||
setLog(true); | ||
} | ||
}; | ||
|
||
React.useEffect(() => { | ||
readCookie(); | ||
}, []); | ||
|
||
const login = () => { | ||
// const hash = fs.readFileSync('hash.txt'); | ||
const check = bcrypt.compareSync(password, hashValue.value); | ||
const handleLogin = () => { | ||
setInvalidInput(false); | ||
const check = bcrypt.compareSync(passwordRef.current.value, hashValue.value); | ||
if (check) { | ||
setLog(true); | ||
// set cookie with 1 day expiry | ||
// Set cookie with 1 day expiry | ||
Cookies.set('user', hashValue.value, { expires: 1 }); | ||
setLoggedIn(true); | ||
} else { | ||
setPopUp(true); | ||
setInvalidInput(true); | ||
} | ||
}; | ||
|
||
if (log) { | ||
React.useEffect(() => { | ||
// Read from cookie | ||
if (Cookies.get('user')) { | ||
setLoggedIn(true); | ||
} | ||
}, []); | ||
|
||
if (isLoggedIn) { | ||
return ( | ||
<App /> | ||
); | ||
} | ||
|
||
const isMain = 'login-screen'; | ||
|
||
return ( | ||
<div className="login-container"> | ||
<div className={isMain}> | ||
<div className="login-screen"> | ||
Welcome to Rome. | ||
<input | ||
name="password-field" | ||
type="password" | ||
className={!popUp ? 'login-input' : 'login-input-invalid'} | ||
value={password} | ||
onChange={setInput} | ||
className={`login-input ${isInvalidInput ? 'login-input-invalid' : ''}`} | ||
placeholder="password" | ||
ref={passwordRef} | ||
/> | ||
<button | ||
type="submit" | ||
onClick={login} | ||
onClick={handleLogin} | ||
className="login-btn" | ||
> | ||
Go | ||
</button> | ||
</div> | ||
|
||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default LoginScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.