|
@@ -1,6 +1,7 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
use oxusmedia\webApp\controller;
|
|
use oxusmedia\webApp\controller;
|
|
|
|
+use oxusmedia\webApp\MyWebauthn;
|
|
use oxusmedia\webApp\form;
|
|
use oxusmedia\webApp\form;
|
|
use oxusmedia\webApp\column;
|
|
use oxusmedia\webApp\column;
|
|
use oxusmedia\webApp\input;
|
|
use oxusmedia\webApp\input;
|
|
@@ -9,11 +10,14 @@ use oxusmedia\webApp\button;
|
|
|
|
|
|
class site extends controller
|
|
class site extends controller
|
|
{
|
|
{
|
|
|
|
+ const LOGIN_METHOD_PASSWORD = 'P';
|
|
|
|
+ const LOGIN_METHOD_WEBAUTHN = 'W';
|
|
|
|
+
|
|
public function index()
|
|
public function index()
|
|
{
|
|
{
|
|
$this->webApp()->requireLoginRedir();
|
|
$this->webApp()->requireLoginRedir();
|
|
|
|
|
|
- $this->titulo = '';
|
|
|
|
|
|
+ $this->titulo = 'Bienvenido';
|
|
|
|
|
|
$this->render('index');
|
|
$this->render('index');
|
|
}
|
|
}
|
|
@@ -24,11 +28,51 @@ class site extends controller
|
|
|
|
|
|
$this->redirect($this->webApp()->getSite());
|
|
$this->redirect($this->webApp()->getSite());
|
|
|
|
|
|
- else{
|
|
|
|
|
|
+ else {
|
|
|
|
|
|
- if (isset($_POST["login"])) {
|
|
|
|
|
|
+ $form = new form('login', array(
|
|
|
|
+ new column(array(
|
|
|
|
+ ($this->webApp()->getConfig('LOGIN_WITH_EMAIL')
|
|
|
|
+ ? new input('email', array(
|
|
|
|
+ 'rules' => array(
|
|
|
|
+ 'required' => true,
|
|
|
|
+ 'email' => true
|
|
|
|
+ ),
|
|
|
|
+ 'htmlOptions' => array(
|
|
|
|
+ 'placeholder' => 'Email',
|
|
|
|
+ 'class' => 'step1'
|
|
|
|
+ ),
|
|
|
|
+ 'value' => $_COOKIE['login_email'] ?? ''
|
|
|
|
+ ))
|
|
|
|
+ : new input('usuario', array(
|
|
|
|
+ 'rules' => array(
|
|
|
|
+ 'required' => true
|
|
|
|
+ ),
|
|
|
|
+ 'htmlOptions' => array(
|
|
|
|
+ 'placeholder' => 'Usuario',
|
|
|
|
+ 'class' => 'step1'
|
|
|
|
+ )
|
|
|
|
+ ))
|
|
|
|
+ ),
|
|
|
|
+ new password('pass', array(
|
|
|
|
+ 'htmlOptions' => array(
|
|
|
|
+ 'placeholder' => 'Contraseña',
|
|
|
|
+ 'class' => 'step2'
|
|
|
|
+ )
|
|
|
|
+ ))
|
|
|
|
+ ))
|
|
|
|
+ ), array(
|
|
|
|
+ 'buttons' => array(
|
|
|
|
+ new button('siguiente', button::SUBMIT, button::PRIMARY),
|
|
|
|
+ new button('cancelar', button::BUTTON, button::SECONDARY, array(
|
|
|
|
+ 'htmlOptions' => array(
|
|
|
|
+ 'class' => 'step2'
|
|
|
|
+ )
|
|
|
|
+ ))
|
|
|
|
+ )
|
|
|
|
+ ));
|
|
|
|
|
|
- $form = $this->constructLoginForm();
|
|
|
|
|
|
+ if (isset($_POST['login'])) {
|
|
|
|
|
|
$form->setAtributes($_POST['login']);
|
|
$form->setAtributes($_POST['login']);
|
|
|
|
|
|
@@ -36,9 +80,12 @@ class site extends controller
|
|
|
|
|
|
$param = $form->getAtributes();
|
|
$param = $form->getAtributes();
|
|
|
|
|
|
- if ($this->webApp()->login($param["usuario"], $param["contrasena"])) {
|
|
|
|
|
|
+ if ($this->webApp()->login($param['email'], $param['pass'])) {
|
|
|
|
+
|
|
|
|
+ $this->webApp()->setCookie('login_email', $param['email']);
|
|
|
|
+ $this->webApp()->setCookie('login_method', $this::LOGIN_METHOD_PASSWORD);
|
|
|
|
|
|
- $this->redirect($this->webApp()->getSite());
|
|
|
|
|
|
+ $this->redirect($this->getMethodUrl('registerWebauthn'));
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -50,42 +97,120 @@ class site extends controller
|
|
|
|
|
|
$this->titulo = 'Iniciar sesión';
|
|
$this->titulo = 'Iniciar sesión';
|
|
|
|
|
|
- $this->addCss($this->webApp()->getSite() . 'assets/css/login.css');
|
|
|
|
|
|
+ MyWebauthn::initialize();
|
|
|
|
+
|
|
|
|
+ $this->addCss($this->webApp()->getUrlAssets() . 'css/login.css');
|
|
|
|
+
|
|
|
|
+ $this->addJs($this->webApp()->getUrlAssets() . 'webapp/js/jquery.validate.min.js');
|
|
|
|
+ $this->addJs($this->webApp()->getUrlAssets() . 'webapp/js/additional-methods.min.js');
|
|
|
|
+ $this->addJs($this->webApp()->getUrlAssets() . 'webapp/js/jquery.validate.messages_es_AR.js');
|
|
|
|
|
|
$this->render('login', array(
|
|
$this->render('login', array(
|
|
- 'loginForm' => $this->constructLoginForm()
|
|
|
|
|
|
+ 'method' => $_COOKIE['login_method'] ?? $this::LOGIN_METHOD_PASSWORD,
|
|
|
|
+ 'form' => $form
|
|
));
|
|
));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private function constructLoginForm()
|
|
|
|
|
|
+ public function loginWebauthnStep1()
|
|
{
|
|
{
|
|
- return new form('login',
|
|
|
|
- array(
|
|
|
|
- new column(array(
|
|
|
|
- new input('usuario'),
|
|
|
|
- new password('contrasena', array(
|
|
|
|
- 'label' => 'Contraseña',
|
|
|
|
- ))
|
|
|
|
|
|
+ if (isset($_GET['email']))
|
|
|
|
+ $this->returnJson(
|
|
|
|
+ MyWebauthn::loginStep1($_GET['email'])
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function loginWebauthnStep2()
|
|
|
|
+ {
|
|
|
|
+ $post = trim(file_get_contents('php://input'));
|
|
|
|
+
|
|
|
|
+ if ($post and isset($_GET['email'])) {
|
|
|
|
+
|
|
|
|
+ $return = MyWebauthn::loginStep2($post, $_GET['email']);
|
|
|
|
+
|
|
|
|
+ if ($return->success) {
|
|
|
|
+ $this->webApp()->setCookie('login_email', $_GET['email']);
|
|
|
|
+ $this->webApp()->setCookie('login_method', $this::LOGIN_METHOD_WEBAUTHN);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->returnJson($return);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function registerWebauthn()
|
|
|
|
+ {
|
|
|
|
+ $this->titulo = 'Bienvenido';
|
|
|
|
+
|
|
|
|
+ MyWebauthn::initialize();
|
|
|
|
+
|
|
|
|
+ $this->addJs($this->webApp()->getUrlAssets() . 'webapp/js/jquery.validate.min.js');
|
|
|
|
+ $this->addJs($this->webApp()->getUrlAssets() . 'webapp/js/additional-methods.min.js');
|
|
|
|
+ $this->addJs($this->webApp()->getUrlAssets() . 'webapp/js/jquery.validate.messages_es_AR.js');
|
|
|
|
+
|
|
|
|
+ $form = new form('register', array(
|
|
|
|
+ new column(array(
|
|
|
|
+ new input('dispositivo', array(
|
|
|
|
+ 'label' => '',
|
|
|
|
+ 'htmlOptions' => array(
|
|
|
|
+ 'placeholder' => 'Dispositivo'
|
|
|
|
+ )
|
|
))
|
|
))
|
|
- ),
|
|
|
|
- array(
|
|
|
|
- 'buttons' => array(
|
|
|
|
- new button('login', button::SUBMIT, button::PRIMARY, array(
|
|
|
|
- 'label' => 'Iniciar sesión'
|
|
|
|
- ))
|
|
|
|
- )
|
|
|
|
|
|
+ ))
|
|
|
|
+ ), array(
|
|
|
|
+ 'buttons' => array(
|
|
|
|
+ new button('siguiente', button::SUBMIT, button::PRIMARY),
|
|
|
|
+ new button('cancelar', button::BUTTON, button::SECONDARY)
|
|
)
|
|
)
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ $this->render('webauthn', array(
|
|
|
|
+ 'form' => $form
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function registerWebauthnStep1()
|
|
|
|
+ {
|
|
|
|
+ $this->webApp()->requireLogin();
|
|
|
|
+
|
|
|
|
+ $this->returnJson(
|
|
|
|
+ MyWebauthn::registerStep1($this->webApp()->getUsuarioId())
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function registerWebauthnStep2()
|
|
|
|
+ {
|
|
|
|
+ $this->webApp()->requireLogin();
|
|
|
|
+
|
|
|
|
+ $post = trim(file_get_contents('php://input'));
|
|
|
|
+
|
|
|
|
+ if ($post) {
|
|
|
|
+
|
|
|
|
+ $return = MyWebauthn::registerStep2($post, $_GET['device']);
|
|
|
|
+
|
|
|
|
+ if ($return->success)
|
|
|
|
+ $this->webApp()->setCookie('login_method', $this::LOGIN_METHOD_WEBAUTHN);
|
|
|
|
+
|
|
|
|
+ $this->returnJson($return);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public function logout()
|
|
public function logout()
|
|
{
|
|
{
|
|
$this->webApp()->logout();
|
|
$this->webApp()->logout();
|
|
|
|
|
|
- $this->redirect($this->webApp()->getSite() . 'site/login');
|
|
|
|
|
|
+ $this->redirect($this->getMethodUrl('login'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function downloadCertificates()
|
|
|
|
+ {
|
|
|
|
+ $return = MyWebauthn::downloadFidoCertificates();
|
|
|
|
+
|
|
|
|
+ $this->returnJson($return);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|