Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- routes: {
- 'POST /user/login': async function (req, res) {
- const { login, password } = req.body
- const responseBody = await this.controllers.userLogin(login, password)
- return res(responseBody {
- type: 'application/json',
- headers: [
- 'Api-Version': '1.0.1',
- ]
- })
- }
- },
- controllers: {
- userLogin: async function (login, password) {
- const userLoginDto = new UserLoginDto(login, password)
- const requestBody = await this.services.useLoginService(userLoginDto)
- return requestBody
- }
- }
- services: {
- userLoginService: async function (userLoginDto) {
- const sessionToken = await this.repositories.user.validateCredentials(userLoginDto)
- return sessionToken
- }
- }
- repositories: {
- user: {
- validateCredentials: async function (login, password) {
- const { login, password } = userLoginDto
- const user = await this.entities.userEntity.findOne({ username: login })
- if (user && user.methods.validatePassword(password)) {
- return {
- token: user.getSessionToken(login, password)
- }
- } else {
- return null
- }
- }
- }
- }
- entities: {
- userEntity: {
- schema: {
- id: {
- type: number,
- relation: 'Column'
- },
- likes: {
- type: array,
- relation: 'OneToMany'
- relations: ...
- },
- password...
- salt...
- },
- methods: {
- validatePassword: async function (password) {
- const hash = await bcrypt.hash(password, this....schema.salt)
- }
- return hash === this.[Symbol].schema.password
- }
- }
- }
- }
- // dariuszsikorski.pl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement