Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MotherProject
/
Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
송용우
2020-06-22 14:12:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
95c511dc4725347e591fb81cda6a47907ccc6125
95c511dc
1 parent
699244b1
Update SYNCBJ
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
134 additions
and
48 deletions
jaksimsamil-page/src/components/setting/BJIDForm.js
jaksimsamil-page/src/components/setting/SettingForm.js
jaksimsamil-page/src/containers/setting/SettingContainer.js
jaksimsamil-page/src/lib/api/profile.js
jaksimsamil-page/src/modules/profile.js
jaksimsamil-server/API.md
jaksimsamil-server/src/api/auth/auth.ctrl.js
jaksimsamil-server/src/api/profile/index.js
jaksimsamil-server/src/api/profile/profile.ctrl.js
jaksimsamil-server/src/lib/jwtMiddleware.js
jaksimsamil-page/src/components/setting/BJIDForm.js
View file @
95c511d
...
...
@@ -13,19 +13,20 @@ const BJIDFormBlock = styled.div`
}
`
;
const
BJIDForm
=
({
onChange
,
onBJIDSubmit
,
profile
})
=>
{
const
BJIDForm
=
({
onChange
,
onBJIDSubmit
,
profile
,
onSyncBJIDSubmit
})
=>
{
return
(
<
BJIDFormBlock
>
<
h4
>
백준
아이디
<
/h4
>
<
input
name
=
"userBJID"
onChange
=
{
onChange
}
value
=
{
profile
.
userBJID
}
placeholder
=
"백준 아이디"
/>
<
button
type
=
"submit"
onSubmit
=
{
onBJIDSubmit
}
>
등록
<
/button
>
<
form
onSubmit
=
{
onBJIDSubmit
}
>
<
input
name
=
"userBJID"
onChange
=
{
onChange
}
value
=
{
profile
.
userBJID
}
placeholder
=
"백준 아이디"
/>
<
button
type
=
"submit"
>
등록
<
/button
>
<
/form
>
<
button
onClick
=
{
onSyncBJIDSubmit
}
>
동기화
<
/button
>
<
/BJIDFormBlock
>
);
};
...
...
jaksimsamil-page/src/components/setting/SettingForm.js
View file @
95c511d
...
...
@@ -33,8 +33,7 @@ const SectionContainer = styled.div`
display: flex;
`
;
const
SettingForm
=
({
onChange
,
onBJIDSubmit
,
profile
})
=>
{
console
.
log
(
profile
);
const
SettingForm
=
({
onChange
,
onBJIDSubmit
,
profile
,
onSyncBJIDSubmit
})
=>
{
return
(
<
SettingFormBlock
>
<
SectionContainer
>
...
...
@@ -47,6 +46,7 @@ const SettingForm = ({ onChange, onBJIDSubmit, profile }) => {
profile
=
{
profile
}
onChange
=
{
onChange
}
onBJIDSubmit
=
{
onBJIDSubmit
}
onSyncBJIDSubmit
=
{
onSyncBJIDSubmit
}
/
>
<
/SectionContainer
>
...
...
jaksimsamil-page/src/containers/setting/SettingContainer.js
View file @
95c511d
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
{
withRouter
}
from
'react-router-dom'
;
import
{
changeField
,
setBJID
}
from
'../../modules/profile'
;
import
{
changeField
,
setBJID
,
getPROFILE
,
syncBJID
,
}
from
'../../modules/profile'
;
import
SettingForm
from
'../../components/setting/SettingForm'
;
import
{
sync
}
from
'../../../node_modules/fast-glob/index'
;
const
SettingContainer
=
({
history
})
=>
{
const
dispatch
=
useDispatch
();
const
[
error
,
setError
]
=
useState
(
null
);
...
...
@@ -21,16 +27,25 @@ const SettingContainer = ({ history }) => {
);
};
const
onSyncBJIDSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
let
username
=
profile
.
username
;
dispatch
(
syncBJID
({
username
}));
};
const
onBJIDSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
let
username
=
profile
.
username
;
let
userBJID
=
profile
.
userBJID
;
dispatch
(
setBJID
({
username
,
userBJID
}));
};
useEffect
(()
=>
{
console
.
log
(
'1'
);
let
username
=
JSON
.
parse
(
user
).
username
;
dispatch
(
getPROFILE
({
username
}));
//Do Init Form
console
.
log
(
profile
);
},
[
dispatch
]);
return
(
...
...
@@ -38,6 +53,7 @@ const SettingContainer = ({ history }) => {
type
=
"setting"
onChange
=
{
onChange
}
onBJIDSubmit
=
{
onBJIDSubmit
}
onSyncBJIDSubmit
=
{
onSyncBJIDSubmit
}
profile
=
{
profile
}
><
/SettingForm
>
);
...
...
jaksimsamil-page/src/lib/api/profile.js
View file @
95c511d
import
client
from
'./client'
;
export
const
setBJID
=
({
username
,
BJID
})
=>
client
.
post
(
'api/profile/setprofile'
,
{
username
,
BJID
});
export
const
setBJID
=
({
username
,
userBJID
})
=>
client
.
post
(
'api/profile/setprofile'
,
{
username
:
username
,
userBJID
:
userBJID
,
});
export
const
getPROFILE
=
({
username
})
=>
client
.
post
(
'api/profile/getprofile'
,
{
username
});
export
const
syncBJ
=
({
username
})
=>
client
.
patch
(
'api/profile/syncBJ'
,
{
username
});
...
...
jaksimsamil-page/src/modules/profile.js
View file @
95c511d
...
...
@@ -8,14 +8,27 @@ import { takeLatest } from 'redux-saga/effects';
const
INITIALIZE
=
'profile/INITIALIZE'
;
const
CHANGE_FIELD
=
'profile/CHANGE_FIELD'
;
const
[
SET_BJID
,
SET_BJID_SUCCESS
,
SET_BJID_FAILURE
]
=
createRequestActionTypes
(
'profile/SET_BJID'
,
);
const
[
GET_PROFILE
,
GET_PROFILE_SUCCESS
,
GET_PROFILE_FAILURE
,
]
=
createRequestActionTypes
(
'profile/GET_PROFILE'
);
const
[
SYNC_BJID
,
SYNC_BJID_SUCCESS
,
SYNC_BJID_FAILURE
,
]
=
createRequestActionTypes
(
'profile/SYNC_BJID'
);
export
const
setBJID
=
createAction
(
SET_BJID
,
({
username
,
BJID
})
=>
({
export
const
syncBJID
=
createAction
(
SYNC_BJID
,
({
username
})
=>
({
username
,
}));
export
const
setBJID
=
createAction
(
SET_BJID
,
({
username
,
userBJID
})
=>
({
username
,
BJID
,
user
BJID
,
}));
export
const
changeField
=
createAction
(
CHANGE_FIELD
,
({
key
,
value
})
=>
({
...
...
@@ -23,17 +36,23 @@ export const changeField = createAction(CHANGE_FIELD, ({ key, value }) => ({
value
,
}));
export
const
getPROFILE
=
createAction
(
GET_PROFILE
,
({
username
})
=>
({
username
,
}));
const
initialState
=
{
username
:
''
,
userBJID
:
''
,
solvedBJ
:
''
,
friendList
:
[],
BJID
Error
:
''
,
profile
Error
:
''
,
};
const
getPROFILESaga
=
createRequestSaga
(
GET_PROFILE
,
profileAPI
.
getPROFILE
);
const
setBJIDSaga
=
createRequestSaga
(
SET_BJID
,
profileAPI
.
setBJID
);
const
syncBJIDSaga
=
createRequestSaga
(
SYNC_BJID
,
profileAPI
.
syncBJ
);
export
function
*
profileSaga
()
{
yield
takeLatest
(
SET_BJID
,
setBJIDSaga
);
yield
takeLatest
(
GET_PROFILE
,
getPROFILESaga
);
yield
takeLatest
(
SYNC_BJID
,
syncBJIDSaga
);
}
export
default
handleActions
(
...
...
@@ -43,15 +62,39 @@ export default handleActions(
produce
(
state
,
(
draft
)
=>
{
draft
[
key
]
=
value
;
}),
[
GET_PROFILE_SUCCESS
]:
(
state
,
{
payload
:
{
username
,
userBJID
,
solvedBJ
,
friendList
}
},
)
=>
({
...
state
,
username
:
username
,
userBJID
:
userBJID
,
solvedBJ
:
solvedBJ
,
friendList
:
friendList
,
profileError
:
null
,
}),
[
GET_PROFILE_FAILURE
]:
(
state
,
{
payload
:
error
})
=>
({
...
state
,
profileError
:
error
,
}),
[
SET_BJID_SUCCESS
]:
(
state
,
{
payload
:
BJID
})
=>
({
[
SET_BJID_SUCCESS
]:
(
state
,
{
payload
:
{
userBJID
}
})
=>
({
...
state
,
BJID
,
BJID
Error
:
null
,
userBJID
:
user
BJID
,
profile
Error
:
null
,
}),
[
SET_BJID_FAILURE
]:
(
state
,
{
payload
:
error
})
=>
({
...
state
,
BJIDError
:
error
,
profileError
:
error
,
}),
[
SYNC_BJID_SUCCESS
]:
(
state
,
{
payload
:
{
solvedBJ
}
})
=>
({
...
state
,
solvedBJ
,
profileError
:
null
,
}),
[
SYNC_BJID_FAILURE
]:
(
state
,
{
payload
:
error
})
=>
({
...
state
,
profileError
:
error
,
}),
},
initialState
,
...
...
jaksimsamil-server/API.md
View file @
95c511d
...
...
@@ -18,20 +18,22 @@
## API Table
| group | description | method | URL | Detail | Auth |
| ------- | --------------------------- | ------ | ------------------------ | -------- | --------- |
| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token |
| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token |
| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None |
| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token |
| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token |
| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None |
| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None |
| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None |
| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN |
| profile | 추천 문제 조회 | GET | api/profile/recommend:id | 바로가기 | None |
| notify | 슬랙 메시지 전송 요청 | POST | api/notify/slack | 바로가기 | Jwt Token |
| auth | 로그인 | POST | api/auth/login | 바로가기 | None |
| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token |
| auth | 회원가입 | POST | api/auth/register | 바로가기 | None |
| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None |
| group | description | method | URL | Detail | Auth |
| ------- | --------------------------- | --------- | ------------------------ | -------- | --------- |
| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token |
| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token |
| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None |
| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token |
| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token |
| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None |
| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None |
| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None |
| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN |
| profile | 유저 정보 받아오기 | POST | api/profile/getprofile | 바로가기 | JWT |
| profile | 추천 문제 조회 | GET | api/profile/recommend:id | 바로가기 | None |
| notify | 슬랙 메시지 전송 요청 | POST | api/notify/ |
| slack | 바로가기 | Jwt Token |
| auth | 로그인 | POST | api/auth/login | 바로가기 | None |
| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token |
| auth | 회원가입 | POST | api/auth/register | 바로가기 | None |
| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None |
...
...
jaksimsamil-server/src/api/auth/auth.ctrl.js
View file @
95c511d
...
...
@@ -88,7 +88,6 @@ exports.login = async (ctx) => {
GET api/auth/check
*/
exports
.
check
=
async
(
ctx
)
=>
{
console
.
log
(
ctx
.
state
);
const
{
user
}
=
ctx
.
state
;
if
(
!
user
)
{
ctx
.
status
=
401
;
...
...
jaksimsamil-server/src/api/profile/index.js
View file @
95c511d
...
...
@@ -7,4 +7,5 @@ profile.get("/solvednum:id");
profile
.
get
(
"/recommendps:id"
);
profile
.
patch
(
"/syncBJ"
,
profileCtrl
.
syncBJ
);
profile
.
post
(
"/setprofile"
,
profileCtrl
.
setProfile
);
profile
.
post
(
"/getprofile"
,
profileCtrl
.
getProfile
);
module
.
exports
=
profile
;
...
...
jaksimsamil-server/src/api/profile/profile.ctrl.js
View file @
95c511d
...
...
@@ -13,6 +13,24 @@ exports.checkObjectId = (ctx, next) => {
}
return
next
();
};
/*POST /api/profile/getprofile
{
username: "username"
}
*/
exports
.
getProfile
=
async
(
ctx
)
=>
{
try
{
const
{
username
}
=
ctx
.
request
.
body
;
const
profile
=
await
Profile
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
}
ctx
.
body
=
profile
;
}
catch
(
e
)
{
ctx
.
throw
(
500
,
e
);
}
};
/*
POST /api/proflie/setprofile
{
...
...
jaksimsamil-server/src/lib/jwtMiddleware.js
View file @
95c511d
...
...
@@ -3,14 +3,11 @@ const User = require("../models/user");
const
jwtMiddleware
=
async
(
ctx
,
next
)
=>
{
const
token
=
ctx
.
cookies
.
get
(
"access_token"
);
console
.
log
(
"1"
);
console
.
log
(
token
);
if
(
!
token
)
{
console
.
log
(
"1"
);
return
next
();
}
try
{
console
.
log
(
"1"
);
const
decoded
=
jwt
.
verify
(
token
,
process
.
env
.
JWT_SECRET
);
ctx
.
state
.
user
=
{
_id
:
decoded
.
_id
,
...
...
@@ -25,7 +22,7 @@ const jwtMiddleware = async (ctx, next) => {
httpOnly
:
true
,
});
}
console
.
log
(
decoded
);
return
next
();
}
catch
(
e
)
{
return
next
();
...
...
Please
register
or
login
to post a comment