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

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

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

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

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

            return (setAdmin(true)

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

JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
53
54
    }

JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
55
56
57



58
    return (
JeongYeonwoo's avatar
JeongYeonwoo committed
59
        <div className="container-fluid bg-light p-5 h-100">
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
60
            {admin ? <Redirect to='/admin' /> : ''}
JeongYeonwoo's avatar
updated    
JeongYeonwoo committed
61
            {done ? <Redirect to='/quiz' /> : ''}
JeongYeonwoo's avatar
JeongYeonwoo committed
62
            
JeongYeonwoo's avatar
JeongYeonwoo committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
            <div>
                <h3 className="text-center pb-5 font-weight-bold text-danger" style={{'font-family':'sans-serif'}}>Korea University</h3>
            </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
84
85
                        </div>
                    </div>
JeongYeonwoo's avatar
JeongYeonwoo committed
86
87
88
89
                </form>
            </div>

        </div>
JeongYeonwoo's avatar
JeongYeonwoo committed
90

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

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