Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-05-11 02:38:32 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
16aaa1c40016f7c4f417296407d5a9bd268c2f46
16aaa1c4
1 parent
562d2748
fix. syntax error
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
server/src/api/auth/auth.ctrl.js
server/src/models/user.js
server/src/api/auth/auth.ctrl.js
View file @
16aaa1c
...
...
@@ -5,7 +5,7 @@ const Joi = require('joi');
exports
.
register
=
async
(
ctx
)
=>
{
const
{
userId
,
password
,
passwordCheck
}
=
ctx
.
request
.
body
;
const
schema
=
Joi
.
object
.
keys
({
const
schema
=
Joi
.
object
()
.
keys
({
userId
:
Joi
.
string
().
min
(
8
).
max
(
15
).
required
(),
password
:
Joi
.
string
().
required
(),
passwordCheck
:
Joi
.
string
().
required
(),
...
...
@@ -37,7 +37,7 @@ exports.register = async(ctx) => {
exports
.
login
=
async
(
ctx
)
=>
{
const
{
userId
,
password
}
=
ctx
.
request
.
body
;
const
schema
=
Joi
.
object
.
keys
({
const
schema
=
Joi
.
object
()
.
keys
({
userId
:
Joi
.
string
().
min
(
8
).
max
(
15
).
required
(),
password
:
Joi
.
string
().
required
()
})
...
...
@@ -67,7 +67,9 @@ exports.login = async(ctx) => {
});
ctx
.
status
=
201
;
ctx
.
body
=
user
;
ctx
.
body
=
{
userId
};
};
...
...
@@ -76,6 +78,7 @@ exports.logout = async(ctx) => {
httpOnly
:
true
,
maxAge
:
0
});
ctx
.
status
=
204
;
ctx
.
body
=
null
;
};
\ No newline at end of file
...
...
server/src/models/user.js
View file @
16aaa1c
const
mongoose
=
require
(
'mongoose'
);
const
b
y
crypt
=
require
(
'bcrypt'
);
const
bcrypt
=
require
(
'bcrypt'
);
const
jwt
=
require
(
'jsonwebtoken'
);
const
Schema
=
mongoose
.
Schema
;
...
...
@@ -10,12 +10,12 @@ const UserSchema = new Schema({
});
UserSchema
.
methods
.
setPassword
=
async
function
(
password
)
{
const
hash
=
await
b
ycrypt
(
password
,
10
);
const
hash
=
await
b
crypt
.
hash
(
password
,
10
);
this
.
hashedPassword
=
hash
;
};
UserSchema
.
methods
.
checkPassword
=
async
function
(
password
)
{
const
result
=
await
b
y
crypt
.
compare
(
password
,
this
.
hashedPassword
)
const
result
=
await
bcrypt
.
compare
(
password
,
this
.
hashedPassword
)
return
result
;
};
...
...
Please
register
or
login
to post a comment