서민정

Update login function

...@@ -8,6 +8,21 @@ import Card from "./Sections/Card"; ...@@ -8,6 +8,21 @@ import Card from "./Sections/Card";
8 import CheckString from './Check'; 8 import CheckString from './Check';
9 const username = "유저"; 9 const username = "유저";
10 10
11 +function getKeyword(){
12 + let url = window.location.href;
13 + let keyword = "";
14 + if(!url) return keyword;
15 + for(var i = 0; i <= url.length; i++){
16 + if(url[i] === '='){
17 + keyword = url.substr(i+1);
18 + keyword = decodeURI(keyword);
19 + return keyword;
20 + }
21 + }
22 +}
23 +
24 +let userKeyword = getKeyword();
25 +
11 function Chatbot() { 26 function Chatbot() {
12 const dispatch = useDispatch(); 27 const dispatch = useDispatch();
13 const messagesFromRedux = useSelector(state => state.message.messages) 28 const messagesFromRedux = useSelector(state => state.message.messages)
......
...@@ -4,24 +4,28 @@ import { withRouter } from "react-router-dom"; ...@@ -4,24 +4,28 @@ import { withRouter } from "react-router-dom";
4 import Axios from 'axios'; 4 import Axios from 'axios';
5 5
6 const { Title } = Typography; 6 const { Title } = Typography;
7 -const email = document.getElementById('email');
8 -const pw = document.getElementById('password');
9 7
10 -async function login() { 8 +console.log("start");
11 9
12 - var LoginForm = document.loginForm; 10 +const userInfo = async (info) => {
11 + const email = document.getElementById('email').value;
12 + const pw = document.getElementById('password').value;
13 if(email && pw){ 13 if(email && pw){
14 - const info = { 14 + const userVariables = {
15 email, 15 email,
16 pw 16 pw
17 } 17 }
18 18
19 - const response = await Axios.post('/users/login', info) 19 + const response = await Axios.post('/api/login/userInfo', userVariables);
20 - if(response){ 20 + if(response.data === "오마이걸"){
21 - LoginForm.action = `/chat?${response}`; 21 + // loginForm.action = `/chat?${response.data}`;
22 - LoginForm.loginForm.submit(); 22 + // loginForm.submit();
23 + window.location.href=`/chat?keyword=${response.data}`;
23 } 24 }
24 } 25 }
26 + else{
27 + alert("nothing");
28 + }
25 } 29 }
26 30
27 31
...@@ -54,7 +58,7 @@ function loginpage() { ...@@ -54,7 +58,7 @@ function loginpage() {
54 58
55 <Form.Item> 59 <Form.Item>
56 <div> 60 <div>
57 - <Button type="primary" htmlType="submit" className="login-form-button" style={{ minWidth: '100%' }} onClick={login}> 61 + <Button type="primary" className="login-form-button" style={{ minWidth: '100%' }} onClick={userInfo}>
58 Log in 62 Log in
59 </Button> 63 </Button>
60 </div> 64 </div>
...@@ -65,7 +69,7 @@ function loginpage() { ...@@ -65,7 +69,7 @@ function loginpage() {
65 </div> 69 </div>
66 ); 70 );
67 // return ( 71 // return (
68 - 72 + // htmlType="submit"
69 73
70 74
71 75
......
...@@ -8,7 +8,7 @@ const config = require("./server/config/keys"); ...@@ -8,7 +8,7 @@ const config = require("./server/config/keys");
8 app.use(bodyParser.urlencoded({ extended: true })); 8 app.use(bodyParser.urlencoded({ extended: true }));
9 app.use(bodyParser.json()); 9 app.use(bodyParser.json());
10 10
11 -app.use('/users/login',require('./server/routes/users/login')); 11 +app.use('/api/login',require('./server/routes/users/login'));
12 app.use('/api/dialogflow', require('./server/routes/dialogflow')); 12 app.use('/api/dialogflow', require('./server/routes/dialogflow'));
13 app.use('/api/latest',require('./server/routes/latest')); 13 app.use('/api/latest',require('./server/routes/latest'));
14 app.use('/api/related',require('./server/routes/related')); 14 app.use('/api/related',require('./server/routes/related'));
......
...@@ -8,12 +8,15 @@ var user = { ...@@ -8,12 +8,15 @@ var user = {
8 keyword: "오마이걸" 8 keyword: "오마이걸"
9 } 9 }
10 10
11 -router.post('/users/login', async(req,res)=>{ 11 +router.post('/userInfo', async(req,res)=>{
12 - const userEmail = req.body.email; 12 + let userEmail = req.body.email;
13 - const userPW = req.body.pw; 13 + console.log(userEmail);
14 - const data = ""; 14 + let userPW = req.body.pw;
15 - if(userEmail === user.email && ueserPW === user.pw){ 15 + console.log(userPW);
16 + let data = "";
17 + if(userEmail === user.email && userPW === user.pw){
16 data = user.keyword; 18 data = user.keyword;
19 + console.log(data);
17 } 20 }
18 res.send(data); 21 res.send(data);
19 }) 22 })
......