Changeset - 1aa1655bf019
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 15 years ago 2011-03-15 23:34:14
marcin@python-works.com
fixed some config bool converter problems with ldap
3 files changed with 18 insertions and 6 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/__init__.py
Show inline comments
 
@@ -23,13 +23,22 @@
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 

	
 
def str2bool(v):
 
    return v.lower() in ["yes", "true", "t", "1"] if v else None
 
    if isinstance(v, (str, unicode)):
 
        obj = v.strip().lower()
 
        if obj in ['true', 'yes', 'on', 'y', 't', '1']:
 
            return True
 
        elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
 
            return False
 
        else:
 
            if not safe:
 
                raise ValueError("String is not true/false: %r" % obj)
 
    return bool(obj)
 

	
 
def generate_api_key(username, salt=None):
 
    from tempfile import _RandomNameSequence
 
    import hashlib
 

	
 
    if salt is None:
rhodecode/lib/auth.py
Show inline comments
 
@@ -40,13 +40,13 @@ from rhodecode import __platform__
 

	
 
if __platform__ == 'Windows':
 
    from hashlib import sha256
 
if __platform__ in ('Linux', 'Darwin'):
 
    import bcrypt
 

	
 

	
 
from rhodecode.lib import str2bool
 
from rhodecode.lib.exceptions import LdapPasswordError, LdapUsernameError
 
from rhodecode.lib.utils import get_repo_slug
 
from rhodecode.lib.auth_ldap import AuthLdap
 

	
 
from rhodecode.model import meta
 
from rhodecode.model.user import UserModel
 
@@ -176,21 +176,21 @@ def authenticate(username, password):
 
        from rhodecode.model.settings import SettingsModel
 
        ldap_settings = SettingsModel().get_ldap_settings()
 

	
 
        #======================================================================
 
        # FALLBACK TO LDAP AUTH IF ENABLE                
 
        #======================================================================
 
        if ldap_settings.get('ldap_active', False):
 
        if str2bool(ldap_settings.get('ldap_active')):
 
            log.debug("Authenticating user using ldap")
 
            kwargs = {
 
                  'server':ldap_settings.get('ldap_host', ''),
 
                  'base_dn':ldap_settings.get('ldap_base_dn', ''),
 
                  'port':ldap_settings.get('ldap_port'),
 
                  'bind_dn':ldap_settings.get('ldap_dn_user'),
 
                  'bind_pass':ldap_settings.get('ldap_dn_pass'),
 
                  'use_ldaps':ldap_settings.get('ldap_ldaps'),
 
                  'use_ldaps':str2bool(ldap_settings.get('ldap_ldaps')),
 
                  'tls_reqcert':ldap_settings.get('ldap_tls_reqcert'),
 
                  'ldap_filter':ldap_settings.get('ldap_filter'),
 
                  'search_scope':ldap_settings.get('ldap_search_scope'),
 
                  'attr_login':ldap_settings.get('ldap_attr_login'),
 
                  'ldap_version':3,
 
                  }
rhodecode/model/settings.py
Show inline comments
 
@@ -92,11 +92,14 @@ class SettingsModel(BaseModel):
 
                .all()
 

	
 
        fd = {}
 

	
 
        for row in r:
 
            v = row.app_settings_value
 
            if v in ['0', '1']:
 
                v = v == '1'
 
            if v in ['true', 'yes', 'on', 'y', 't', '1']:
 
                v = True
 
            elif v in ['false', 'no', 'off', 'n', 'f', '0']:
 
                v = False
 

	
 
            fd.update({row.app_settings_name:v})
 

	
 
        return fd
0 comments (0 inline, 0 general)