root / logic / users.py @ 76cc889c
History | View | Annotate | Download (983 Bytes)
1 | 420f2c20 | Georgios Gousios | #
|
---|---|---|---|
2 | 420f2c20 | Georgios Gousios | # Business Logic for working with users
|
3 | 420f2c20 | Georgios Gousios | #
|
4 | 420f2c20 | Georgios Gousios | # Copyright 2010 Greek Research and Technology Network
|
5 | 420f2c20 | Georgios Gousios | #
|
6 | 420f2c20 | Georgios Gousios | |
7 | 420f2c20 | Georgios Gousios | from synnefo.db.models import SynnefoUser |
8 | 420f2c20 | Georgios Gousios | from django.db import transaction |
9 | 420f2c20 | Georgios Gousios | import hashlib |
10 | 420f2c20 | Georgios Gousios | |
11 | 420f2c20 | Georgios Gousios | @transaction.commit_on_success
|
12 | 76cc889c | Georgios Gousios | def _register_user(f, u, unq, t): |
13 | 76cc889c | Georgios Gousios | user = SynnefoUser() |
14 | 76cc889c | Georgios Gousios | user.realname = f |
15 | 76cc889c | Georgios Gousios | user.name = u |
16 | 76cc889c | Georgios Gousios | user.uniq = unq |
17 | 76cc889c | Georgios Gousios | user.type = t |
18 | 76cc889c | Georgios Gousios | user.auth_token = create_auth_token(user) |
19 | 76cc889c | Georgios Gousios | user.credit = 10 #TODO: Fix this when we have a per group policy |
20 | 420f2c20 | Georgios Gousios | user.save() |
21 | 420f2c20 | Georgios Gousios | |
22 | 76cc889c | Georgios Gousios | @transaction.commit_on_success
|
23 | 76cc889c | Georgios Gousios | def delete_user(user): |
24 | 76cc889c | Georgios Gousios | if user is not None: |
25 | 76cc889c | Georgios Gousios | user.delete() |
26 | 76cc889c | Georgios Gousios | |
27 | 420f2c20 | Georgios Gousios | def register_student(fullname, username, uniqid): |
28 | 420f2c20 | Georgios Gousios | _register_user(fullname, username, uniqid, 'STUDENT')
|
29 | 420f2c20 | Georgios Gousios | |
30 | 420f2c20 | Georgios Gousios | def register_professor(fullname, username, uniqid): |
31 | 420f2c20 | Georgios Gousios | _register_user(fullname, username, uniqid, 'PROFESSOR')
|
32 | 420f2c20 | Georgios Gousios | |
33 | 420f2c20 | Georgios Gousios | def create_auth_token(user): |
34 | 76cc889c | Georgios Gousios | md5 = hashlib.md5() |
35 | 76cc889c | Georgios Gousios | md5.update(user.uniq) |
36 | 76cc889c | Georgios Gousios | md5.update(user.name) |
37 | 76cc889c | Georgios Gousios | return md5.hexdigest()
|
38 | 420f2c20 | Georgios Gousios | |
39 | 420f2c20 | Georgios Gousios | #def login(username, password): |