generated from osamhack2021/Repo_Sample-Technology_ProjectName_TeamName
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/backend/#152
- Loading branch information
Showing
9 changed files
with
77 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,44 @@ | ||
|
||
const authService = require('../services/authService.js'); | ||
const userService = require('../services/userService.js'); | ||
|
||
module.exports = { | ||
async login(req, res) { | ||
try { | ||
const { user, token } = await authService.login(req.body); | ||
const projection = { | ||
_id: true, | ||
serviceNumber: true, | ||
password: true, | ||
name: true, | ||
rank: true, | ||
title: true, | ||
status: true, | ||
group: true, | ||
email: true, | ||
tel: true, | ||
lastLogin: true, | ||
firstLogin: true, | ||
bookmarks: true, | ||
subscriptions: true, | ||
}; | ||
res.cookie('jwt', token); | ||
res.status(200).send({ | ||
result: 'OK', | ||
user, | ||
token, | ||
}); | ||
} catch (err) { | ||
res.status(err.status || 500).send(err.message); | ||
} | ||
}, | ||
login: async function(req, res) { | ||
try { | ||
const token = await authService.login(req.body); | ||
const projection = { | ||
_id:true, | ||
serviceNumber: true, | ||
name:true, | ||
rank:true, | ||
title:true, | ||
status:true, | ||
group: true, | ||
email:true, | ||
tel: true, | ||
lastLogin:true, | ||
firstLogin:true, | ||
bookmarks:true, | ||
subscriptions:true | ||
}; | ||
const user = await userService.findOne({serviceNumber:req.body.serviceNumber}, projection); | ||
|
||
res.cookie('jwt', token); | ||
res.status(200).send({ | ||
result: 'OK', | ||
user, | ||
token | ||
}); | ||
|
||
async logout(req, res) { | ||
res.cookie('jwt', ''); | ||
res.status(200).send({ | ||
result: 'OK', | ||
}); | ||
}, | ||
}; | ||
} catch(err) { | ||
res.status(err.status || 500).send(err.message); | ||
} | ||
}, | ||
|
||
logout: async function(req, res) { | ||
res.cookie('jwt', ''); | ||
res.status(200).send({ | ||
result: 'OK', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.