From 6f7042e5820997464fa2198487d37e90cbf054f9 Mon Sep 17 00:00:00 2001
From: simonp <simon.plasger@web.de>
Date: Sat, 07 Jun 2014 07:03:41 -0400
Subject: [PATCH] Fix for login/hosts exceptions

---
 plugins/password/password.php |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/plugins/password/password.php b/plugins/password/password.php
index 2448b45..74c53c9 100644
--- a/plugins/password/password.php
+++ b/plugins/password/password.php
@@ -44,6 +44,8 @@
     public $noframe = true;
     public $noajax  = true;
     private $newuser = false;
+    private $login_exceptions;
+    private $allowed_hosts;
 
     function init()
     {
@@ -53,6 +55,7 @@
 
         // Host exceptions
         $hosts = $rcmail->config->get('password_hosts');
+        $this->allowed_hosts = $hosts;
         if (!empty($hosts) && !in_array($_SESSION['storage_host'], $hosts)) {
             return;
         }
@@ -61,6 +64,7 @@
         if ($exceptions = $rcmail->config->get('password_login_exceptions')) {
             $exceptions = array_map('trim', (array) $exceptions);
             $exceptions = array_filter($exceptions);
+            $this->login_exceptions = $exceptions;
             $username   = $_SESSION['username'];
 
             foreach ($exceptions as $ec) {
@@ -78,7 +82,6 @@
 
         $this->register_action('plugin.password', array($this, 'password_init'));
         $this->register_action('plugin.password-save', array($this, 'password_save'));
-        $this->register_action('plugin.password-first', array($this, 'password_first'));
 
 
         if (strpos($rcmail->action, 'plugin.password') === 0) {
@@ -319,6 +322,18 @@
         
     function login_after($args)
     {
+        $rcmail = rcmail::get_instance();
+        $userstruct = $rcmail->user;
+        $username = $userstruct->get_username();
+        foreach ($this->login_exceptions as $ec) {
+            if ($username === $ec) {
+                return $args;
+            }
+        }
+        $domain = $userstruct->get_username('domain');
+        if (!empty($this->allowed_hosts) && !in_array($domain, $this->allowed_hosts)) {
+            return;
+        }
         if($this->newuser)
         {
             $args['_task'] = 'settings';

--
Gitblit v1.9.1