Mercurial > public > sg101
comparison gpp/accounts/__init__.py @ 347:69d0306a6fe7
Fixing #165: add a way to filter users in the admin by join date; add an admin action to approve a pending user; added a honeypot type field to the registration form.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 02 Mar 2011 01:11:32 +0000 |
parents | dbd703f7d63a |
children |
comparison
equal
deleted
inserted
replaced
346:efa3b4901777 | 347:69d0306a6fe7 |
---|---|
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) |