device detection
This commit is contained in:
parent
93f79cb4f0
commit
6968957159
31
app.py
31
app.py
@ -186,8 +186,8 @@ def post_signup():
|
||||
elif form('password') != form('confirm-password'):
|
||||
return error(i18n.msg[7])
|
||||
|
||||
try:
|
||||
account_request(username, firstname, surname, form('password'), email, isFake)
|
||||
try:
|
||||
account_request(username, firstname, surname, form('password'), email, isFake, get_dev())
|
||||
except Error as e:
|
||||
LOG.warning("Unsuccessful attempt to create an account for %s: %s" % (form('username'), e))
|
||||
return error(str(e))
|
||||
@ -444,14 +444,14 @@ def logout_user_ldap(conf, username):
|
||||
LOG.info("%s LOGED OUT" % (username))
|
||||
|
||||
#SIGN UP
|
||||
def account_request(username, firstname, surname, password, email, isFake):
|
||||
def account_request(username, firstname, surname, password, email, isFake, device):
|
||||
created = []
|
||||
for key in (key for key in CONF.sections()
|
||||
if key == 'ldap' or key.startswith('ldap:')):
|
||||
|
||||
LOG.debug("Creating account for %s on %s server" % (username, key))
|
||||
try:
|
||||
new_user_account(CONF[key], username, firstname, surname, password, email, isFake)
|
||||
new_user_account(CONF[key], username, firstname, surname, password, email, isFake, device)
|
||||
created.append(key)
|
||||
except Error as e:
|
||||
for key in reversed(created):
|
||||
@ -478,7 +478,7 @@ def new_user_account(conf, *args):
|
||||
LOG.error('{}: {!s}'.format(e.__class__.__name__, e))
|
||||
raise Error(i18n.msg[23])
|
||||
|
||||
def register(conf, username, firstname, surname, password, email, isFake):
|
||||
def register(conf, username, firstname, surname, password, email, isFake, device):
|
||||
|
||||
def to_ascii(str):
|
||||
ascii_str=""
|
||||
@ -509,7 +509,8 @@ def register(conf, username, firstname, surname, password, email, isFake):
|
||||
uidNumber = find_uid_number(conf,c)+1
|
||||
directory = 'home/user/'+to_ascii(username)
|
||||
OBJECT_CLASS = ['top', 'inetOrgPerson', 'posixAccount', 'accountsManagement']
|
||||
attributes = {'gidNumber': '501', 'uidNumber': uidNumber, 'homeDirectory': directory, 'givenName': firstname, 'sn': surname, 'uid' : username, 'mail': email, 'active': False, 'fakeCn': isFake}
|
||||
attributes = {'gidNumber': '501', 'uidNumber': uidNumber, 'homeDirectory': directory, 'givenName':
|
||||
firstname, 'sn': surname, 'uid' : username, 'mail': email, 'active': False, 'fakeCn': isFake, 'device':device}
|
||||
new_user_dn = "cn="+firstname+" "+surname+" - "+username+",cn=users,"+conf['base']
|
||||
c.add(dn=new_user_dn,object_class=OBJECT_CLASS, attributes=attributes)
|
||||
#create/change user password
|
||||
@ -785,7 +786,7 @@ def get_user_email_array(user_dn, conn, old_email, new_email):
|
||||
|
||||
def get_user_data(user_dn, conn):
|
||||
search_filter = '(objectClass=*)'
|
||||
conn.search(user_dn, search_filter, attributes=['active','fakeCn','givenName','sn','uid','mail'])
|
||||
conn.search(user_dn, search_filter, attributes=['active','fakeCn','givenName','sn','uid','mail','device'])
|
||||
data = []
|
||||
data.append(conn.entries[0].active.values[0])
|
||||
data.append(conn.entries[0].fakeCn.values[0])
|
||||
@ -793,6 +794,7 @@ def get_user_data(user_dn, conn):
|
||||
data.append(conn.entries[0].sn.values[0])
|
||||
data.append(conn.entries[0].uid.values[0])
|
||||
data.append(conn.entries[0].mail.values[0])
|
||||
data.append(conn.entries[0].device.values)
|
||||
return(data)
|
||||
|
||||
def read_config():
|
||||
@ -818,6 +820,12 @@ def reg():
|
||||
|
||||
allowed = reg()
|
||||
|
||||
def get_dev():
|
||||
ua_string = bottle.request.environ.get('HTTP_USER_AGENT')
|
||||
user_agent = parse(ua_string)
|
||||
return str(user_agent)
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
pass
|
||||
|
||||
@ -835,14 +843,6 @@ def newSession():
|
||||
global i18n
|
||||
i18n = LocalizeTo(self.lang, CONF)
|
||||
|
||||
self.device = self.get_dev()
|
||||
|
||||
def get_dev(self):
|
||||
ua_string = bottle.request.environ.get('HTTP_USER_AGENT')
|
||||
user_agent = parse(ua_string)
|
||||
|
||||
return str(user_agent)
|
||||
|
||||
def get_lang(self):
|
||||
if 'HTTP_ACCEPT_LANGUAGE' in bottle.request.environ:
|
||||
lang = bottle.request.get('HTTP_ACCEPT_LANGUAGE')
|
||||
@ -863,6 +863,7 @@ def newSession():
|
||||
self.surname = data[3]
|
||||
self.username = data[4]
|
||||
self.mail = data[5]
|
||||
self.device = data[6]
|
||||
|
||||
self.data['active'] = self.active
|
||||
self.data['fakeCn'] = self.fakeCn
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user