LoginComp.js 4.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import React, { useState } from "react";
import "../App.css";
import {
  Form,
  Button,
  Row,
  Col,
  Card,
  Alert,
  FloatingLabel,
} from "react-bootstrap";
import { AuthWithKakao } from "../utils/Oauth";
import axios from "axios";
import { routesClient } from "../routesClient";
Spark's avatar
Spark committed
15
16

function LoginComp() {
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  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",
    maxWidth: "80%",
    justifyContent: "center",
    margin: "auto",
    padding: "0.5em",
    color: "black",
  };

  const [alertShow, setAlertShow] = useState(false);
  const [emailAddress, setEmailAddress] = useState("");

  const [mailSend, setMailSend] = useState(false);

  function addressUrl() {
    const afterAt = emailAddress.split("@")[1];
    if (afterAt) {
      const newLink = "https://www." + afterAt;
      window.location.replace(newLink);
Spark's avatar
Spark committed
49
    }
50
51
    if (afterAt === "korea.ac.kr") {
      window.location.replace("https://www.gmail.com");
Spark's avatar
Spark committed
52
    }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  }

  function handleChange(event) {
    setEmailAddress(event.target.value);
  }

  async function handleSubmit(event) {
    event.preventDefault();
    const res = await axios.post(routesClient.login, {
      email: emailAddress,
      isOauth: false,
    });
    console.log("mail_sending : ", res.data.contents.mail_sending);
    setMailSend(res.data.contents.mail_sending);
    setAlertShow(true);
    localStorage.setItem("login", true);
  }

  return (
    <Row className="text-center w-100 my-2">
      <Card style={cardstyled}>
        <Card.Title id="impactTitle">로그인</Card.Title>
        <Card.Subtitle style={{ fontWeight: "lighter" }}>
          이메일 또는 소셜미디어로 로그인하세요
        </Card.Subtitle>
        <hr />
        <Card.Text>
          <Row
            className="m-auto d-flex justify-content-center"
            style={{ width: "80%" }}
          >
            {mailSend ? (
              <Alert show={alertShow} variant={"success"}>
                <Col>😍 이메일 전송이 완료 되었습니다.</Col>
                <Alert.Link
                  href=""
                  onClick={addressUrl}
                  target="_blank"
                  style={{ fontSize: "0.8em" }}
                >
                  이메일 확인 하러가기 
                </Alert.Link>
              </Alert>
            ) : (
              <Alert show={alertShow} variant={"danger"}>
                <Col>😭 이메일을 정확하게 적어주세요.</Col>
                <Alert.Link
                  href="/signup"
                  target="_blank"
                  style={{ fontSize: "0.8em" }}
                >
                  회원가입 하러가기 
                </Alert.Link>
              </Alert>
            )}
          </Row>

          <Form style={inboxstyled} onSubmit={handleSubmit}>
            <FloatingLabel label="Email">
              <Form.Control
                type="email"
                placeholder="Email"
                onChange={handleChange}
                required
              />
            </FloatingLabel>
            <Button variant="light" className="mt-3" id="formbtn" type="submit">
              로그인
            </Button>
          </Form>

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

          <Row
            style={{
              margin: "auto",
              marginBottom: "5px",
              display: "flex",
              justifyContent: "center",
            }}
          >
            <a href="#;" onClick={() => AuthWithKakao(true)} id="socialLink">
              {/* 세미콜론이 붙으면 최상단 이동 x */}
              <img
                src="http://image.kmib.co.kr/online_image/2020/0626/611514110014734788_1.jpg"
                id="logpng"
                alt="KAKAO"
              />
            </a>
          </Row>
        </Card.Text>
      </Card>
    </Row>
  );
Spark's avatar
Spark committed
155
156
}

157
export default LoginComp;