Showing
10 changed files
with
134 additions
and
48 deletions
... | @@ -13,19 +13,20 @@ const BJIDFormBlock = styled.div` | ... | @@ -13,19 +13,20 @@ const BJIDFormBlock = styled.div` |
13 | } | 13 | } |
14 | `; | 14 | `; |
15 | 15 | ||
16 | -const BJIDForm = ({ onChange, onBJIDSubmit, profile }) => { | 16 | +const BJIDForm = ({ onChange, onBJIDSubmit, profile, onSyncBJIDSubmit }) => { |
17 | return ( | 17 | return ( |
18 | <BJIDFormBlock> | 18 | <BJIDFormBlock> |
19 | <h4>백준 아이디</h4> | 19 | <h4>백준 아이디</h4> |
20 | - <input | 20 | + <form onSubmit={onBJIDSubmit}> |
21 | - name="userBJID" | 21 | + <input |
22 | - onChange={onChange} | 22 | + name="userBJID" |
23 | - value={profile.userBJID} | 23 | + onChange={onChange} |
24 | - placeholder="백준 아이디" | 24 | + value={profile.userBJID} |
25 | - /> | 25 | + placeholder="백준 아이디" |
26 | - <button type="submit" onSubmit={onBJIDSubmit}> | 26 | + /> |
27 | - 등록 | 27 | + <button type="submit">등록</button> |
28 | - </button> | 28 | + </form> |
29 | + <button onClick={onSyncBJIDSubmit}>동기화</button> | ||
29 | </BJIDFormBlock> | 30 | </BJIDFormBlock> |
30 | ); | 31 | ); |
31 | }; | 32 | }; | ... | ... |
... | @@ -33,8 +33,7 @@ const SectionContainer = styled.div` | ... | @@ -33,8 +33,7 @@ const SectionContainer = styled.div` |
33 | display: flex; | 33 | display: flex; |
34 | `; | 34 | `; |
35 | 35 | ||
36 | -const SettingForm = ({ onChange, onBJIDSubmit, profile }) => { | 36 | +const SettingForm = ({ onChange, onBJIDSubmit, profile, onSyncBJIDSubmit }) => { |
37 | - console.log(profile); | ||
38 | return ( | 37 | return ( |
39 | <SettingFormBlock> | 38 | <SettingFormBlock> |
40 | <SectionContainer> | 39 | <SectionContainer> |
... | @@ -47,6 +46,7 @@ const SettingForm = ({ onChange, onBJIDSubmit, profile }) => { | ... | @@ -47,6 +46,7 @@ const SettingForm = ({ onChange, onBJIDSubmit, profile }) => { |
47 | profile={profile} | 46 | profile={profile} |
48 | onChange={onChange} | 47 | onChange={onChange} |
49 | onBJIDSubmit={onBJIDSubmit} | 48 | onBJIDSubmit={onBJIDSubmit} |
49 | + onSyncBJIDSubmit={onSyncBJIDSubmit} | ||
50 | /> | 50 | /> |
51 | </SectionContainer> | 51 | </SectionContainer> |
52 | 52 | ... | ... |
1 | import React, { useEffect, useState } from 'react'; | 1 | import React, { useEffect, useState } from 'react'; |
2 | import { useDispatch, useSelector } from 'react-redux'; | 2 | import { useDispatch, useSelector } from 'react-redux'; |
3 | import { withRouter } from 'react-router-dom'; | 3 | import { withRouter } from 'react-router-dom'; |
4 | -import { changeField, setBJID } from '../../modules/profile'; | 4 | +import { |
5 | + changeField, | ||
6 | + setBJID, | ||
7 | + getPROFILE, | ||
8 | + syncBJID, | ||
9 | +} from '../../modules/profile'; | ||
5 | import SettingForm from '../../components/setting/SettingForm'; | 10 | import SettingForm from '../../components/setting/SettingForm'; |
11 | +import { sync } from '../../../node_modules/fast-glob/index'; | ||
6 | const SettingContainer = ({ history }) => { | 12 | const SettingContainer = ({ history }) => { |
7 | const dispatch = useDispatch(); | 13 | const dispatch = useDispatch(); |
8 | const [error, setError] = useState(null); | 14 | const [error, setError] = useState(null); |
... | @@ -21,16 +27,25 @@ const SettingContainer = ({ history }) => { | ... | @@ -21,16 +27,25 @@ const SettingContainer = ({ history }) => { |
21 | ); | 27 | ); |
22 | }; | 28 | }; |
23 | 29 | ||
30 | + const onSyncBJIDSubmit = (e) => { | ||
31 | + e.preventDefault(); | ||
32 | + let username = profile.username; | ||
33 | + dispatch(syncBJID({ username })); | ||
34 | + }; | ||
35 | + | ||
24 | const onBJIDSubmit = (e) => { | 36 | const onBJIDSubmit = (e) => { |
25 | e.preventDefault(); | 37 | e.preventDefault(); |
26 | let username = profile.username; | 38 | let username = profile.username; |
27 | let userBJID = profile.userBJID; | 39 | let userBJID = profile.userBJID; |
40 | + | ||
28 | dispatch(setBJID({ username, userBJID })); | 41 | dispatch(setBJID({ username, userBJID })); |
29 | }; | 42 | }; |
30 | 43 | ||
31 | useEffect(() => { | 44 | useEffect(() => { |
45 | + console.log('1'); | ||
46 | + let username = JSON.parse(user).username; | ||
47 | + dispatch(getPROFILE({ username })); | ||
32 | //Do Init Form | 48 | //Do Init Form |
33 | - console.log(profile); | ||
34 | }, [dispatch]); | 49 | }, [dispatch]); |
35 | 50 | ||
36 | return ( | 51 | return ( |
... | @@ -38,6 +53,7 @@ const SettingContainer = ({ history }) => { | ... | @@ -38,6 +53,7 @@ const SettingContainer = ({ history }) => { |
38 | type="setting" | 53 | type="setting" |
39 | onChange={onChange} | 54 | onChange={onChange} |
40 | onBJIDSubmit={onBJIDSubmit} | 55 | onBJIDSubmit={onBJIDSubmit} |
56 | + onSyncBJIDSubmit={onSyncBJIDSubmit} | ||
41 | profile={profile} | 57 | profile={profile} |
42 | ></SettingForm> | 58 | ></SettingForm> |
43 | ); | 59 | ); | ... | ... |
1 | import client from './client'; | 1 | import client from './client'; |
2 | 2 | ||
3 | -export const setBJID = ({ username, BJID }) => | 3 | +export const setBJID = ({ username, userBJID }) => |
4 | - client.post('api/profile/setprofile', { username, BJID }); | 4 | + client.post('api/profile/setprofile', { |
5 | + username: username, | ||
6 | + userBJID: userBJID, | ||
7 | + }); | ||
8 | + | ||
9 | +export const getPROFILE = ({ username }) => | ||
10 | + client.post('api/profile/getprofile', { username }); | ||
11 | + | ||
12 | +export const syncBJ = ({ username }) => | ||
13 | + client.patch('api/profile/syncBJ', { username }); | ... | ... |
... | @@ -8,14 +8,27 @@ import { takeLatest } from 'redux-saga/effects'; | ... | @@ -8,14 +8,27 @@ import { takeLatest } from 'redux-saga/effects'; |
8 | 8 | ||
9 | const INITIALIZE = 'profile/INITIALIZE'; | 9 | const INITIALIZE = 'profile/INITIALIZE'; |
10 | const CHANGE_FIELD = 'profile/CHANGE_FIELD'; | 10 | const CHANGE_FIELD = 'profile/CHANGE_FIELD'; |
11 | - | ||
12 | const [SET_BJID, SET_BJID_SUCCESS, SET_BJID_FAILURE] = createRequestActionTypes( | 11 | const [SET_BJID, SET_BJID_SUCCESS, SET_BJID_FAILURE] = createRequestActionTypes( |
13 | 'profile/SET_BJID', | 12 | 'profile/SET_BJID', |
14 | ); | 13 | ); |
14 | +const [ | ||
15 | + GET_PROFILE, | ||
16 | + GET_PROFILE_SUCCESS, | ||
17 | + GET_PROFILE_FAILURE, | ||
18 | +] = createRequestActionTypes('profile/GET_PROFILE'); | ||
19 | + | ||
20 | +const [ | ||
21 | + SYNC_BJID, | ||
22 | + SYNC_BJID_SUCCESS, | ||
23 | + SYNC_BJID_FAILURE, | ||
24 | +] = createRequestActionTypes('profile/SYNC_BJID'); | ||
15 | 25 | ||
16 | -export const setBJID = createAction(SET_BJID, ({ username, BJID }) => ({ | 26 | +export const syncBJID = createAction(SYNC_BJID, ({ username }) => ({ |
27 | + username, | ||
28 | +})); | ||
29 | +export const setBJID = createAction(SET_BJID, ({ username, userBJID }) => ({ | ||
17 | username, | 30 | username, |
18 | - BJID, | 31 | + userBJID, |
19 | })); | 32 | })); |
20 | 33 | ||
21 | export const changeField = createAction(CHANGE_FIELD, ({ key, value }) => ({ | 34 | export const changeField = createAction(CHANGE_FIELD, ({ key, value }) => ({ |
... | @@ -23,17 +36,23 @@ export const changeField = createAction(CHANGE_FIELD, ({ key, value }) => ({ | ... | @@ -23,17 +36,23 @@ export const changeField = createAction(CHANGE_FIELD, ({ key, value }) => ({ |
23 | value, | 36 | value, |
24 | })); | 37 | })); |
25 | 38 | ||
39 | +export const getPROFILE = createAction(GET_PROFILE, ({ username }) => ({ | ||
40 | + username, | ||
41 | +})); | ||
26 | const initialState = { | 42 | const initialState = { |
27 | username: '', | 43 | username: '', |
28 | userBJID: '', | 44 | userBJID: '', |
29 | solvedBJ: '', | 45 | solvedBJ: '', |
30 | friendList: [], | 46 | friendList: [], |
31 | - BJIDError: '', | 47 | + profileError: '', |
32 | }; | 48 | }; |
33 | - | 49 | +const getPROFILESaga = createRequestSaga(GET_PROFILE, profileAPI.getPROFILE); |
34 | const setBJIDSaga = createRequestSaga(SET_BJID, profileAPI.setBJID); | 50 | const setBJIDSaga = createRequestSaga(SET_BJID, profileAPI.setBJID); |
51 | +const syncBJIDSaga = createRequestSaga(SYNC_BJID, profileAPI.syncBJ); | ||
35 | export function* profileSaga() { | 52 | export function* profileSaga() { |
36 | yield takeLatest(SET_BJID, setBJIDSaga); | 53 | yield takeLatest(SET_BJID, setBJIDSaga); |
54 | + yield takeLatest(GET_PROFILE, getPROFILESaga); | ||
55 | + yield takeLatest(SYNC_BJID, syncBJIDSaga); | ||
37 | } | 56 | } |
38 | 57 | ||
39 | export default handleActions( | 58 | export default handleActions( |
... | @@ -43,15 +62,39 @@ export default handleActions( | ... | @@ -43,15 +62,39 @@ export default handleActions( |
43 | produce(state, (draft) => { | 62 | produce(state, (draft) => { |
44 | draft[key] = value; | 63 | draft[key] = value; |
45 | }), | 64 | }), |
65 | + [GET_PROFILE_SUCCESS]: ( | ||
66 | + state, | ||
67 | + { payload: { username, userBJID, solvedBJ, friendList } }, | ||
68 | + ) => ({ | ||
69 | + ...state, | ||
70 | + username: username, | ||
71 | + userBJID: userBJID, | ||
72 | + solvedBJ: solvedBJ, | ||
73 | + friendList: friendList, | ||
74 | + profileError: null, | ||
75 | + }), | ||
76 | + [GET_PROFILE_FAILURE]: (state, { payload: error }) => ({ | ||
77 | + ...state, | ||
78 | + profileError: error, | ||
79 | + }), | ||
46 | 80 | ||
47 | - [SET_BJID_SUCCESS]: (state, { payload: BJID }) => ({ | 81 | + [SET_BJID_SUCCESS]: (state, { payload: { userBJID } }) => ({ |
48 | ...state, | 82 | ...state, |
49 | - BJID, | 83 | + userBJID: userBJID, |
50 | - BJIDError: null, | 84 | + profileError: null, |
51 | }), | 85 | }), |
52 | [SET_BJID_FAILURE]: (state, { payload: error }) => ({ | 86 | [SET_BJID_FAILURE]: (state, { payload: error }) => ({ |
53 | ...state, | 87 | ...state, |
54 | - BJIDError: error, | 88 | + profileError: error, |
89 | + }), | ||
90 | + [SYNC_BJID_SUCCESS]: (state, { payload: { solvedBJ } }) => ({ | ||
91 | + ...state, | ||
92 | + solvedBJ, | ||
93 | + profileError: null, | ||
94 | + }), | ||
95 | + [SYNC_BJID_FAILURE]: (state, { payload: error }) => ({ | ||
96 | + ...state, | ||
97 | + profileError: error, | ||
55 | }), | 98 | }), |
56 | }, | 99 | }, |
57 | initialState, | 100 | initialState, | ... | ... |
... | @@ -18,20 +18,22 @@ | ... | @@ -18,20 +18,22 @@ |
18 | 18 | ||
19 | ## API Table | 19 | ## API Table |
20 | 20 | ||
21 | -| group | description | method | URL | Detail | Auth | | 21 | +| group | description | method | URL | Detail | Auth | |
22 | -| ------- | --------------------------- | ------ | ------------------------ | -------- | --------- | | 22 | +| ------- | --------------------------- | --------- | ------------------------ | -------- | --------- | |
23 | -| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token | | 23 | +| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token | |
24 | -| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token | | 24 | +| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token | |
25 | -| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None | | 25 | +| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None | |
26 | -| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token | | 26 | +| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token | |
27 | -| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token | | 27 | +| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token | |
28 | -| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None | | 28 | +| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None | |
29 | -| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None | | 29 | +| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None | |
30 | -| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None | | 30 | +| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None | |
31 | -| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN | | 31 | +| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN | |
32 | -| profile | 추천 문제 조회 | GET | api/profile/recommend:id | 바로가기 | None | | 32 | +| profile | 유저 정보 받아오기 | POST | api/profile/getprofile | 바로가기 | JWT | |
33 | -| notify | 슬랙 메시지 전송 요청 | POST | api/notify/slack | 바로가기 | Jwt Token | | 33 | +| profile | 추천 문제 조회 | GET | api/profile/recommend:id | 바로가기 | None | |
34 | -| auth | 로그인 | POST | api/auth/login | 바로가기 | None | | 34 | +| notify | 슬랙 메시지 전송 요청 | POST | api/notify/ | |
35 | -| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token | | 35 | +| slack | 바로가기 | Jwt Token | |
36 | -| auth | 회원가입 | POST | api/auth/register | 바로가기 | None | | 36 | +| auth | 로그인 | POST | api/auth/login | 바로가기 | None | |
37 | -| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None | | 37 | +| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token | |
38 | +| auth | 회원가입 | POST | api/auth/register | 바로가기 | None | | ||
39 | +| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None | | ... | ... |
... | @@ -88,7 +88,6 @@ exports.login = async (ctx) => { | ... | @@ -88,7 +88,6 @@ exports.login = async (ctx) => { |
88 | GET api/auth/check | 88 | GET api/auth/check |
89 | */ | 89 | */ |
90 | exports.check = async (ctx) => { | 90 | exports.check = async (ctx) => { |
91 | - console.log(ctx.state); | ||
92 | const { user } = ctx.state; | 91 | const { user } = ctx.state; |
93 | if (!user) { | 92 | if (!user) { |
94 | ctx.status = 401; | 93 | ctx.status = 401; | ... | ... |
... | @@ -7,4 +7,5 @@ profile.get("/solvednum:id"); | ... | @@ -7,4 +7,5 @@ profile.get("/solvednum:id"); |
7 | profile.get("/recommendps:id"); | 7 | profile.get("/recommendps:id"); |
8 | profile.patch("/syncBJ", profileCtrl.syncBJ); | 8 | profile.patch("/syncBJ", profileCtrl.syncBJ); |
9 | profile.post("/setprofile", profileCtrl.setProfile); | 9 | profile.post("/setprofile", profileCtrl.setProfile); |
10 | +profile.post("/getprofile", profileCtrl.getProfile); | ||
10 | module.exports = profile; | 11 | module.exports = profile; | ... | ... |
... | @@ -13,6 +13,24 @@ exports.checkObjectId = (ctx, next) => { | ... | @@ -13,6 +13,24 @@ exports.checkObjectId = (ctx, next) => { |
13 | } | 13 | } |
14 | return next(); | 14 | return next(); |
15 | }; | 15 | }; |
16 | +/*POST /api/profile/getprofile | ||
17 | +{ | ||
18 | + username: "username" | ||
19 | +} | ||
20 | +*/ | ||
21 | +exports.getProfile = async (ctx) => { | ||
22 | + try { | ||
23 | + const { username } = ctx.request.body; | ||
24 | + const profile = await Profile.findByUsername(username); | ||
25 | + if (!profile) { | ||
26 | + ctx.status = 401; | ||
27 | + return; | ||
28 | + } | ||
29 | + ctx.body = profile; | ||
30 | + } catch (e) { | ||
31 | + ctx.throw(500, e); | ||
32 | + } | ||
33 | +}; | ||
16 | /* | 34 | /* |
17 | POST /api/proflie/setprofile | 35 | POST /api/proflie/setprofile |
18 | { | 36 | { | ... | ... |
... | @@ -3,14 +3,11 @@ const User = require("../models/user"); | ... | @@ -3,14 +3,11 @@ const User = require("../models/user"); |
3 | 3 | ||
4 | const jwtMiddleware = async (ctx, next) => { | 4 | const jwtMiddleware = async (ctx, next) => { |
5 | const token = ctx.cookies.get("access_token"); | 5 | const token = ctx.cookies.get("access_token"); |
6 | - console.log("1"); | 6 | + |
7 | - console.log(token); | ||
8 | if (!token) { | 7 | if (!token) { |
9 | - console.log("1"); | ||
10 | return next(); | 8 | return next(); |
11 | } | 9 | } |
12 | try { | 10 | try { |
13 | - console.log("1"); | ||
14 | const decoded = jwt.verify(token, process.env.JWT_SECRET); | 11 | const decoded = jwt.verify(token, process.env.JWT_SECRET); |
15 | ctx.state.user = { | 12 | ctx.state.user = { |
16 | _id: decoded._id, | 13 | _id: decoded._id, |
... | @@ -25,7 +22,7 @@ const jwtMiddleware = async (ctx, next) => { | ... | @@ -25,7 +22,7 @@ const jwtMiddleware = async (ctx, next) => { |
25 | httpOnly: true, | 22 | httpOnly: true, |
26 | }); | 23 | }); |
27 | } | 24 | } |
28 | - console.log(decoded); | 25 | + |
29 | return next(); | 26 | return next(); |
30 | } catch (e) { | 27 | } catch (e) { |
31 | return next(); | 28 | return next(); | ... | ... |
-
Please register or login to post a comment