Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/controllers/AuthController.php

60 lines
1.5 KiB
PHP

<?php
namespace App\Controller;
use App\Controller\ControllerBase;
use Form\Login as LoginForm;
class AuthController extends ControllerBase
{
public function indexAction()
{
$form = new LoginForm();
if ($this->request->isPost()) {
$data = $this->request->getPost();
if ($form->isValid($data)) {
$email = $form->getValue('Email');
$passwd = $form->getValue('Password');
// Perform login
if ($this->auth->login($email, $passwd)) {
$this->response->redirect('/');
} else {
$this->flash->message('error', "Invalid credentials");
}
} else {
$msg = '<ul>';
foreach($form->getMessages() as $message) {
$msg .= '<li><strong>' . $message->getField() . '</strong> '. $message->getMessage() . '</li>';
}
$msg .= '</ul>';
$this->flash->message('error', $msg);
}
}
$this->view->form = $form;
}
public function oauthAction()
{
$response = $this->oauth->perform();
if (is_array($response)) {
$this->auth->loginOauth($response['auth']);
}
$this->flash->message('error', 'Failed to authenticate.');
$this->response->redirect('/login');
}
public function logoutAction()
{
$this->auth->clearIdentity();
$this->response->redirect('/');
}
}