nfp_sites/api/authentication/routes.mjs

33 lines
792 B
JavaScript
Raw Normal View History

2019-09-14 19:03:38 +00:00
import Staff from '../staff/model.mjs'
import Jwt from '../jwt.mjs'
import * as security from './security.mjs'
import AuthHelper from './helper.mjs'
2019-02-20 16:10:37 +00:00
export default class AuthRoutes {
constructor(opts = {}) {
Object.assign(this, {
helper: opts.helper || new AuthHelper(),
2019-02-20 16:10:37 +00:00
Staff: opts.Staff || Staff,
jwt: opts.jwt || new Jwt(),
security: opts.security || security,
2019-02-20 16:10:37 +00:00
})
}
/*
* POST /api/login/user - Authenticate a user using password login
*
* @body {string} username - Username
* @body {string} password - Password
* @returns
*
* { token: 'Authentication token' }
*/
async loginUser(ctx) {
this.security.isValidLogin(ctx, ctx.request.body)
let token = await this.helper.loginStaff(ctx)
ctx.body = { token }
}
2019-02-20 16:10:37 +00:00
}