LoginComp.js 4.72 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
import { routesClient } from '../routesClient';
Spark's avatar
Spark committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

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
25
        maxWidth: '80%',
Spark's avatar
Spark committed
26
27
        justifyContent: 'center',
        margin: 'auto',
Spark's avatar
Spark committed
28
29
        padding: '0.5em',
        color: 'black'
Spark's avatar
Spark committed
30
31
    }

Spark's avatar
Spark committed
32
33
    const [alertShow, setAlertShow] = useState(false)
    const [emailAddress, setEmailAddress] = useState('')
Spark's avatar
Spark committed
34

35
    const [mailSend, setMailSend] = useState(false)
Spark's avatar
Spark committed
36
37

    function addressUrl() {
38
        const afterAt = emailAddress.split('@')[1]
39
40
41
42
        if (afterAt == ('naver.com' || 'gmail.com' || 'daum.net')) {
            const newLink = 'https://www.' + afterAt;
            window.open(newLink);
        }
43
        if (afterAt == 'korea.ac.kr') {
44
45
            window.open('https://www.gmail.com');
        }
46
        else {
47
48
            window.open();
        }
Spark's avatar
Spark committed
49
    }
Spark's avatar
Spark committed
50

Spark's avatar
Spark committed
51
52
53
54
    function handleChange(event) {
        setEmailAddress(event.target.value)
    }

Spark's avatar
Spark committed
55
56
    async function handleSubmit(event) {
        event.preventDefault();
Spark's avatar
Spark committed
57
        const res = await axios.post(routesClient.login, { email: emailAddress, isOauth: false })
58
59
60
61
        console.log('mail_sending : ', res.data.contents.mail_sending)
        setMailSend(res.data.contents.mail_sending)
        setAlertShow(true)
        localStorage.setItem('login', true)
Spark's avatar
Spark committed
62
63
64
    }


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

Spark's avatar
Spark committed
98
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
99
100
                        <FloatingLabel label="Email">
                            <Form.Control type="email" placeholder="Email" onChange={handleChange} required/>
Spark's avatar
Spark committed
101
                        </FloatingLabel>
102
                        <Button variant='light' className='mt-3' id='formbtn' type='submit'>
Spark's avatar
Spark committed
103
104
105
                            LOGIN
                        </Button>
                    </Form>
Spark's avatar
Spark committed
106
107
108
109
110
111
112
113
114
115
116

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

Spark's avatar
Spark committed
117
118
119
                    <Row style={{ margin: 'auto', marginBottom: '5px', display: 'flex', justifyContent: 'center' }}>
                        <a href="#;" onClick={LoginWithKakao} id='socialLink' >
                            {/* 세미콜론이 붙으면 최상단 이동 x */}
Spark's avatar
Spark committed
120
                            <img src='http://image.kmib.co.kr/online_image/2020/0626/611514110014734788_1.jpg' id='logpng' alt='KAKAO' />
Spark's avatar
Spark committed
121
122
123
124
125
126
127
128
129
130
131
                        </a>

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

        </Row>
    )
}

export default LoginComp;