summaryrefslogtreecommitdiffstats
path: root/py-bin
diff options
context:
space:
mode:
authoralice <alice@immerda.ch>2012-08-31 15:50:59 +0200
committeralice <alice@immerda.ch>2012-10-19 15:20:06 +0200
commitdff6e7353195a13da73fa1e864dd186ad99bb060 (patch)
tree71b8e48642b2328294ec426608faaf4f713a62f5 /py-bin
parent2b47c309cb58d4f7257456245f5a73673f281c73 (diff)
registration working again
Diffstat (limited to 'py-bin')
-rw-r--r--py-bin/jabberman.py51
-rw-r--r--py-bin/mail_auth.py9
-rw-r--r--py-bin/main.py31
-rw-r--r--py-bin/setup.py5
4 files changed, 20 insertions, 76 deletions
diff --git a/py-bin/jabberman.py b/py-bin/jabberman.py
index 082fd3c..bec3731 100644
--- a/py-bin/jabberman.py
+++ b/py-bin/jabberman.py
@@ -39,11 +39,9 @@ class WebUser:
class JabberDB:
def __init__(self):
self.__connection = sqlite3.connect(config.sqlite_path)
- logging.info("JabberDB init")
- atexit.register(self.__close_db) # FIXME: test that!
+ atexit.register(self.__close_db)
def __close_db(self):
- logging.info("closing connection")
self.__connection.cursor().close()
def login_user(self, user_id, password):
@@ -63,28 +61,25 @@ class JabberDB:
if self.get_web_user(user_id):
return (False, "Benutzer existiert bereits!")
- #user = JabberUser(user_id)
- #user.set_token(token)
- #self.__store_user(user)
- generate_web_user(user_id)
+ token = self.generate_web_user(user_id)
- return (True, "Benutzer registriert, Aktivierung noch ausstehend.")
+ return (True, token)
def validate_token(self, user_id, token):
user = self.get_web_user(user_id)
- if not user:
+ if not user or user.token != token:
return (False, "Zugriff verweigert.")
- #fixme: is this actually needed?
- return user.token == token
+
+ return (True, user)
def activate_user(self, user_id, password, token):
user = self.get_web_user(user_id)
if not user:
return (False, "Zugriff verweigert.")
- success = update_web_user(self, user_id, password, token)
+ success = self.update_web_user(user_id, password, token)
if not success:
- return (False, status)
+ return (False, "Fehler beim Verarbeiten.")
return (True, user)
@@ -127,18 +122,20 @@ class JabberDB:
def generate_web_user(self, email):
token = str(random.getrandbits(60))
- print token
token_date = datetime.datetime.utcnow()
cur = self.__connection.cursor()
cur.execute("INSERT INTO web_users VALUES (NULL,?,?,?)", (email, token, token_date))
self.__connection.commit()
+ return token
def get_web_user(self, email):
cur = self.__connection.cursor()
cur.execute("SELECT * FROM web_users where email=?", (email,))
row = cur.fetchone()
- #FIXME: fix this call
+ if row == None:
+ return None
+
return WebUser(row[0],row[1],row[2],row[3])
def update_web_user(self, email, plain_pwd, provided_token):
@@ -147,16 +144,16 @@ class JabberDB:
row = cur.fetchone()
if row == None:
return False
- web_user_id, token, token_date = row[0]
+ web_user_id, token, token_date = row[0], row[2], row[3]
+ # FIXME: check token date!!!!
if provided_token != token:
return False
- cur.execute("UPDATE web_users SET token=NULL WHERE web_user_id=?", (web_user_id,))
+ cur.execute("UPDATE web_users SET token=NULL WHERE id=?", (web_user_id,))
self.__connection.commit()
- user, domain = email.split("@")
- jid = user + "@jabber." + domain
+ jid = WebUser.derive_primary_jid(email)
self.create_jid(jid, plain_pwd, web_user_id)
return True
@@ -256,20 +253,13 @@ class JabberManager:
def logout(self):
self.current_user, self.authenticated = None, False
self.__clear_session()
-
- def generate_token(self, user_id):
- ok, status = self.check_user_id(user_id)
- if not ok:
- return (False, status)
-
- return self.jadb.generate_token(user_id)
- def prepare_user(self, user_id, token):
+ def prepare_user(self, user_id):
ok, status = self.check_user_id(user_id)
if not ok:
return (False, status)
- return self.jadb.prepare_user(user_id, token)
+ return self.jadb.prepare_user(user_id)
def validate_token(self, user_id, token):
if user_id == "":
@@ -305,11 +295,6 @@ class JabberManager:
self.__clear_session()
return (False, status_or_user)
- ok, status = self.add_account(self.current_user.get_primary_jid())
- if not ok:
- #todo: handle this smarter somehow
- return (False, status)
-
return (True, status)
def change_password(self, password):
diff --git a/py-bin/mail_auth.py b/py-bin/mail_auth.py
index 27607e8..22b4a34 100644
--- a/py-bin/mail_auth.py
+++ b/py-bin/mail_auth.py
@@ -13,7 +13,7 @@ class MailAuthMixIn:
def mail_process(self, req):
email = req.params.get("email", "")
- success, status_or_token = self.jman.generate_token(email)
+ success, status_or_token = self.jman.prepare_user(email)
if not success:
self.render_template(req, "mail_error.em", dict(reason=status_or_token))
return
@@ -24,11 +24,6 @@ class MailAuthMixIn:
self.render_template(req, "mail_trylater.em", dict(reason=msg))
return
- success, status = self.jman.prepare_user(email, token)
- if not success:
- self.render_template(req, "mail_error.em", dict(reason=status))
- return
-
msg = "Mail erfolgreich versandt."
self.render_template(req, "mail_success.em", dict(status=msg, email=email))
mail_process.web_callable = True
@@ -40,7 +35,7 @@ class MailAuthMixIn:
token_ok, status_or_user = self.jman.validate_token(user_id, token)
if token_ok:
- user_id = status_or_user.get_user_id()
+ user_id = status_or_user.email
self.render_template(req, "set_pw_form.em",
dict(user_id=user_id, error=last_error, command="mail_pw_process"))
else:
diff --git a/py-bin/main.py b/py-bin/main.py
deleted file mode 100644
index 39294e0..0000000
--- a/py-bin/main.py
+++ /dev/null
@@ -1,31 +0,0 @@
-#main url mapper
-
-from utils import BasicHandler, process_request, set_logging_defaults
-from jabberman import JabberManager
-from login import LoginMixIn
-from mail_auth import MailAuthMixIn
-from setup import SetupMixIn
-
-set_logging_defaults()
-
-class MainHandler(BasicHandler, MailAuthMixIn, LoginMixIn, SetupMixIn):
- def do_process(self, req):
- command = req.params.get("cmd", "")
-
- if command == "":
- self.login_form(req)
- else:
- if hasattr(self, command):
- method = getattr(self, command)
- if hasattr(method, 'web_callable') and method.web_callable:
- self.jman = JabberManager(self.session)
- method(req)
- else:
- self.invalid_page(req)
- else:
- self.invalid_page(req)
-
- def invalid_page(self, req):
- self.error_page(req, "Ungueltiger Request.")
-
-process_request(MainHandler) \ No newline at end of file
diff --git a/py-bin/setup.py b/py-bin/setup.py
index d59964d..fc521c6 100644
--- a/py-bin/setup.py
+++ b/py-bin/setup.py
@@ -124,11 +124,6 @@ class SetupMixIn:
self.render_template(req, "logged_out.em")
logout.web_callable = True
- def test(self, req):
- ctx = dict(user_id="alice@immerda.ch")
- self.render_template(req, "test.em", ctx)
- test.web_callable = True
-
def __redirect_to_main(self, req):
self.redirect_to(req, self.make_url([("cmd","setup_main")]))