Toggle navigation
Toggle navigation
This project
Loading...
Sign in
송용우
/
oss-Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
송용우
2020-06-12 23:18:45 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
664acc3e6279af390aa8d1f7d8d28a469dc4445d
664acc3e
2 parents
89c20583
24bb25e9
Merge commit '
24bb25e9
' into develop
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
64 additions
and
58 deletions
jaksimsamil-server/API.md
jaksimsamil-server/index.js
jaksimsamil-server/package-lock.json
jaksimsamil-server/package.json
jaksimsamil-server/src/api/auth/auth.ctrl.js
jaksimsamil-server/src/api/auth/index.js
jaksimsamil-server/src/api/friend/index.js
jaksimsamil-server/src/api/index.js
jaksimsamil-server/src/api/notify/index.js
jaksimsamil-server/src/api/profile/index.js
jaksimsamil-server/src/api/user/index.js
jaksimsamil-server/src/models/user.js
jaksimsamil-server/yarn.lock
jaksimsamil-server/API.md
View file @
664acc3
...
...
@@ -27,6 +27,7 @@
| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token |
| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None |
| profile | 유저가 푼 문제 조회 | GET | api/profile/solved:id | 바로가기 | None |
| profile | 유저가 푼 문제 동기화 | Update | api/profile/solved:id | 바로가기 | None |
| profile | 유저가 푼 문제 개수 조회 | GET | api/profile/solvednum:id | 바로가기 | None |
| profile | 추천 문제 조회 | GET | api/profile/recommendps:id | 바로가기 | None |
| notify | 슬랙 메시지 전송 요청 | POST | api/notify/slack | 바로가기 | Jwt Token |
...
...
jaksimsamil-server/index.js
View file @
664acc3
const
express
=
require
(
"express"
);
const
morgan
=
require
(
"morgan"
);
const
Koa
=
require
(
"koa"
);
const
Router
=
require
(
"koa-router"
);
const
bodyParser
=
require
(
"koa-bodyparser"
);
const
mongoose
=
require
(
"mongoose"
);
const
app
=
express
();
const
bodyParser
=
require
(
"body-parser"
);
const
api
=
require
(
"./src/api"
);
const
jwtMiddleware
=
require
(
"./src/lib/jwtMiddleware"
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
require
(
"dotenv"
).
config
();
const
{
SERVER_PORT
,
MONGO_URL
}
=
process
.
env
;
app
.
use
(
morgan
(
"dev"
));
app
.
use
(
express
.
json
());
app
.
use
(
express
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
());
app
.
use
(
jwtMiddleware
);
const
api
=
require
(
"./src/api"
);
const
{
SERVER_PORT
,
MONGO_URL
}
=
process
.
env
;
router
.
use
(
"/api"
,
api
.
routes
());
app
.
use
(
router
.
routes
()).
use
(
router
.
allowedMethods
());
app
.
use
(
"/api"
,
api
);
mongoose
.
connect
(
MONGO_URL
,
{
useNewUrlParser
:
true
,
useFindAndModify
:
false
})
.
connect
(
MONGO_URL
,
{
useNewUrlParser
:
true
,
useFindAndModify
:
false
,
useUnifiedTopology
:
true
,
})
.
then
(()
=>
{
console
.
log
(
"Connected to MongoDB"
);
})
...
...
jaksimsamil-server/package-lock.json
View file @
664acc3
This diff is collapsed. Click to expand it.
jaksimsamil-server/package.json
View file @
664acc3
...
...
@@ -8,13 +8,16 @@
"bcrypt"
:
"^4.0.1"
,
"body-parser"
:
"^1.19.0"
,
"cheerio"
:
"^1.0.0-rc.3"
,
"cookie-parser"
:
"^1.4.5"
,
"dotenv"
:
"^8.2.0"
,
"eslint-config-prettier"
:
"^6.11.0"
,
"express"
:
"^4.17.1"
,
"fs"
:
"^0.0.1-security"
,
"iconv"
:
"^3.0.0"
,
"joi"
:
"^14.3.1"
,
"jsonwebtoken"
:
"^8.5.1"
,
"koa"
:
"^2.12.0"
,
"koa-bodyparser"
:
"^4.3.0"
,
"koa-router"
:
"^9.0.1"
,
"mongoose"
:
"^5.9.17"
,
"morgan"
:
"^1.10.0"
,
"path"
:
"^0.12.7"
,
...
...
jaksimsamil-server/src/api/auth/auth.ctrl.js
View file @
664acc3
...
...
@@ -12,6 +12,7 @@ exports.register = async (ctx) => {
username
:
Joi
.
string
().
alphanum
().
min
(
3
).
max
(
20
).
required
(),
password
:
Joi
.
string
().
required
(),
});
const
result
=
Joi
.
validate
(
ctx
.
request
.
body
,
schema
);
if
(
result
.
error
)
{
ctx
.
status
=
400
;
...
...
@@ -33,7 +34,7 @@ exports.register = async (ctx) => {
await
user
.
save
();
ctx
.
body
=
user
.
serialize
();
const
token
=
user
.
generateTo
ek
n
();
const
token
=
user
.
generateTo
ke
n
();
ctx
.
cookies
.
set
(
"acces_token"
,
token
,
{
//3일동안 유효
maxAge
:
1000
*
60
*
60
*
24
*
3
,
...
...
jaksimsamil-server/src/api/auth/index.js
View file @
664acc3
const
express
=
require
(
"express"
);
const
router
=
express
.
Router
();
router
.
post
(
"/login"
);
router
.
get
(
"/logout"
);
router
.
post
(
"/register"
);
module
.
exports
=
router
;
const
Router
=
require
(
"koa-router"
);
const
auth
=
new
Router
();
const
authCtrl
=
require
(
"./auth.ctrl"
);
auth
.
post
(
"/login"
,
authCtrl
.
login
);
auth
.
get
(
"/logout"
,
authCtrl
.
logout
);
auth
.
post
(
"/register"
,
authCtrl
.
register
);
module
.
exports
=
auth
;
...
...
jaksimsamil-server/src/api/friend/index.js
View file @
664acc3
const
express
=
require
(
"express
"
);
const
router
=
express
.
Router
();
const
Router
=
require
(
"koa-router
"
);
const
friend
=
new
Router
();
router
.
post
(
"/"
);
router
.
delete
(
"/:id"
);
router
.
get
(
"/:id"
);
router
.
get
(
""
);
friend
.
post
(
"/"
);
friend
.
delete
(
"/:id"
);
friend
.
get
(
"/:id"
);
friend
.
get
(
""
);
module
.
exports
=
router
;
module
.
exports
=
friend
;
...
...
jaksimsamil-server/src/api/index.js
View file @
664acc3
const
express
=
require
(
"express
"
);
const
ap
p
=
express
();
const
Router
=
require
(
"koa-router
"
);
const
ap
i
=
new
Router
();
const
auth
=
require
(
"./auth"
);
const
friend
=
require
(
"./friend"
);
...
...
@@ -7,10 +7,10 @@ const notify = require("./profile");
const
user
=
require
(
"./user"
);
const
profile
=
require
(
"./profile"
);
ap
p
.
use
(
"/auth"
,
auth
);
ap
p
.
use
(
"/friend"
,
friend
);
ap
p
.
use
(
"/notify"
,
notify
);
ap
p
.
use
(
"/user"
,
user
);
ap
p
.
use
(
"/profile"
,
profile
);
ap
i
.
use
(
"/auth"
,
auth
.
routes
()
);
ap
i
.
use
(
"/friend"
,
friend
.
routes
()
);
ap
i
.
use
(
"/notify"
,
notify
.
routes
()
);
ap
i
.
use
(
"/user"
,
user
.
routes
()
);
ap
i
.
use
(
"/profile"
,
profile
.
routes
()
);
module
.
exports
=
ap
p
;
module
.
exports
=
ap
i
;
...
...
jaksimsamil-server/src/api/notify/index.js
View file @
664acc3
const
express
=
require
(
"express
"
);
const
router
=
express
.
Router
();
const
Router
=
require
(
"koa-router
"
);
const
notify
=
new
Router
();
router
.
post
(
"/slack"
);
notify
.
post
(
"/slack"
);
module
.
exports
=
router
;
module
.
exports
=
notify
;
...
...
jaksimsamil-server/src/api/profile/index.js
View file @
664acc3
const
express
=
require
(
"express
"
);
const
router
=
express
.
Router
();
const
Router
=
require
(
"koa-router
"
);
const
profile
=
new
Router
();
router
.
post
(
"/solved:id"
);
router
.
get
(
"/solvednum:id"
);
router
.
get
(
"recommendps:id"
);
profile
.
post
(
"/solved:id"
);
profile
.
get
(
"/solvednum:id"
);
profile
.
get
(
"recommendps:id"
);
module
.
exports
=
router
;
module
.
exports
=
profile
;
...
...
jaksimsamil-server/src/api/user/index.js
View file @
664acc3
const
express
=
require
(
"express"
);
const
router
=
express
.
Router
();
const
Router
=
require
(
"koa-router"
);
const
user
=
new
Router
();
user
.
post
(
"/"
);
user
.
delete
(
"/:id"
);
user
.
get
(
"/:id"
);
user
.
get
(
""
);
router
.
post
(
"/"
);
router
.
delete
(
"/:id"
);
router
.
get
(
"/:id"
);
router
.
get
(
""
);
module
.
exports
=
router
;
module
.
exports
=
user
;
...
...
jaksimsamil-server/src/models/user.js
View file @
664acc3
const
mongoose
=
require
(
"mongoose"
);
const
bcrypt
=
require
(
"bcrypt"
);
const
jwt
=
require
(
"jsonwebtoken"
);
const
Schema
=
mongoose
.
Schema
;
const
UserSchema
=
new
Schema
({
...
...
@@ -12,7 +13,7 @@ UserSchema.methods.setPassword = async function (password) {
const
hash
=
await
bcrypt
.
hash
(
password
,
10
);
this
.
hashedPassword
=
hash
;
};
UserSchema
.
methods
s
.
checkPassword
=
async
function
(
password
)
{
UserSchema
.
methods
.
checkPassword
=
async
function
(
password
)
{
const
result
=
await
bcrypt
.
compare
(
password
,
this
.
hashedPassword
);
return
result
;
};
...
...
jaksimsamil-server/yarn.lock
View file @
664acc3
This diff is collapsed. Click to expand it.
Please
register
or
login
to post a comment