mirror of https://github.com/openspug/spug
				
				
				
			fix issue
							parent
							
								
									466d036c71
								
							
						
					
					
						commit
						919d64594e
					
				|  | @ -167,9 +167,10 @@ def login(request): | |||
|         if user and not user.is_active: | ||||
|             return json_response(error="账户已被系统禁用") | ||||
|         if form.type == 'ldap': | ||||
|             if not AppSetting.get_default('ldap_service'): | ||||
|             config = AppSetting.get_default('ldap_service') | ||||
|             if not config: | ||||
|                 return json_response(error='请在系统设置中配置LDAP后再尝试通过该方式登录') | ||||
|             ldap = LDAP() | ||||
|             ldap = LDAP(**config) | ||||
|             is_success, message = ldap.valid_user(form.username, form.password) | ||||
|             if is_success: | ||||
|                 if not user: | ||||
|  |  | |||
|  | @ -1,21 +1,17 @@ | |||
| # Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug | ||||
| # Copyright: (c) <spug.dev@gmail.com> | ||||
| # Released under the AGPL-3.0 License. | ||||
| from apps.setting.models import Setting | ||||
| import ldap | ||||
| import json | ||||
| 
 | ||||
| 
 | ||||
| class LDAP: | ||||
|     def __init__(self): | ||||
|         server_info = Setting.objects.filter(key='ldap_service').first() | ||||
|         ldap_info_dict = json.loads(server_info.value) | ||||
|         self.server = ldap_info_dict['server'] | ||||
|         self.port = ldap_info_dict['port'] | ||||
|         self.rules = ldap_info_dict['rules'] | ||||
|         self.admin_dn = ldap_info_dict['admin_dn'] | ||||
|         self.password = ldap_info_dict['password'] | ||||
|         self.base_dn = ldap_info_dict['base_dn'] | ||||
|     def __init__(self, server, port, rules, admin_dn, password, base_dn): | ||||
|         self.server = server | ||||
|         self.port = port | ||||
|         self.rules = rules | ||||
|         self.admin_dn = admin_dn | ||||
|         self.password = password | ||||
|         self.base_dn = base_dn | ||||
| 
 | ||||
|     def valid_user(self, username, password): | ||||
|         try: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 vapao
						vapao