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