Showing
2 changed files
with
9 additions
and
6 deletions
| ... | @@ -5,7 +5,7 @@ const Joi = require('joi'); | ... | @@ -5,7 +5,7 @@ const Joi = require('joi'); |
| 5 | exports.register = async(ctx) => { | 5 | exports.register = async(ctx) => { |
| 6 | const { userId, password, passwordCheck } = ctx.request.body; | 6 | const { userId, password, passwordCheck } = ctx.request.body; |
| 7 | 7 | ||
| 8 | - const schema = Joi.object.keys({ | 8 | + const schema = Joi.object().keys({ |
| 9 | userId : Joi.string().min(8).max(15).required(), | 9 | userId : Joi.string().min(8).max(15).required(), |
| 10 | password : Joi.string().required(), | 10 | password : Joi.string().required(), |
| 11 | passwordCheck : Joi.string().required(), | 11 | passwordCheck : Joi.string().required(), |
| ... | @@ -37,7 +37,7 @@ exports.register = async(ctx) => { | ... | @@ -37,7 +37,7 @@ exports.register = async(ctx) => { |
| 37 | exports.login = async(ctx) => { | 37 | exports.login = async(ctx) => { |
| 38 | const { userId, password } = ctx.request.body; | 38 | const { userId, password } = ctx.request.body; |
| 39 | 39 | ||
| 40 | - const schema = Joi.object.keys({ | 40 | + const schema = Joi.object().keys({ |
| 41 | userId : Joi.string().min(8).max(15).required(), | 41 | userId : Joi.string().min(8).max(15).required(), |
| 42 | password : Joi.string().required() | 42 | password : Joi.string().required() |
| 43 | }) | 43 | }) |
| ... | @@ -67,7 +67,9 @@ exports.login = async(ctx) => { | ... | @@ -67,7 +67,9 @@ exports.login = async(ctx) => { |
| 67 | }); | 67 | }); |
| 68 | 68 | ||
| 69 | ctx.status = 201; | 69 | ctx.status = 201; |
| 70 | - ctx.body = user; | 70 | + ctx.body = { |
| 71 | + userId | ||
| 72 | + }; | ||
| 71 | 73 | ||
| 72 | }; | 74 | }; |
| 73 | 75 | ||
| ... | @@ -76,6 +78,7 @@ exports.logout = async(ctx) => { | ... | @@ -76,6 +78,7 @@ exports.logout = async(ctx) => { |
| 76 | httpOnly : true, | 78 | httpOnly : true, |
| 77 | maxAge : 0 | 79 | maxAge : 0 |
| 78 | }); | 80 | }); |
| 81 | + | ||
| 79 | ctx.status = 204; | 82 | ctx.status = 204; |
| 80 | ctx.body = null; | 83 | ctx.body = null; |
| 81 | }; | 84 | }; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | const mongoose = require('mongoose'); | 1 | const mongoose = require('mongoose'); |
| 2 | -const bycrypt = require('bcrypt'); | 2 | +const bcrypt = require('bcrypt'); |
| 3 | const jwt = require('jsonwebtoken'); | 3 | const jwt = require('jsonwebtoken'); |
| 4 | 4 | ||
| 5 | const Schema = mongoose.Schema; | 5 | const Schema = mongoose.Schema; |
| ... | @@ -10,12 +10,12 @@ const UserSchema = new Schema({ | ... | @@ -10,12 +10,12 @@ const UserSchema = new Schema({ |
| 10 | }); | 10 | }); |
| 11 | 11 | ||
| 12 | UserSchema.methods.setPassword = async function(password) { | 12 | UserSchema.methods.setPassword = async function(password) { |
| 13 | - const hash = await bycrypt(password, 10); | 13 | + const hash = await bcrypt.hash(password, 10); |
| 14 | this.hashedPassword = hash; | 14 | this.hashedPassword = hash; |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | UserSchema.methods.checkPassword = async function(password) { | 17 | UserSchema.methods.checkPassword = async function(password) { |
| 18 | - const result = await bycrypt.compare(password, this.hashedPassword) | 18 | + const result = await bcrypt.compare(password, this.hashedPassword) |
| 19 | return result; | 19 | return result; |
| 20 | }; | 20 | }; |
| 21 | 21 | ... | ... |
-
Please register or login to post a comment