LoginComp.js 5.01 KB
Newer Older
Spark's avatar
Spark committed
1
import React, { useState } from 'react';
Spark's avatar
Spark committed
2
import '../App.css'
Spark's avatar
Spark committed
3
import { Form, Button, Row, Col, Card, Alert, FloatingLabel } from 'react-bootstrap';
Spark's avatar
Spark committed
4
import { LoginWithKakao } from '../utils/Oauth';
Spark's avatar
Spark committed
5
import axios from 'axios';
Spark's avatar
Spark committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

function LoginComp() {

    const cardstyled = {
        margin: 'auto',
        padding: '1em',
        display: 'flex',
        justifyContent: 'center',
        width: '100%',
        borderWidth: '3px',
        borderRadius: '20px',
        borderColor: 'rgb(110, 189, 142)',
        color: '#04AB70'
    }

    const inboxstyled = {
        display: 'flex',
        flexDirection: 'column',
Spark's avatar
Spark committed
24
        maxWidth: '80%',
Spark's avatar
Spark committed
25
26
        justifyContent: 'center',
        margin: 'auto',
Spark's avatar
Spark committed
27
28
        padding: '0.5em',
        color: 'black'
Spark's avatar
Spark committed
29
30
    }

Spark's avatar
Spark committed
31
32
    const [emailSentAlert, setEmailSentAlert] = useState(false)
    const [alertShow, setAlertShow] = useState(false)
Spark's avatar
Spark committed
33

Spark's avatar
Spark committed
34
    const [emailAddress, setEmailAddress] = useState('')
Spark's avatar
Spark committed
35

Spark's avatar
Spark committed
36
37
38
    function CheckEmailSend() {
        localStorage.setItem('login_email_Address', emailAddress)
        const emailIs = localStorage.getItem('login_email_Address').split('@')[1]
Spark's avatar
Spark committed
39
        if (emailIs) {
Spark's avatar
Spark committed
40
41
42
43
44
45
46
            setAlertShow(true)
            setEmailSentAlert(false)
        }
        else {
            setAlertShow(true)
            setEmailSentAlert(true)
        }
Spark's avatar
Spark committed
47
48
49
    }

    function addressUrl() {
Spark's avatar
Spark committed
50
        const afterAt = localStorage.getItem('login_email_Address').split('@')[1]
51
52
53
54
55
56
57
58
59
60
        if (afterAt == ('naver.com' || 'gmail.com' || 'daum.net')) {
            const newLink = 'https://www.' + afterAt;
            window.open(newLink);
        }
        if (afterAt == 'korea.ac.kr' ) {
            window.open('https://www.gmail.com');
        }
        else { 
            window.open();
        }
Spark's avatar
Spark committed
61
    }
Spark's avatar
Spark committed
62

Spark's avatar
Spark committed
63
64
65
66
    function handleChange(event) {
        setEmailAddress(event.target.value)
    }

Spark's avatar
Spark committed
67
68
69
70
71
72
73
74
75
    console.log(emailAddress)

    async function handleSubmit(event) {
        event.preventDefault();
        const res = await axios.post("/api/login", { email: emailAddress })
        console.log(res)
    }


Spark's avatar
Spark committed
76
77
78
    return (
        <Row className='text-center w-100 my-2'>
            <Card style={cardstyled}>
Spark's avatar
Spark committed
79
                <Card.Title id='impactTitle'>
Spark's avatar
Spark committed
80
81
                    LOGIN
                </Card.Title>
Spark's avatar
Spark committed
82
83
84
                <Card.Subtitle style={{ fontWeight: 'lighter' }}>
                    Log in with your social media account or email address
                </Card.Subtitle>
Spark's avatar
Spark committed
85
86
                <hr />
                <Card.Text>
Spark's avatar
Spark committed
87
                    <Row className='m-auto d-flex justify-content-center' style={{ width: '80%' }}>
Spark's avatar
Spark committed
88
                        {!emailSentAlert ?
Spark's avatar
Spark committed
89
90
91
92
                            <Alert show={alertShow} variant={'success'}>
                                <Col>
                                    😍 이메일 전송이 완료 되었습니다.
                                </Col>
Spark's avatar
Spark committed
93
                                <Alert.Link href="" onClick={addressUrl} target='_blank' style={{ fontSize: '0.8em' }}>
Spark's avatar
Spark committed
94
95
96
97
98
99
100
101
                                    이메일 확인 하러가기 
                                </Alert.Link>
                            </Alert>
                            :
                            <Alert show={alertShow} variant={'danger'}>
                                <Col>
                                    😭 이메일을 정확하게 적어주세요.
                                </Col>
Spark's avatar
Spark committed
102
103
104
                                <Alert.Link href="/signup" target='_blank' style={{ fontSize: '0.8em' }}>
                                    회원가입 하러가기 
                                </Alert.Link>
Spark's avatar
Spark committed
105
106
107
                            </Alert>
                        }
                    </Row>
Spark's avatar
Spark committed
108

Spark's avatar
Spark committed
109
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
Spark's avatar
Spark committed
110
111
112
                        <FloatingLabel
                            label="Email"
                        >
Spark's avatar
Spark committed
113
                            <Form.Control type="email" placeholder="Email" onChange={handleChange} />
Spark's avatar
Spark committed
114
115

                        </FloatingLabel>
Spark's avatar
Spark committed
116
                        <Button variant='light' className='mt-3' id='formbtn' onClick={CheckEmailSend} type='submit'>
Spark's avatar
Spark committed
117
118
119
                            LOGIN
                        </Button>
                    </Form>
Spark's avatar
Spark committed
120
121
122
123
124
125
126
127
128
129
130

                    <Row className='d-flex align-items-center m-2'>
                        <Col>
                            <hr />
                        </Col>
                        OR
                        <Col>
                            <hr />
                        </Col>
                    </Row>

Spark's avatar
Spark committed
131
132
133
                    <Row style={{ margin: 'auto', marginBottom: '5px', display: 'flex', justifyContent: 'center' }}>
                        <a href="#;" onClick={LoginWithKakao} id='socialLink' >
                            {/* 세미콜론이 붙으면 최상단 이동 x */}
Spark's avatar
Spark committed
134
                            <img src='http://image.kmib.co.kr/online_image/2020/0626/611514110014734788_1.jpg' id='logpng' alt='KAKAO' />
Spark's avatar
Spark committed
135
136
137
138
139
140
141
142
143
144
145
                        </a>

                    </Row>
                </Card.Text>
            </Card>

        </Row>
    )
}

export default LoginComp;