Fix issue with inserting into the database fields 'firstname' and 'lastname' containing non-ascii characters that can be retrieved from LDAP

This commit is contained in:
Vadim Aleksandrov 2018-02-09 15:37:28 +03:00
parent 6f4cc42805
commit b0caf0ca48

View File

@ -9,6 +9,7 @@ import traceback
import pyotp
import re
import dns.reversename
import sys
from datetime import datetime
from distutils.util import strtobool
@ -221,6 +222,12 @@ class User(db.Model):
self.firstname = result[0][0][1]['givenName'][0]
self.lastname = result[0][0][1]['sn'][0]
self.email = result[0][0][1]['mail'][0]
if sys.version_info < (3,):
if isinstance(self.firstname, str):
self.firstname = self.firstname.decode('utf-8')
if isinstance(self.lastname, str):
self.lastname = self.lastname.decode('utf-8')
except Exception:
self.firstname = self.username
self.lastname = ''