summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-01-24 04:33:34 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-02-02 04:22:16 +0100
commit152bc7c3155ad3bb44bb3d9b14f8ad1854f09961 (patch)
treeb1c80879d52d76bae4d2111f3208f9690f35602b
parent587b79a8470a0c069f1b1d81e01685baa5e6a39b (diff)
downloadweb-152bc7c3155ad3bb44bb3d9b14f8ad1854f09961.tar.gz
web-152bc7c3155ad3bb44bb3d9b14f8ad1854f09961.tar.bz2
web-152bc7c3155ad3bb44bb3d9b14f8ad1854f09961.zip
Create models.py with Account and Service
-rw-r--r--accounts/account.py65
-rw-r--r--accounts/models.py74
-rw-r--r--accounts/utils/__init__.py11
-rw-r--r--accounts/views/default/__init__.py2
4 files changed, 76 insertions, 76 deletions
diff --git a/accounts/account.py b/accounts/account.py
index fdfeba2..72ea42d 100644
--- a/accounts/account.py
+++ b/accounts/account.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
-from utils import Service
-from uuid import uuid4
-
+from models import Service
SERVICES = [
Service('foren', 'Foren', 'https://foren.spline.inf.fu-berlin.de/'),
@@ -10,64 +8,3 @@ SERVICES = [
Service('jabber', 'Jabber', 'http://jabber.spline.de/'),
Service('zettel', 'Zettel', 'https://zettel.spline.inf.fu-berlin.de/'),
]
-
-
-class Account:
- """
- An Account represents a complex ldap tree entry for spline users.
- For each service a spline user can have a different password.
- """
- def __init__(self, uid, mail, services=[], dn=None, password=None):
- self.uid = uid.encode('utf8') if isinstance(uid, unicode) else uid
- self.services = services
- self.dn = dn
- self.password = password.encode('utf8') if isinstance(password, unicode) else password
- self.new_password_root = None
- self.new_password_services = {}
- self.attributes = {}
-
- self._set_attribute('mail', mail)
-
- def __repr__(self):
- return "<Account uid=%s>" % self.uid
-
-
- def reset_password(self, service):
- self.new_password_services[service] = (None, None)
-
- def change_password(self, new_password, old_password='', service=None):
- """
- Changes a password for a given service. You have to use the
- AccountService class to make the changes permanent. If no service is
- given, the root password will be changed.
- """
- if isinstance(new_password, unicode):
- new_password = new_password.encode('utf8')
-
- if isinstance(old_password, unicode):
- old_password = old_password.encode('utf8')
-
- if not service:
- self.new_password_root = (old_password, new_password)
- else:
- self.new_password_services[service] = (old_password, new_password)
-
- def _set_attribute(self, key, value):
- if isinstance(value, unicode):
- value = value.encode('utf8')
-
- self.attributes[key] = value
-
- def change_email(self, new_mail):
- """
- Changes the mail address of an account. You have to use the
- AccountService class to make changes permanent.
- """
- self._set_attribute('mail', new_mail)
-
- def __getattr__(self, name):
- if name in self.attributes:
- return self.attributes[name]
-
- raise AttributeError("'%s' object has no attribute '%s'" %
- (self.__class__.__name__, name))
diff --git a/accounts/models.py b/accounts/models.py
new file mode 100644
index 0000000..9e0c45e
--- /dev/null
+++ b/accounts/models.py
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+
+class Account(object):
+ """
+ An Account represents a complex ldap tree entry for spline users.
+ For each service a spline user can have a different password.
+ """
+
+ def __init__(self, uid, mail, services=[], dn=None, password=None):
+ self.uid = uid.encode('utf8') if isinstance(uid, unicode) else uid
+ self.services = services
+ self.dn = dn
+ self.password = password.encode('utf8') if isinstance(password, unicode) else password
+ self.new_password_root = None
+ self.new_password_services = {}
+ self.attributes = {}
+
+ self._set_attribute('mail', mail)
+
+ def __repr__(self):
+ return "<Account uid=%s>" % self.uid
+
+
+ def reset_password(self, service):
+ self.new_password_services[service] = (None, None)
+
+ def change_password(self, new_password, old_password='', service=None):
+ """
+ Changes a password for a given service. You have to use the
+ AccountService class to make the changes permanent. If no service is
+ given, the root password will be changed.
+ """
+
+ if isinstance(new_password, unicode):
+ new_password = new_password.encode('utf8')
+
+ if isinstance(old_password, unicode):
+ old_password = old_password.encode('utf8')
+
+ if not service:
+ self.new_password_root = (old_password, new_password)
+ else:
+ self.new_password_services[service] = (old_password, new_password)
+
+ def _set_attribute(self, key, value):
+ if isinstance(value, unicode):
+ value = value.encode('utf8')
+
+ self.attributes[key] = value
+
+ def change_email(self, new_mail):
+ """
+ Changes the mail address of an account. You have to use the
+ AccountService class to make changes permanent.
+ """
+ self._set_attribute('mail', new_mail)
+
+ def __getattr__(self, name):
+ if name in self.attributes:
+ return self.attributes[name]
+
+ raise AttributeError("'%s' object has no attribute '%s'" %
+ (self.__class__.__name__, name))
+
+
+class Service(object):
+ def __init__(self, id, name, url):
+ self.id = id
+ self.name = name
+ self.url = url
+ self.changed = None # used by settings view
+
+ def __repr__(self):
+ return '<Service %s>' % self.id
diff --git a/accounts/utils/__init__.py b/accounts/utils/__init__.py
index 2b0f566..6698734 100644
--- a/accounts/utils/__init__.py
+++ b/accounts/utils/__init__.py
@@ -162,17 +162,6 @@ def constant_time_compare(val1, val2):
return result == 0
-class Service(object):
- def __init__(self, id, name, url):
- self.id = id
- self.name = name
- self.url = url
- self.changed = None # used by settings view
-
- def __repr__(self):
- return '<Service %s>' % self.id
-
-
def ensure_utf8(s):
if isinstance(s, unicode):
s = s.encode('utf8')
diff --git a/accounts/views/default/__init__.py b/accounts/views/default/__init__.py
index 52edb10..0074cd9 100644
--- a/accounts/views/default/__init__.py
+++ b/accounts/views/default/__init__.py
@@ -8,7 +8,7 @@ from flask import current_app, redirect, request, g, flash, url_for
from accounts.forms import LoginForm, RegisterForm, RegisterCompleteForm, \
LostPasswordForm, SettingsForm
from accounts.utils import *
-from accounts.account import Account
+from accounts.models import Account
bp = Blueprint('default', __name__)