Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions client/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import axios from "axios"
import { useHistory } from "react-router-dom"

// action types
export const CHANGE_USER_INFO = "CHANGE_USER_INFO"
export const UPDATE_CURRENT_PAGE = "UPDATE_CURRENT_PAGE"
export const UPDATE_START_END_PAGE = "UPDATE_START_END_PAGE"

export const SIGNIN_USER = "SIGNIN_USER"
// export const SIGNIN_USER = "SIGNIN_USER"
export const LOGGEDIN_USER = "LOGGEDIN_USER"
export const SIGNUP_USER = "SIGNUP_USER"
export const CHANGE_USER_GENDER = "CHANGE_USER_GENDER"
export const CHANGE_IS_LOGIN = "CHANGE_IS_LOGIN"

// export const LOGIN_USER = "LOGIN_USER"
<<<<<<< HEAD

=======
>>>>>>> b80992d1beeb2faba0efc11115504b420e4286dc


// actions creator functions
Expand Down Expand Up @@ -46,16 +40,6 @@ export const updateStartEndPage = (start, end) => {
}
}

//홈 바로가기
export const Home = (history) => () => {
history.push("/home")
}
//로그인 화면 바로가기
export const Login = (history) => () => {
history.push("/login")
}


//로그인된 상태
export const loggedInUser = (accessToken, path) => {
return {
Expand All @@ -65,7 +49,7 @@ export const loggedInUser = (accessToken, path) => {
};
};

//로그인

export const signInUser = (userInfoId, userInfoPw, history) => (dispatch) => {
dispatch({
type: SIGNIN_USER
Expand Down Expand Up @@ -93,18 +77,6 @@ export const signUpUser = (data, history) => (dispatch) => {
}


<<<<<<< HEAD
// export const loginUser = (data) => {
// const loginDate = axios.post("http://localhost:3000/login", data)
// .then(res => res.data)
// return {
// type: LOGIN_USER,
// payload: loginDate
// }
// }
=======
>>>>>>> b80992d1beeb2faba0efc11115504b420e4286dc

export const changeGender = (usergender) => {
return {
type: CHANGE_USER_GENDER,
Expand Down
18 changes: 12 additions & 6 deletions client/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import axios from "axios"
import styled from "styled-components"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faGoogle } from "@fortawesome/free-brands-svg-icons"
import { changeIsLogin } from "../actions/index"
import { signInUser } from "../actions"
import { changeIsLogin, signInUser } from "../actions/index"

/*
TODO
Expand Down Expand Up @@ -101,7 +100,6 @@ const Button = styled.button`
}
`

// axios.defaults.withCredentials = true;

export default function Login() {
const dispatch = useDispatch()
Expand Down Expand Up @@ -157,16 +155,24 @@ export default function Login() {
setPwInputMessage((prevText) => "")
}
}

const loginButtonHandler = (e) => {
e.preventDefault();

if (idInput.length === 0 && pwInput.length === 0) {
console.log("모든 항목을 입력해야 합니다.")
}
dispatch(signInUser(idInput, pwInput))

}

axios.post("http://localhost/login",
{ user_id: idInput, password: pwInput },
{ headers: { "Content-Type" : "application/json" }, withCredentials: true })
.then((res) =>
localStorage.setItem("accessToken", res.data.data.accessToken),
dispatch(changeIsLogin(true))
)
history.push("/home")
}
//localStorage.removeItem("key") 로그아웃시 로컬스토리지에서 토큰 삭제

function googleLoginButtonHandler() {
console.log("구글 로그인 버튼 동작 확인")
Expand Down
8 changes: 4 additions & 4 deletions client/src/pages/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ const PhotoBox2 = styled.img`
const url = process.env.REACT_APP_URL || "http://ec2-54-180-102-202.ap-northeast-2.compute.amazonaws.com"

export default function SignUp() {
const state = useSelector(state => state.itemReducer)
const dispatch = useDispatch();
// const state = useSelector(state => state.itemReducer)
// const dispatch = useDispatch();

// input 상태 관리, 유효성 검사
const [inputSignUpData, setInputSignUpData] = useState({ idInput: "", pwInput: "", nickNameInput: "" })
Expand Down Expand Up @@ -304,7 +304,7 @@ export default function SignUp() {
}

function signupFunc(e) {
e.preventDefault();
// e.preventDefault();


console.log("프론트 콘솔:회원가입 입장")
Expand Down Expand Up @@ -335,7 +335,7 @@ export default function SignUp() {
}
})
}
dispatch(signUpUser(inputSignUpData, history))
// dispatch(signUpUser(inputSignUpData, history))
}
////////////////////////////////////////////////
const onSubmit = (e) => {
Expand Down
12 changes: 6 additions & 6 deletions client/src/reducers/initialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const initialState = {

//로그인 테스트
//로그인시
userSignin: {
signIn: null,
},
// userSignin: {
// signIn: null,
// },

//로그인된 상태
userLoggedIn: {
Expand All @@ -22,8 +22,8 @@ export const initialState = {
},

//회원가입
signUp: {
signUpStatus: false
}
// signUp: {
// signUpStatus: false
// }

}
26 changes: 0 additions & 26 deletions client/src/reducers/itemReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const itemReducer = (state = initialState, action) => {
genderToggle: action.payload,
}
break;

// case CHANGE_USER_INFO:
// break
case UPDATE_CURRENT_PAGE:
return {
...state,
Expand All @@ -44,34 +41,11 @@ const itemReducer = (state = initialState, action) => {
},
}
break;
case SIGNIN_USER:
return {
...state,
userSignin: {
signIn: false,
}
}
break;
case SIGNUP_USER:
return {
...state,
signUp: {
signUpStatus: false
}
}
break;
// case LOGIN_USER:
// return {
// ...state,
// loginSuccess: action.payload
// }

case CHANGE_IS_LOGIN:
return {
...state,
isLogin: action.payload,
}

default:
return state
}
Expand Down
6 changes: 3 additions & 3 deletions server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ dotenv.config()

module.exports = {
development: {
username: process.env.MYSQL_ID,
password: process.env.MYSQL_PASSWORD,
database: "TWD",
username: "root",
password: "1234",
database: "there_weather",
host: "127.0.0.1",
dialect: "mysql",
},
Expand Down
23 changes: 0 additions & 23 deletions server/config/config.json

This file was deleted.

8 changes: 1 addition & 7 deletions server/controllers/get/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@ module.exports = async (req, res) => {
.catch((err) => {
console.log(err)
})
}

// const { getAccessToken } = require("../tokenFunc");
// const { user } = require("../../models");
// const refreshToken = async (req, res) => {
// res.send()
// }
}
25 changes: 13 additions & 12 deletions server/controllers/get/setpw.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
const crypto = require('crypto');
require("dotenv").config();

const algorithm = 'aes-256-cbc'; //암호화에 사용할 알고리즘
const key = crypto.scryptSync(process.env.PW_KEY, process.env.PW_SALT, 32); //암호화 및 복호화 생성 키 설정
const iv = Buffer.alloc(16, 0);//초기화 백터
//Buffer.alloc(16, 0)
//crypto.randomBytes(16);

module.exports = {
//암호화
encrypto: (data) => {
const algorithm = 'aes-256-cbc'; //암호화에 사용할 알고리즘
const key = crypto.scryptSync(process.env.PW_KEY, process.env.PW_SALT, 24); //암호화 및 복호화 생성 키 설정
const iv = crypto.randomBytes(16); //초기화 백터
if(!data){
return '';
}
const cipher = crypto.createCipheriv(algorithm, key, iv); //cipher 객체
const result = cipher.update(data, "utf-8", "base64"); //인코딩
result += cipher.final("base64");
return result;
const enresult = cipher.update(data, "utf8", "base64"); //인코딩
const results = enresult + cipher.final("base64");
return results;
},

//복호화
decrypto: (data) => {
const algorithm = 'aes-256-cbc'; //암호화에 사용할 알고리즘
const key = crypto.scryptSync(process.env.PW_KEY, process.env.PW_SALT, 24); //암호화 및 복호화 생성 키 설정
const iv = crypto.randomBytes(16); //초기화 백터
decrypto: (data) => {
if(!data){
return '';
}
const decipher = crypto.createDecipheriv(algorithm, key, iv);
const result2 = decipher.update(data, "base64", "utf-8");
result2 += decipher.final("utf-8");
const deresult = decipher.update(data, "base64", "utf8");
const output = deresult + decipher.final("utf8");
return output;
}
}
1 change: 0 additions & 1 deletion server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
map: require("./get/map"),
mypage: require("./get/mypage"),
readpost: require("./get/readpost"),
// setpw: require("./get/setpw"),
login: require("./post/login"),
signout: require("./post/signout"),
signup: require("./post/signup"),
Expand Down
26 changes: 3 additions & 23 deletions server/controllers/post/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,20 @@ module.exports = async (req, res) => {

const userInfo = await user.findOne({
where: {
user_id, password
user_id
}
})

//비밀번호 복호화
const dePw = decrypto(userInfo.password);
//console.log(dePw)
if(dePw !== password){
return res.status(401).send("비밀번호를 확인해주세요.")
}

//비밀번호가 맞다면
delete userInfo.dataValues.password;
const accessToken = getAccessToken(userInfo.dataValues);
const refreshToken = getRefreshToken(userInfo.dataValues);
sendToken(res, accessToken, refreshToken);

// .then((data) => {
// if(!data){
// return res.status(401).send("로그인 정보를 확인해주세요.")
// }
// //비밀번호 복호화
// const dePw = decrypto(data.dataValues.password);
// if(dePw !== password){
// return res.status(401).send("비밀번호를 확인해주세요.")
// }

// delete data.dataValues.password;
// const accessToken = getAccessToken(data.dataValues);
// const refreshToken = getRefreshToken(data.dataValues);
// sendRefreshToken(res, refreshToken)
// res.cookie("jwt", accessToken, {
// httpOnly: true, sameSite: "None", secure: true
// })
// .status(200).send("로그인 성공")
// })
//res.send()
}
4 changes: 3 additions & 1 deletion server/controllers/post/signout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = async (req, res) => {
res.send()
delete req.headers.authorization;
res.clearCookie("refreshToken");
localStorage.clear();
}
Loading