Home.js 2.67 KB
Newer Older
JeongYeonwoo's avatar
JeongYeonwoo committed
1
2
// import bg from './img_study.jpg'
// import korea from './img_korea.jpg'
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
3
import React, { useState} from 'react'
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
4
import { Redirect } from 'react-router-dom';
JeongYeonwoo's avatar
JeongYeonwoo committed
5

6
function Home() {
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
7
    const [name, setName] = useState('')
JeongYeonwoo's avatar
JeongYeonwoo committed
8
    const [password, SetPassword] = useState('')
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
9
10
    const [done, setDone] = useState(false)

JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
11
12
    const [admin, setAdmin] = useState(false);

JeongYeonwoo's avatar
JeongYeonwoo committed
13
    const handleChangename = (event) => {
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
14
15
        setName(event.target.value)
    }
JeongYeonwoo's avatar
JeongYeonwoo committed
16
17
18
    const handleChangepassword = (event) => {
        SetPassword(event.target.value)
    }
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
19

JeongYeonwoo's avatar
JeongYeonwoo committed
20
    function handleClick() {
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
21
22
23
        if (!name) {
            alert('이름을 입력하세요')
        }
JeongYeonwoo's avatar
JeongYeonwoo committed
24
25
26
        else if (!password) {
            alert('비밀번호를 입력하세요')
        }
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
27
28
29
30
31
32
33
34
        else if (name === 'admin' && password === '0001') {
            console.log('done')

            return (setAdmin(true)

            )
        }
        else if (password !== '0319') {
JeongYeonwoo's avatar
JeongYeonwoo committed
35
36
            alert('유효한 비밀번호를 입력하세요')
        }
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
37
        else {
JeongYeonwoo's avatar
JeongYeonwoo committed
38
            alert('입력하신 이름은 ' + name + '입니다.')
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
39
            localStorage.setItem('name', name)
JeongYeonwoo's avatar
JeongYeonwoo committed
40
            localStorage.setItem('password', password)
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
41
42
            setDone(true)
        }
JeongYeonwoo's avatar
JeongYeonwoo committed
43

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
44
45
    }

JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
46
47
48



49
50
    return (
        <>
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
51
            {admin ? <Redirect to='/admin' /> : ''}
JeongYeonwoo's avatar
JeongYeonwoo committed
52

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
53
            {done ? <Redirect to='/quiz' /> : ''}
JeongYeonwoo's avatar
JeongYeonwoo committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
            <h1 className="h-3 mb-5 mx-3 text-center bg-danger py-2">
                KOREA UNIVERSITY
            </h1>
            
            <form className="d-flex justify-content-center">

                <div className="table table-bordered" style={{width: "400px" }}>

                    <label for="inputId" className="d-flex justify-content-center" >
                        정보 입력
                    </label>
                    <div className="form-group text-center">
                        <label for="inputName">
                            이름입력<input className="ml-3 inputBox" onChange={handleChangename} placeholder="Name"/>
                        </label>

                        <label for="inputPassword">
                            비밀번호<input type='password' className="ml-3 inputBox" onChange={handleChangepassword} placeholder="Password"/>
                        </label>
                        <div className="form-group for login">
                            <label for="inputLogin" className="d-flex justify-content-center">
                                <button className="mt-4 btn btn-dark" onClick={handleClick}>Login</button>
                            </label>
                        </div>
                    </div>
                </div>
            </form>
81
        </>
JeongYeonwoo's avatar
JeongYeonwoo committed
82

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
83
84
    )
}
JeongYeonwoo's avatar
JeongYeonwoo committed
85

86
export default Home;
JeongYeonwoo's avatar
JeongYeonwoo committed
87