diff --git a/admin/controllers/edit-user.php b/admin/controllers/edit-user.php
index 59cc3bad..5b535be8 100644
--- a/admin/controllers/edit-user.php
+++ b/admin/controllers/edit-user.php
@@ -17,14 +17,14 @@ function editUser($args)
}
}
-function setPassword($new, $confirm)
+function setPassword($username, $new_password, $confirm_password)
{
global $dbUsers;
global $Language;
- if( ($new===$confirm) && !Text::isEmpty($new) )
+ if( ($new_password===$confirm_password) && !Text::isEmpty($new_password) )
{
- if( $dbUsers->setPassword($new) ) {
+ if( $dbUsers->setPassword($username, $new_password) ) {
Alert::set($Language->g('The changes have been saved'));
}
else {
@@ -93,7 +93,7 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
deleteUser($_POST, false);
}
elseif( !empty($_POST['new-password']) && !empty($_POST['confirm-password']) ) {
- setPassword($_POST['new-password'], $_POST['confirm-password']);
+ setPassword($_POST['username'], $_POST['new-password'], $_POST['confirm-password']);
}
else {
editUser($_POST);
diff --git a/admin/controllers/login-email.php b/admin/controllers/login-email.php
index a7aca352..32b0f79e 100644
--- a/admin/controllers/login-email.php
+++ b/admin/controllers/login-email.php
@@ -11,8 +11,67 @@
function checkPost($args)
{
global $Security;
- global $Login;
global $Language;
+ global $dbUsers;
+ global $Site;
+
+ if($Security->isBlocked()) {
+ Alert::set($Language->g('IP address has been blocked').'
'.$Language->g('Try again in a few minutes'));
+ return false;
+ }
+
+ // Remove illegal characters from email
+ $email = Sanitize::email($args['email']);
+
+ if(Valid::email($email))
+ {
+ $user = $dbUsers->getByEmail($email);
+ if($user!=false)
+ {
+ // Generate the token and the token expiration date.
+ $token = $dbUsers->generateTokenEmail($user['username']);
+
+ // ---- EMAIL ----
+ $link = $Site->url().'admin/login-email?tokenEmail='.$token.'&username='.$user['username'];
+ $subject = $Language->g('BLUDIT Login access code');
+ $message = Text::replaceAssoc(
+ array(
+ '{{WEBSITE_NAME}}'=>$Site->title(),
+ '{{LINK}}'=>''.$link.''
+ ),
+ $Language->g('email-notification-login-access-code')
+ );
+
+ $sent = Email::send(array(
+ 'from'=>$Site->emailFrom(),
+ 'to'=>$email,
+ 'subject'=>$subject,
+ 'message'=>$message
+ ));
+
+ if($sent) {
+ Alert::set($Language->g('check-your-inbox-for-your-login-access-code'));
+ return true;
+ }
+ else {
+ Alert::set($Language->g('There was a problem sending the email'));
+ return false;
+ }
+ }
+ }
+
+ // Bruteforce protection, add IP to blacklist.
+ $Security->addLoginFail();
+ Alert::set($Language->g('check-your-inbox-for-your-login-access-code'));
+
+ return false;
+}
+
+function checkGet($args)
+{
+ global $Security;
+ global $Language;
+ global $Login;
if($Security->isBlocked()) {
Alert::set($Language->g('IP address has been blocked').'
'.$Language->g('Try again in a few minutes'));
@@ -20,9 +79,9 @@ function checkPost($args)
}
// Verify User sanitize the input
- if( $Login->verifyUser($_POST['username'], $_POST['password']) )
+ if( $Login->verifyUserByToken($args['username'], $args['tokenEmail']) )
{
- // Renew the token. This token will be the same inside the session for multiple forms.
+ // Renew the tokenCRFS. This token will be the same inside the session for multiple forms.
$Security->generateToken();
Redirect::page('admin', 'dashboard');
@@ -31,8 +90,6 @@ function checkPost($args)
// Bruteforce protection, add IP to blacklist.
$Security->addLoginFail();
- Alert::set($Language->g('Username or password incorrect'));
-
return false;
}
@@ -40,6 +97,16 @@ function checkPost($args)
// Main before POST
// ============================================================================
+// ============================================================================
+// GET Method
+// ============================================================================
+
+if( !empty($_GET['tokenEmail']) && !empty($_GET['username']) )
+{
+ checkGet($_GET);
+}
+
+
// ============================================================================
// POST Method
// ============================================================================
diff --git a/admin/views/add-user.php b/admin/views/add-user.php
index 6a2b055d..ff3b871d 100644
--- a/admin/views/add-user.php
+++ b/admin/views/add-user.php
@@ -6,7 +6,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
// Security token
HTML::formInputHidden(array(
- 'name'=>'token',
+ 'name'=>'tokenCSRF',
'value'=>$Security->getToken()
));
diff --git a/admin/views/configure-plugin.php b/admin/views/configure-plugin.php
index 4511bf10..28a4f4f0 100644
--- a/admin/views/configure-plugin.php
+++ b/admin/views/configure-plugin.php
@@ -6,7 +6,7 @@ HTML::formOpen(array('id'=>'jsformplugin'));
// Security token
HTML::formInputHidden(array(
- 'name'=>'token',
+ 'name'=>'tokenCSRF',
'value'=>$Security->getToken()
));
diff --git a/admin/views/edit-page.php b/admin/views/edit-page.php
index 5f5bd18c..1e05de23 100644
--- a/admin/views/edit-page.php
+++ b/admin/views/edit-page.php
@@ -6,7 +6,7 @@ HTML::formOpen(array('class'=>'uk-form-stacked'));
// Security token
HTML::formInputHidden(array(
- 'name'=>'token',
+ 'name'=>'tokenCSRF',
'value'=>$Security->getToken()
));
diff --git a/admin/views/edit-post.php b/admin/views/edit-post.php
index 03d14e37..9a26ec14 100644
--- a/admin/views/edit-post.php
+++ b/admin/views/edit-post.php
@@ -6,7 +6,7 @@ HTML::formOpen(array('class'=>'uk-form-stacked'));
// Security token
HTML::formInputHidden(array(
- 'name'=>'token',
+ 'name'=>'tokenCSRF',
'value'=>$Security->getToken()
));
diff --git a/admin/views/edit-user.php b/admin/views/edit-user.php
index 5e2ecad5..b9afed03 100644
--- a/admin/views/edit-user.php
+++ b/admin/views/edit-user.php
@@ -6,7 +6,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
// Security token
HTML::formInputHidden(array(
- 'name'=>'token',
+ 'name'=>'tokenCSRF',
'value'=>$Security->getToken()
));
diff --git a/admin/views/login-email.php b/admin/views/login-email.php
index fe595e95..0af999e9 100644
--- a/admin/views/login-email.php
+++ b/admin/views/login-email.php
@@ -1,19 +1,19 @@