24 from django.core.exceptions import ObjectDoesNotExist |
24 from django.core.exceptions import ObjectDoesNotExist |
25 |
25 |
26 #PIL |
26 #PIL |
27 from PIL import Image |
27 from PIL import Image |
28 |
28 |
29 #kiwipycon |
29 #scipycon |
30 from project.kiwipycon.utils import set_message_cookie |
30 from project.scipycon.utils import set_message_cookie |
31 from project.kiwipycon.talk.models import Talk |
31 from project.scipycon.talk.models import Talk |
32 from project.kiwipycon.registration.models import Registration |
32 from project.scipycon.registration.models import Registration |
33 from project.kiwipycon.registration.models import Wifi |
33 from project.scipycon.registration.models import Wifi |
34 from project.kiwipycon.registration.forms import WifiForm |
34 from project.scipycon.registration.forms import WifiForm |
35 from project.kiwipycon.sponsor.models import Sponsor |
35 |
36 |
36 from .utils import scipycon_createuser |
37 from .utils import kiwipycon_createuser |
|
38 from .utils import handle_uploaded_photo |
37 from .utils import handle_uploaded_photo |
39 from .forms import RegisterForm |
38 from .forms import RegisterForm |
40 from .forms import EditProfileForm |
39 from .forms import EditProfileForm |
41 from .forms import UsernameForm |
40 from .forms import UsernameForm |
42 |
41 |
109 |
108 |
110 profile.url = form.data.get("url") |
109 profile.url = form.data.get("url") |
111 profile.about = form.data.get("about") |
110 profile.about = form.data.get("about") |
112 profile.save() |
111 profile.save() |
113 |
112 |
114 redirect_to = reverse("kiwipycon_account") |
113 redirect_to = reverse("scipycon_account") |
115 return set_message_cookie(redirect_to, |
114 return set_message_cookie(redirect_to, |
116 msg = u"Your profile has been changed.") |
115 msg = u"Your profile has been changed.") |
117 |
116 |
118 else: |
117 else: |
119 form = EditProfileForm(initial={"email" : user.email, |
118 form = EditProfileForm(initial={"email" : user.email, |
133 Integration of register and login form |
132 Integration of register and login form |
134 It uses Django's standard AuthenticationForm, though. |
133 It uses Django's standard AuthenticationForm, though. |
135 """ |
134 """ |
136 user = request.user |
135 user = request.user |
137 if user.is_authenticated(): |
136 if user.is_authenticated(): |
138 redirect_to = reverse("kiwipycon_account") |
137 redirect_to = reverse("scipycon_account") |
139 return set_message_cookie(redirect_to, |
138 return set_message_cookie(redirect_to, |
140 msg = u"Redirected to account from login form.") |
139 msg = u"Redirected to account from login form.") |
141 |
140 |
142 # Using Djangos default AuthenticationForm |
141 # Using Djangos default AuthenticationForm |
143 login_form = AuthenticationForm() |
142 login_form = AuthenticationForm() |
148 |
147 |
149 if login_form.is_valid(): |
148 if login_form.is_valid(): |
150 redirect_to = request.POST.get("next") |
149 redirect_to = request.POST.get("next") |
151 # Light security check -- make sure redirect_to isn't garbage. |
150 # Light security check -- make sure redirect_to isn't garbage. |
152 if not redirect_to or '//' in redirect_to or ' ' in redirect_to: |
151 if not redirect_to or '//' in redirect_to or ' ' in redirect_to: |
153 redirect_to = reverse("kiwipycon_account") |
152 redirect_to = reverse("scipycon_account") |
154 |
153 |
155 from django.contrib.auth import login |
154 from django.contrib.auth import login |
156 login(request, login_form.get_user()) |
155 login(request, login_form.get_user()) |
157 |
156 |
158 return set_message_cookie(redirect_to, msg = u"You have been logged in.") |
157 return set_message_cookie(redirect_to, msg = u"You have been logged in.") |
159 |
158 |
160 elif request.POST.get("action") == "register": |
159 elif request.POST.get("action") == "register": |
161 register_form = RegisterForm(data=request.POST) |
160 register_form = RegisterForm(data=request.POST) |
162 if register_form.is_valid(): |
161 if register_form.is_valid(): |
163 |
162 |
164 user = kiwipycon_createuser(request, register_form.data) |
163 user = scipycon_createuser(request, register_form.data) |
165 |
164 |
166 redirect_to = request.POST.get("next") |
165 redirect_to = request.POST.get("next") |
167 if not redirect_to or '//' in redirect_to or ' ' in redirect_to: |
166 if not redirect_to or '//' in redirect_to or ' ' in redirect_to: |
168 redirect_to = reverse("kiwipycon_account") |
167 redirect_to = reverse("scipycon_account") |
169 |
168 |
170 return set_message_cookie( |
169 return set_message_cookie( |
171 redirect_to, msg = u"You have been registered and logged in.") |
170 redirect_to, msg = u"You have been registered and logged in.") |
172 |
171 |
173 # Get next_url |
172 # Get next_url |
174 next_url = request.REQUEST.get("next") |
173 next_url = request.REQUEST.get("next") |
175 if next_url is None: |
174 if next_url is None: |
176 next_url = request.META.get("HTTP_REFERER") |
175 next_url = request.META.get("HTTP_REFERER") |
177 if next_url is None: |
176 if next_url is None: |
178 next_url = reverse("kiwipycon_account") |
177 next_url = reverse("scipycon_account") |
179 # Get just the path of the url. See django.contrib.auth.views.login for more |
178 # Get just the path of the url. See django.contrib.auth.views.login for more |
180 next_url = urlparse(next_url) |
179 next_url = urlparse(next_url) |
181 next_url = next_url[2] |
180 next_url = next_url[2] |
182 |
181 |
183 try: |
182 try: |
210 """ |
209 """ |
211 if request.method == "POST": |
210 if request.method == "POST": |
212 form = PasswordChangeForm(request.user, request.POST) |
211 form = PasswordChangeForm(request.user, request.POST) |
213 if form.is_valid(): |
212 if form.is_valid(): |
214 form.save() |
213 form.save() |
215 redirect_to = reverse("kiwipycon_account") |
214 redirect_to = reverse("scipycon_account") |
216 return set_message_cookie(redirect_to, |
215 return set_message_cookie(redirect_to, |
217 msg = u"Your password has been changed.") |
216 msg = u"Your password has been changed.") |
218 else: |
217 else: |
219 form = PasswordChangeForm(request.user) |
218 form = PasswordChangeForm(request.user) |
220 |
219 |
229 if request.method == "POST": |
228 if request.method == "POST": |
230 username_form = UsernameForm(initial={"username" : request.user.username}, data=request.POST) |
229 username_form = UsernameForm(initial={"username" : request.user.username}, data=request.POST) |
231 if username_form.is_valid(): |
230 if username_form.is_valid(): |
232 request.user.username = username_form.cleaned_data.get("username") |
231 request.user.username = username_form.cleaned_data.get("username") |
233 request.user.save() |
232 request.user.save() |
234 redirect_to = reverse("kiwipycon_account") |
233 redirect_to = reverse("scipycon_account") |
235 return set_message_cookie(redirect_to, |
234 return set_message_cookie(redirect_to, |
236 msg = u"Your username has been changed.") |
235 msg = u"Your username has been changed.") |
237 else: |
236 else: |
238 username_form = UsernameForm(initial={"username" : request.user.username}) |
237 username_form = UsernameForm(initial={"username" : request.user.username}) |
239 |
238 |