From b4d72c76e602060d0a360b0e56b0eb15fc2b7fb4 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 7 May 2019 16:51:19 +0100 Subject: [PATCH] accounts: Create LDAP user when account is activated This converts the temporary user account into an account on our LDAP database. Signed-off-by: Michael Tremer --- src/backend/accounts.py | 27 ++++++++++++++++++------ src/templates/auth/activate.html | 7 ++++++- src/web/auth.py | 35 ++++++++++++-------------------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/backend/accounts.py b/src/backend/accounts.py index a474bc0c..657d765b 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -191,13 +191,23 @@ class Accounts(Object): activation_code=activation_code, email=email, first_name=first_name, last_name=last_name) - def create(self, uid, email, first_name, last_name): - activation_code = util.random_string(24) + def activate(self, uid, activation_code): + res = self.db.get("DELETE FROM account_activations \ + WHERE uid = %s AND activation_code = %s AND expires_at > NOW() \ + RETURNING *", uid, activation_code) + + # Return nothing when account was not found + if not res: + return + # Create a new account on the LDAP database + return self.create(uid, res.email, + first_name=res.first_name, last_name=res.last_name) + + def create(self, uid, email, first_name, last_name): # Account Parameters account = { "objectClass" : [b"top", b"person", b"inetOrgPerson"], - "userPassword" : activation_code.encode(), "mail" : email.encode(), # Name @@ -206,11 +216,16 @@ class Accounts(Object): "givenName" : first_name.encode(), } + logging.info("Creating new account: %s: %s" % (uid, account)) + + # Create DN + dn = "uid=%s,ou=People,dc=mcfly,dc=local" % uid + # Create account on LDAP - self.ldap.add_s("uid=%s,ou=People,dc=mcfly,dc=local" % uid, ldap.modlist.addModlist(account)) + self.ldap.add_s(dn, ldap.modlist.addModlist(account)) - # TODO Send email with activation code - pass + # Return account + return self._get_account_from_dn(dn) # Session stuff diff --git a/src/templates/auth/activate.html b/src/templates/auth/activate.html index 4a88d584..4b661c16 100644 --- a/src/templates/auth/activate.html +++ b/src/templates/auth/activate.html @@ -7,10 +7,15 @@
{{ _("Activate Your Account") }}
+

+ {{ _("Thank you for creating a new account.") }} + {{ _("To activate it, please enter a strong password.") }} +

+
{% raw xsrf_form_html() %} - {% module Password(account) %} + {% module Password() %}