Home.js 3.06 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
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
LAST    
JeongYeonwoo committed
7
8
9
    let info = []
    if (JSON.parse(localStorage.getItem("Set")) === null) {
        info = [{ password: "0319", AdminPassword: "0001", Time: "30010" }]
JeongYeonwoo's avatar
JeongYeonwoo committed
10
    }
JeongYeonwoo's avatar
LAST    
JeongYeonwoo committed
11
    else {
JeongYeonwoo's avatar
JeongYeonwoo committed
12
13
14
        info = JSON.parse(localStorage.getItem("Set"))
    } //수정. 추가

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
15
    const [name, setName] = useState('')
JeongYeonwoo's avatar
JeongYeonwoo committed
16
    const [password, SetPassword] = useState('')
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
17
18
    const [done, setDone] = useState(false)

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

JeongYeonwoo's avatar
JeongYeonwoo committed
21
    const handleChangename = (event) => {
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
22
23
        setName(event.target.value)
    }
JeongYeonwoo's avatar
JeongYeonwoo committed
24
25
26
    const handleChangepassword = (event) => {
        SetPassword(event.target.value)
    }
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
27

JeongYeonwoo's avatar
JeongYeonwoo committed
28
    function handleClick() {
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
29
30
31
        if (!name) {
            alert('이름을 입력하세요')
        }
JeongYeonwoo's avatar
JeongYeonwoo committed
32
33
34
        else if (!password) {
            alert('비밀번호를 입력하세요')
        }
JeongYeonwoo's avatar
JeongYeonwoo committed
35
        else if (name === 'admin' && password === info[0].AdminPassword) {
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
36
37
38
39
40
41
            console.log('done')

            return (setAdmin(true)

            )
        }
JeongYeonwoo's avatar
JeongYeonwoo committed
42
        else if (password !== info[0].password) {
JeongYeonwoo's avatar
JeongYeonwoo committed
43
44
            alert('유효한 비밀번호를 입력하세요')
        }
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
45
        else {
JeongYeonwoo's avatar
JeongYeonwoo committed
46
            alert('입력하신 이름은 ' + name + '입니다.')
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
47
            localStorage.setItem('name', name)
JeongYeonwoo's avatar
JeongYeonwoo committed
48
            localStorage.setItem('password', password)
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
49
50
            setDone(true)
        }
JeongYeonwoo's avatar
JeongYeonwoo committed
51

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
52
53
    }

JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
54
55
56



57
    return (
JeongYeonwoo's avatar
JeongYeonwoo committed
58
        <div className="container-fluid bg-light p-5 h-100">
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
59
            {admin ? <Redirect to='/admin' /> : ''}
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
60
            {done ? <Redirect to='/quiz' /> : ''}
JeongYeonwoo's avatar
LAST    
JeongYeonwoo committed
61

JeongYeonwoo's avatar
JeongYeonwoo committed
62
            <div>
JeongYeonwoo's avatar
LAST    
JeongYeonwoo committed
63
                <h3 className="text-center pb-5 font-weight-bold text-danger" style={{ 'font-family': 'sans-serif' }}>Korea University</h3>
JeongYeonwoo's avatar
JeongYeonwoo committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
            </div>

            <div className="row justify-content-center">
                <form className="col-4 p-5 border bg-white">
                    <div>
                        <div>
                            <p className="font-weight-bold h5 pb-3">로그인</p>
                        </div>
                        <div className="form-group">
                            <label for="inputName">이름입력</label>
                            <input className="form-control" onChange={handleChangename} placeholder="Name" />
                        </div>
                        <div className="form-group">
                            <label for="inputPassword">비밀번호</label>
                            <input type='password' className="form-control" onChange={handleChangepassword} placeholder="Password" />
                        </div>
                        <div className="form-group text-center">
                            <label for="inputLogin" className="d-flex justify-content-center"> </label>
                            <button className="mt-4 btn btn-dark" onClick={handleClick}>Login</button>
JeongYeonwoo's avatar
JeongYeonwoo committed
83
84
                        </div>
                    </div>
JeongYeonwoo's avatar
JeongYeonwoo committed
85
86
87
88
                </form>
            </div>

        </div>
JeongYeonwoo's avatar
JeongYeonwoo committed
89

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
90
91
    )
}
JeongYeonwoo's avatar
JeongYeonwoo committed
92

93
export default Home;
JeongYeonwoo's avatar
JeongYeonwoo committed
94