seepur/app/Controllers/Http/AuthController.js
Sagi Dayan d7c9359ef2 Basic logic
- DB migrations
 - Login/Register flows
 - Dockerfile
 - Layouts, Partials, Components
 - Sass
 - Bulma.io
 - sqlite
2020-01-18 15:46:06 -05:00

46 lines
1.1 KiB
JavaScript

'use strict'
const User = use('App/Models/User')
class AuthController {
async registerIndex({view}){
return view.render('register')
}
async loginIndex({view}){
return view.render('login')
}
async register({request, response, view, session, auth}){
const user = await User.create({
email: request.input('email'),
name: request.input('name'),
password: request.input('password')
});
await auth.login(user)
response.redirect('/');
}
async login({request,response, auth, session}){
console.log('login');
const { email, password } = request.all()
try{
const token = await auth.attempt(email, password);
console.log('logged in');
}catch(e){
session.withErrors({ loginError: 'Invalid Credentials' }).flashAll()
return response.redirect('back')
}
response.redirect('/');
}
async logout({auth, response}){
await auth.logout();
response.redirect('/');
}
}
module.exports = AuthController