Mercurial > public > sg101
comparison accounts/__init__.py @ 1206:02181fa5ac9d modernize tip
Update to Django 1.9.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 22 Jan 2025 17:58:16 -0600 |
parents | 988782c6ce6c |
children |
comparison
equal
deleted
inserted
replaced
1205:510ef3cbf3e6 | 1206:02181fa5ac9d |
---|---|
1 import datetime | |
2 import logging | |
3 | |
4 from django.contrib.auth.models import User | |
5 | |
6 | |
7 logger = logging.getLogger('auth') | |
8 | |
9 | |
10 def create_new_user(pending_user, ip=None, admin_activation=False): | |
11 """ | |
12 This function contains the code to create a new user from a | |
13 pending user. The pending user is deleted and the new user | |
14 is saved. A log message is produced. If admin_activation is false, | |
15 then ip should be the user's IP they confirmed from, if available. | |
16 | |
17 """ | |
18 new_user = User() | |
19 | |
20 new_user.username = pending_user.username | |
21 new_user.first_name = '' | |
22 new_user.last_name = '' | |
23 new_user.email = pending_user.email | |
24 new_user.password = pending_user.password # already been hashed | |
25 new_user.is_staff = False | |
26 new_user.is_active = True | |
27 new_user.is_superuser = False | |
28 new_user.last_login = datetime.datetime.now() | |
29 new_user.date_joined = new_user.last_login | |
30 | |
31 new_user.save() | |
32 pending_user.delete() | |
33 | |
34 if admin_activation: | |
35 msg = 'Accounts registration confirmed by ADMIN for %s' % new_user.username | |
36 else: | |
37 msg = 'Accounts registration confirmed by USER for %s from %s' % ( | |
38 new_user.username, ip) | |
39 | |
40 logger.info(msg) |