Commit 042b0a4e authored by seoyeon's avatar seoyeon
Browse files

0724

parent d9089b86
import { useEffect, useState } from "react";
import { Redirect } from "react-router-dom";
import userApi from "../apis/user.api";
// import catchErrors from "../context/catchError";
const INIT_USER = {
email: "",
password: "",
......@@ -25,6 +26,7 @@ const Login = () => {
async function handleSubmit(e) {
e.preventDefault();
console.log('로그인')
try {
// setLoading(true);
// setError("");
......@@ -37,12 +39,9 @@ const Login = () => {
// setLoading(false);
}
}
if (success) {
return <Redirect to="/user" />;
}
if (success) {
alert('로그인 되었습니다')
return <Redirect to="/user" />;
}
const { email, password } = user;
......
import axios from "axios";
import { useEffect, useState } from "react";
import { Redirect } from "react-router-dom";
import userApi from "../apis/user.api";
// import catchErrors from "../context/catchError";
// import auth from "../context/auth_context"
const INIT_USER = {
name: "",
idNumber1: "",
......@@ -16,6 +19,7 @@ const Signup = () => {
const [error, setError] = useState("");
const [disabled, setDisabled] = useState(false);
const [success, setSuccess] = useState(false);
const [loading, setLoading] = useState(false);
useEffect(() => {
setDisabled(
......@@ -38,21 +42,23 @@ const Signup = () => {
async function handleSubmit() {
try {
const data = await axios.post("https://localhost:8080/api/room/1/1",user)
// setLoading(true);
// setError("");
const data = await userApi.signup(user)
// const data = await axios.post("https://localhost:8080/api/room/1/1",user)
setLoading(true);
setError("");
// const success = await login(user.email, user.password);
console.log(data);
setSuccess(success);
// sestSuccess(success);
} catch (error) {
// catchErrors(error, setError);
} finally {
// setLoading(false);
setLoading(false);
}
}
if (success) {
alert('회원가입 되었습니다.')
return <Redirect to="/" />;
}
......
function catchErrors(error, displayError) {
let errorMsg
if (error.response) {
errorMsg = error.response.data
console.log(errorMsg)
}else if (error.requset) {
errorMsg = error.requset
console.log(errorMsg)
} else {
errorMsg = error.message
console.log(errorMsg)
}
displayError(errorMsg)
}
export default catchErrors
......@@ -45,8 +45,35 @@ const login = async (req, res) => {
const signup = async (req, res) => {
try {
console.log("sign up= ", req.body);
const { id, name, email, password, gender, phone } = req.body;
const user = User.create({ id, name, email, password, gender, phone });
const { name, email, password, gender, phone } = req.body;
const id = Math.floor(( Math.random() * (9999 - 1000) + 1000 ));
console.log('id:', id)
const Id = await User.findOne({ where: { id: id }})
console.log("Id 중복확인:", Id)
while (Id) {
const id = Math.floor((Math.random() * (9999 - 1000) + 1000 ));
const Id = await User.findOne({ where: {id: id}});
}
const user = await User.findOne({ where: { email: email } });
if (user)
return res.status(422).send(`${email} 이미 존재하는 사용자입니다.`);
if (!isLength(name, {min:3, max:10})) {
return res.status(422).send('이름은 3-10자 사이입니다')
} else if (!isLength(password, { min: 6 })){
return res.status(422).send('비밀번호는 6자이상 입니다')
} else if (!isLength(email,{ min:3, max:10 })) {
return res.status(422).send('아이디는 3-10자 사이입니다')
}
const newUser = User.create({
id: id,
name: name,
email: email,
password: password,
gender: gender,
phone: phone,
});
} catch (error) {
console.log(error);
return res.status(500).send("회원가입 중 에러");
......
......@@ -26,6 +26,7 @@ const UserModel = (sequelize) => {
},
img: {
type: DataTypes.ARRAY(DataTypes.INTEGER),
default:'/user.png'
},
roomNumber: {
type: DataTypes.ARRAY(DataTypes.STRING),
......
......@@ -6,5 +6,4 @@ const router = express.Router();
router.route("/login").post(userCtrl.login);
router.route("/signup").post(userCtrl.signup);
router.route("/").post(userCtrl.signup);
export default router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment