서민정

update register

const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(proxy("/api", { target: "https://oss-chatbot-app.ue.r.appspot.com" }));
app.use(proxy("/api", { target: "http://localhost:5000/" }));
};
\ No newline at end of file
// target: "http://localhost:5000/"
\ No newline at end of file
......
......@@ -17,14 +17,16 @@ const userInfo = async (info) => {
}
const response = await Axios.post('/api/login/userInfo', userVariables);
if(response.data === "오마이걸"){
if(response.data){
// loginForm.action = `/chat?${response.data}`;
// loginForm.submit();
window.location.href=`/chat?keyword=${response.data}`;
} else{
alert("입력하신 정보와 일치하는 회원이 존재하지 않습니다 😥");
}
}
else{
alert("nothing");
alert("이메일과 패스워드를 입력해주세요!");
}
}
......
import React from "react";
import { Typography, Form, Input, Button} from 'antd';
import { withRouter } from "react-router-dom";
import Axios from "axios";
const { Title } = Typography;
const saveUser = async (info) => {
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const pw = document.getElementById('password').value;
const keyword = document.getElementById('keyword').value;
if(name && email && pw && keyword){
const userVariable = {
name,
email,
pw,
keyword
}
const response = await Axios.post('/api/register/addUser', userVariable);
if(response.data === 'SUCCESS'){
alert(`${name}님, 회원가입이 완료되었습니다!`);
window.location.href = `/`;
}
else if(response.data === 'EXIST'){
alert("같은 email을 가진 회원이 존재합니다 😥");
}
} else{
alert('모든 정보를 입력해주세요!');
}
}
function registerpage() {
return (
......@@ -45,7 +72,7 @@ function registerpage() {
</Form.Item>
<Form.Item>
<Button type="primary">
<Button type="primary" onClick = {saveUser}>
Submit
</Button>
</Form.Item>
......@@ -53,13 +80,6 @@ function registerpage() {
</div>
</div>
);
// return (
// <div>
// <div style={{ display: 'flex', justifyContent: 'center', marginTop: '1rem' }}>
// <Title level={2} >RegisterPage Test</Title>
// </div>
// </div>
// )
}
export default withRouter(registerpage);
\ No newline at end of file
......
......@@ -9,6 +9,7 @@ app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/api/login',require('./server/routes/users/login'));
app.use('/api/register',require('./server/routes/users/register'));
app.use('/api/dialogflow', require('./server/routes/dialogflow'));
app.use('/api/latest',require('./server/routes/latest'));
app.use('/api/related',require('./server/routes/related'));
......
const express = require('express');
const router = express.Router();
var getUser = require('./user').getUser;
var user = {
email: "mathmjseo@khu.ac.kr",
name: "minjeong",
pw: "1234",
keyword: "오마이걸"
}
// var user = {
// email: "mathmjseo@khu.ac.kr",
// name: "minjeong",
// pw: "1234",
// keyword: "오마이걸"
// }
router.post('/userInfo', async(req,res)=>{
let userEmail = req.body.email;
console.log(userEmail);
let userPW = req.body.pw;
console.log(userPW);
let data = "";
if(userEmail === user.email && userPW === user.pw){
data = user.keyword;
console.log(data);
}
res.send(data);
let result = "";
const simpleUserInfo = {
email: userEmail,
pw: userPW
};
result = getUser(simpleUserInfo);
res.send(result);
})
module.exports = router;
\ No newline at end of file
......
const express = require('express');
const router = express.Router();
var addUser = require('./user').addUser;
router.post('/addUser', async(req,res)=>{
const userName = req.body.name;
const userEmail = req.body.email;
const userPW = req.body.pw;
const userKeyword = req.body.keyword;
const newUser = {
'name':userName,
'email':userEmail,
'pw' :userPW,
'keyword': userKeyword
};
var result = addUser(newUser);
res.send(result);
})
module.exports = router;
\ No newline at end of file
......
let users = new Array();
function addUser(userInfo){
let result = "";
let isExist = false;
for(var i = 0; i < users.length; i++){
if(users[i].email === userInfo.email){
isExist = true;
break;
}
}
if(!isExist){
users.push(userInfo);
result = "SUCCESS";
}
else{
result = "EXIST";
}
return result;
}
function getUser(simpleUserInfo){
let userEmail = simpleUserInfo.email;
let userPw = simpleUserInfo.pw;
let result = "";
for(var i = 0; i < users.length; i++){
if(userEmail === users[i].email && userPw === users[i].pw){
result = users[i].keyword;
}
}
return result;
}
module.exports = {addUser, getUser};