Mercurial > public > sg101
comparison accounts/__init__.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/accounts/__init__.py@69d0306a6fe7 |
children | 988782c6ce6c |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 import datetime | |
2 import logging | |
3 | |
4 from django.contrib.auth.models import User | |
5 | |
6 | |
7 def create_new_user(pending_user, ip=None, admin_activation=False): | |
8 """ | |
9 This function contains the code to create a new user from a | |
10 pending user. The pending user is deleted and the new user | |
11 is saved. A log message is produced. If admin_activation is false, | |
12 then ip should be the user's IP they confirmed from, if available. | |
13 | |
14 """ | |
15 new_user = User() | |
16 | |
17 new_user.username = pending_user.username | |
18 new_user.first_name = '' | |
19 new_user.last_name = '' | |
20 new_user.email = pending_user.email | |
21 new_user.password = pending_user.password # already been hashed | |
22 new_user.is_staff = False | |
23 new_user.is_active = True | |
24 new_user.is_superuser = False | |
25 new_user.last_login = datetime.datetime.now() | |
26 new_user.date_joined = new_user.last_login | |
27 | |
28 new_user.save() | |
29 pending_user.delete() | |
30 | |
31 if admin_activation: | |
32 msg = 'Accounts registration confirmed by ADMIN for %s' % new_user.username | |
33 else: | |
34 msg = 'Accounts registration confirmed by USER for %s from %s' % ( | |
35 new_user.username, ip) | |
36 | |
37 logging.info(msg) |