서민정

Update login function

......@@ -8,6 +8,21 @@ import Card from "./Sections/Card";
import CheckString from './Check';
const username = "유저";
function getKeyword(){
let url = window.location.href;
let keyword = "";
if(!url) return keyword;
for(var i = 0; i <= url.length; i++){
if(url[i] === '='){
keyword = url.substr(i+1);
keyword = decodeURI(keyword);
return keyword;
}
}
}
let userKeyword = getKeyword();
function Chatbot() {
const dispatch = useDispatch();
const messagesFromRedux = useSelector(state => state.message.messages)
......
......@@ -4,24 +4,28 @@ import { withRouter } from "react-router-dom";
import Axios from 'axios';
const { Title } = Typography;
const email = document.getElementById('email');
const pw = document.getElementById('password');
async function login() {
console.log("start");
var LoginForm = document.loginForm;
const userInfo = async (info) => {
const email = document.getElementById('email').value;
const pw = document.getElementById('password').value;
if(email && pw){
const info = {
const userVariables = {
email,
pw
}
const response = await Axios.post('/users/login', info)
if(response){
LoginForm.action = `/chat?${response}`;
LoginForm.loginForm.submit();
const response = await Axios.post('/api/login/userInfo', userVariables);
if(response.data === "오마이걸"){
// loginForm.action = `/chat?${response.data}`;
// loginForm.submit();
window.location.href=`/chat?keyword=${response.data}`;
}
}
else{
alert("nothing");
}
}
......@@ -54,7 +58,7 @@ function loginpage() {
<Form.Item>
<div>
<Button type="primary" htmlType="submit" className="login-form-button" style={{ minWidth: '100%' }} onClick={login}>
<Button type="primary" className="login-form-button" style={{ minWidth: '100%' }} onClick={userInfo}>
Log in
</Button>
</div>
......@@ -65,7 +69,7 @@ function loginpage() {
</div>
);
// return (
// htmlType="submit"
......
......@@ -8,7 +8,7 @@ const config = require("./server/config/keys");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/users/login',require('./server/routes/users/login'));
app.use('/api/login',require('./server/routes/users/login'));
app.use('/api/dialogflow', require('./server/routes/dialogflow'));
app.use('/api/latest',require('./server/routes/latest'));
app.use('/api/related',require('./server/routes/related'));
......
......@@ -8,12 +8,15 @@ var user = {
keyword: "오마이걸"
}
router.post('/users/login', async(req,res)=>{
const userEmail = req.body.email;
const userPW = req.body.pw;
const data = "";
if(userEmail === user.email && ueserPW === user.pw){
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);
})
......