This commit is contained in:
Rutra
2026-05-04 14:16:59 +02:00
commit 03a14da804
60 changed files with 10549 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import env from '#start/env';
export default class AuthController {
async showLogin({ view, session, response }) {
if (session.get('is_authenticated')) {
return response.redirect().toPath('/');
}
return view.render('login');
}
async login({ request, session, response }) {
const { username, password } = request.only(['username', 'password']);
const validUsername = env.get('AUTH_USERNAME');
const validPassword = env.get('AUTH_PASSWORD');
if (username === validUsername && password === validPassword) {
session.put('is_authenticated', true);
session.put('username', username);
const intendedUrl = session.get('intended_url', '/');
session.forget('intended_url');
return response.redirect().toPath(intendedUrl);
}
session.flash('errors', { form: 'Invalid username or password.' });
session.flashOnly(['username']);
return response.redirect().toPath('/login');
}
async logout({ session, response }) {
session.clear();
return response.redirect().toPath('/login');
}
}
//# sourceMappingURL=auth_controller.js.map