Home.js 3 KB
Newer Older
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
1
import React, { useState } from 'react'
baesangjune's avatar
baesangjune committed
2
import { Redirect } from 'react-router-dom';
Jiwon Yoon's avatar
Jiwon Yoon committed
3

baesangjune's avatar
baesangjune committed
4
function Home() {
Jiwon Yoon's avatar
ASD    
Jiwon Yoon committed
5
6
7
8
9
10
11
12
13
    
    let info=[]
    if(JSON.parse(localStorage.getItem("Set")) === null){
        info=[{password:"0319", AdminPassword:"0001",Time : "30010"}] //수정.추가
    }
    else{
        info = JSON.parse(localStorage.getItem("Set"))
    } //수정. 추가

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

baesangjune's avatar
baesangjune committed
18
19
    const [admin, setAdmin] = useState(false);

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

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

            return (setAdmin(true)

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

baesangjune's avatar
baesangjune committed
51
52
    }

baesangjune's avatar
baesangjune committed
53
54
55



Jiwon Yoon's avatar
Jiwon Yoon committed
56
    return (
Jiwon Yoon's avatar
ha..    
Jiwon Yoon committed
57
        <div className="container-fluid bg-light p-5 h-100">
baesangjune's avatar
baesangjune committed
58
            {admin ? <Redirect to='/admin' /> : ''}
baesangjune's avatar
baesangjune committed
59
            {done ? <Redirect to='/quiz' /> : ''}
Jiwon Yoon's avatar
ha..    
Jiwon Yoon committed
60
61
62
63
64
65
66
67
68
69
70
            
            <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>
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
71
72
73
74
75
76
77
78
79
80
81
                        <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>
baesangjune's avatar
css    
baesangjune committed
82
83
                        </div>
                    </div>
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
84
85
86
                </form>
            </div>

Jiwon Yoon's avatar
ha..    
Jiwon Yoon committed
87
        </div>
baesangjune's avatar
home    
baesangjune committed
88

Jiwon Yoon's avatar
Jiwon Yoon committed
89
90
    )
}
baesangjune's avatar
baesangjune committed
91

baesangjune's avatar
baesangjune committed
92
export default Home;