author | nishanth |
Fri, 16 Apr 2010 14:47:42 +0530 | |
changeset 68 | 73720e19d222 |
parent 62 | b7e47cc39342 |
child 81 | a76987f54dac |
permissions | -rwxr-xr-x |
2 | 1 |
#!/usr/bin/python |
2 |
||
3 |
from django.contrib.auth.models import User |
|
46
ff5f34e42aec
registration for workshop is now integrated with man registartion.
nishanth
parents:
45
diff
changeset
|
4 |
from django.core.mail import send_mail |
2 | 5 |
from django.db import IntegrityError |
6 |
||
62
b7e47cc39342
renamed the project to ws_app and modified imports accordingly .
nishanth
parents:
59
diff
changeset
|
7 |
from ws_app.reg.models import Profile, Event |
b7e47cc39342
renamed the project to ws_app and modified imports accordingly .
nishanth
parents:
59
diff
changeset
|
8 |
from ws_app.reg.utils import gen_key |
2 | 9 |
|
17 | 10 |
def create_user(email, password, first_name="", last_name="", gender="M", profession="S", affiliated_to="", interests="" ): |
2 | 11 |
""" create a user with random username and set the password. |
12 |
""" |
|
13 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
14 |
while True: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
15 |
try: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
16 |
username = gen_key(8) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
17 |
user = User.objects.get(username=username) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
18 |
except User.DoesNotExist: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
19 |
break |
2 | 20 |
new_user = User.objects.create_user(username, email, password) |
17 | 21 |
new_user.first_name = first_name |
22 |
new_user.last_name = last_name |
|
2 | 23 |
new_user.is_active = False |
24 |
new_user.save() |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
25 |
|
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
26 |
new_profile = Profile(user=new_user) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
27 |
new_profile.gender = gender |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
28 |
new_profile.profession = profession |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
29 |
new_profile.affiliated_to = affiliated_to |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
30 |
new_profile.interests = interests |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
31 |
|
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
32 |
while True: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
33 |
try: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
34 |
new_profile.activation_key = gen_key(30) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
35 |
new_profile.save() |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
36 |
return new_user |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
37 |
except IntegrityError: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
38 |
pass |
2 | 39 |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
18
diff
changeset
|
40 |
def send_activation(user): |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
18
diff
changeset
|
41 |
""" get key from profile and send an email. |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
18
diff
changeset
|
42 |
""" |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
18
diff
changeset
|
43 |
|
58
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
44 |
activation_link = "http://localhost:8000/reg/activate/%s"%user.get_profile().activation_key |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
45 |
subject = "Activate your account" |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
46 |
message = """ |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
47 |
Dear %s, |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
48 |
|
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
49 |
Thank you for registering at fossee.in. |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
50 |
Your are just a step away from completeing your registration. |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
51 |
Please click on the link below or open the url in your browser to activate your account. |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
52 |
%s |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
53 |
|
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
54 |
Please mail your queries and complaints to admin@fossee.in. |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
55 |
|
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
56 |
If you have not registered at fossee, please ignore this mail. |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
57 |
|
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
58 |
Regards, |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
59 |
FOSSEE Team |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
60 |
"""%(user.get_full_name(), activation_link) |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
61 |
print message |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
62 |
send_mail(subject, message, "admin@fossee.in", [user.email]) |
a26c82f593f0
implemented send activation. have to test it and do the same for change password.
nishanth
parents:
46
diff
changeset
|
63 |
|
43
757d1da69255
added venue field in event model and corresponding forms and views.
nishanth
parents:
23
diff
changeset
|
64 |
def create_event(title, description, start_date, stop_date, venue, created_by=None): |
2 | 65 |
""" make an event and save it. |
66 |
""" |
|
67 |
||
68 |
new_event = Event() |
|
69 |
new_event.title = title |
|
8 | 70 |
new_event.description = description |
2 | 71 |
new_event.start_date = start_date |
72 |
new_event.stop_date = stop_date |
|
43
757d1da69255
added venue field in event model and corresponding forms and views.
nishanth
parents:
23
diff
changeset
|
73 |
new_event.venue = venue |
2 | 74 |
new_event.save() |
75 |
if created_by: |
|
76 |
new_event.organizers.add(created_by) |
|
77 |
||
78 |
while True: |
|
79 |
try: |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
80 |
new_event.key = gen_key(10) |
2 | 81 |
new_event.save() |
82 |
return new_event |
|
83 |
except IntegrityError: |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
2
diff
changeset
|
84 |
pass |
7 | 85 |
|
86 |
def activate_user(user): |
|
87 |
""" mark the is_active flag as true. |
|
88 |
""" |
|
89 |
||
90 |
user.is_active = True |
|
91 |
user.save() |
|
92 |
return user |
|
9 | 93 |
|
94 |
def reset_password(user): |
|
95 |
""" get a key and set it as password. |
|
96 |
for now, print the key. |
|
97 |
later on add the send mail function. |
|
98 |
""" |
|
99 |
||
100 |
new_password = gen_key(10) |
|
101 |
user.set_password(new_password) |
|
102 |
user.save() |
|
103 |
return new_password |
|
104 |
||
105 |
def change_password(user, new_password): |
|
106 |
""" for now just set the password and be done with it. |
|
107 |
later on, if we want to do something else also then we can add them here. |
|
108 |
""" |
|
109 |
||
110 |
user.set_password(new_password) |
|
111 |
user.save() |
|
112 |
||
17 | 113 |
def update_profile(user, properties): |
114 |
""" properties must be a dictionary that contains all the attributes that |
|
115 |
we take while a new user registers. |
|
116 |
""" |
|
9 | 117 |
|
17 | 118 |
profile = user.get_profile() |
119 |
||
120 |
user.first_name = properties['first_name'] |
|
121 |
user.last_name = properties['last_name'] |
|
122 |
user.save() |
|
123 |
||
124 |
profile.gender = properties['gender'] |
|
125 |
profile.profession = properties['profession'] |
|
126 |
profile.affiliated_to = properties['affiliated_to'] |
|
127 |
profile.interests = properties['interests'] |
|
128 |
profile.save() |
|
129 |
||
130 |