2013-12-23 02:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
2014-03-17 02:56:43 +01:00
|
|
|
require_once __DIR__.'/../lib/AuthProvider.php';
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
use PicoFarad\Router;
|
|
|
|
use PicoFarad\Response;
|
|
|
|
use PicoFarad\Request;
|
|
|
|
use PicoFarad\Session;
|
2014-03-17 02:56:43 +01:00
|
|
|
use PicoFarad\Template;
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
// Logout and destroy session
|
|
|
|
Router\get_action('logout', function() {
|
|
|
|
|
2014-05-27 02:47:40 +02:00
|
|
|
Model\RememberMe\destroy();
|
2013-12-23 02:55:53 +01:00
|
|
|
Session\close();
|
|
|
|
Response\redirect('?action=login');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display form login
|
|
|
|
Router\get_action('login', function() {
|
|
|
|
|
2014-05-27 02:47:40 +02:00
|
|
|
if (isset($_SESSION['user'])) {
|
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'google_auth_enable' => Model\Config\get('auth_google_token') !== '',
|
|
|
|
'mozilla_auth_enable' => Model\Config\get('auth_mozilla_token') !== '',
|
|
|
|
'errors' => array(),
|
2014-04-06 02:24:13 +02:00
|
|
|
'values' => array(),
|
|
|
|
'databases' => Model\Database\get_list(),
|
|
|
|
'current_database' => Model\Database\select()
|
2013-12-23 02:55:53 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check credentials and redirect to unread items
|
|
|
|
Router\post_action('login', function() {
|
|
|
|
|
|
|
|
$values = Request\values();
|
|
|
|
list($valid, $errors) = Model\User\validate_login($values);
|
|
|
|
|
2014-05-27 02:47:40 +02:00
|
|
|
if ($valid) {
|
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'google_auth_enable' => Model\Config\get('auth_google_token') !== '',
|
|
|
|
'mozilla_auth_enable' => Model\Config\get('auth_mozilla_token') !== '',
|
|
|
|
'errors' => $errors,
|
2014-04-06 02:24:13 +02:00
|
|
|
'values' => $values,
|
|
|
|
'databases' => Model\Database\get_list(),
|
|
|
|
'current_database' => Model\Database\select()
|
2013-12-23 02:55:53 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Link to a Google Account (redirect)
|
|
|
|
Router\get_action('google-redirect-link', function() {
|
|
|
|
|
|
|
|
Response\Redirect(AuthProvider\google_get_url(Helper\get_current_base_url(), '?action=google-link'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Link to a Google Account (association)
|
|
|
|
Router\get_action('google-link', function() {
|
|
|
|
|
|
|
|
list($valid, $token) = AuthProvider\google_validate();
|
|
|
|
|
|
|
|
if ($valid) {
|
|
|
|
Model\Config\save_auth_token('google', $token);
|
|
|
|
Session\flash(t('Your Google Account is linked to Miniflux.'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session\flash_error(t('Unable to link Miniflux to your Google Account.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\redirect('?action=config');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Authenticate with a Google Account (redirect)
|
|
|
|
Router\get_action('google-redirect-auth', function() {
|
|
|
|
|
|
|
|
Response\Redirect(AuthProvider\google_get_url(Helper\get_current_base_url(), '?action=google-auth'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Authenticate with a Google Account (callback url)
|
|
|
|
Router\get_action('google-auth', function() {
|
|
|
|
|
|
|
|
list($valid, $token) = AuthProvider\google_validate();
|
|
|
|
|
|
|
|
if ($valid && $token === Model\Config\get('auth_google_token')) {
|
|
|
|
|
|
|
|
$_SESSION['user'] = array(
|
|
|
|
'username' => Model\Config\get('username'),
|
|
|
|
'language' => Model\Config\get('language'),
|
|
|
|
);
|
|
|
|
|
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'google_auth_enable' => Model\Config\get('auth_google_token') !== '',
|
|
|
|
'mozilla_auth_enable' => Model\Config\get('auth_mozilla_token') !== '',
|
|
|
|
'errors' => array('login' => t('Unable to authenticate with Google')),
|
|
|
|
'values' => array()
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Authenticate with a Mozilla Persona (ajax check)
|
|
|
|
Router\post_action('mozilla-auth', function() {
|
|
|
|
|
2013-12-23 03:43:29 +01:00
|
|
|
list($valid, $token) = AuthProvider\mozilla_validate(Request\param('token'));
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
if ($valid && $token === Model\Config\get('auth_mozilla_token')) {
|
|
|
|
|
|
|
|
$_SESSION['user'] = array(
|
|
|
|
'username' => Model\Config\get('username'),
|
|
|
|
'language' => Model\Config\get('language'),
|
|
|
|
);
|
|
|
|
|
|
|
|
Response\text('?action=unread');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Response\text("?action=login");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Link Miniflux to a Mozilla Account (ajax check)
|
|
|
|
Router\post_action('mozilla-link', function() {
|
|
|
|
|
2013-12-23 03:43:29 +01:00
|
|
|
list($valid, $token) = AuthProvider\mozilla_validate(Request\param('token'));
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
if ($valid) {
|
|
|
|
Model\Config\save_auth_token('mozilla', $token);
|
|
|
|
Session\flash(t('Your Mozilla Persona Account is linked to Miniflux.'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session\flash_error(t('Unable to link Miniflux to your Mozilla Persona Account.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\text("?action=config");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Remove account link
|
|
|
|
Router\get_action('unlink-account-provider', function() {
|
|
|
|
Model\Config\remove_auth_token(Request\param('type'));
|
|
|
|
Response\redirect('?action=config');
|
|
|
|
});
|