49 from soc.views import helper |
49 from soc.views import helper |
50 from soc.views import out_of_band |
50 from soc.views import out_of_band |
51 from soc.views.helper import redirects |
51 from soc.views.helper import redirects |
52 |
52 |
53 |
53 |
54 DEF_NO_USER_LOGIN_MSG_FMT = ugettext( |
54 DEF_NO_USER_LOGIN_MSG= ugettext( |
55 'Please create <a href="/user/edit">User Profile</a>' |
55 'Please create <a href="/user/create_profile">User Profile</a>' |
56 ' in order to view this page.') |
56 ' in order to view this page.') |
57 |
57 |
58 DEF_AGREE_TO_TOS_MSG_FMT = ugettext( |
58 DEF_AGREE_TO_TOS_MSG_FMT = ugettext( |
59 'You must agree to the <a href="%(tos_link)s">site-wide Terms of' |
59 'You must agree to the <a href="%(tos_link)s">site-wide Terms of' |
60 ' Service</a> in your <a href="/user/edit">User Profile</a>' |
60 ' Service</a> in your <a href="/user/edit_profile">User Profile</a>' |
61 ' in order to view this page.') |
61 ' in order to view this page.') |
62 |
62 |
63 DEF_DEV_LOGOUT_LOGIN_MSG_FMT = ugettext( |
63 DEF_DEV_LOGOUT_LOGIN_MSG_FMT = ugettext( |
64 'Please <a href="%%(sign_out)s">sign out</a>' |
64 'Please <a href="%%(sign_out)s">sign out</a>' |
65 ' and <a href="%%(sign_in)s">sign in</a>' |
65 ' and <a href="%%(sign_in)s">sign in</a>' |
72 'Please <a href="%(sign_out)s">sign out</a> in order to view this page') |
72 'Please <a href="%(sign_out)s">sign out</a> in order to view this page') |
73 |
73 |
74 DEF_GROUP_NOT_FOUND_MSG = ugettext( |
74 DEF_GROUP_NOT_FOUND_MSG = ugettext( |
75 'The requested Group can not be found') |
75 'The requested Group can not be found') |
76 |
76 |
|
77 DEF_USER_ACCOUNT_INVALID_MSG_FMT = ugettext( |
|
78 'The <b><i>%(email)s</i></b> account cannot be used with this site, for' |
|
79 ' one or more of the following reasons:' |
|
80 '<ul>' |
|
81 ' <li>the account is invalid</li>' |
|
82 ' <li>the account is already attached to a User profile and cannot be' |
|
83 ' used to create another one</li>' |
|
84 ' <li>the account is a former account that cannot be used again</li>' |
|
85 '</ul>') |
77 |
86 |
78 def denySidebar(fun): |
87 def denySidebar(fun): |
79 """Decorator that denies access if the sidebar is calling. |
88 """Decorator that denies access if the sidebar is calling. |
80 """ |
89 """ |
81 |
90 |
321 """ |
330 """ |
322 |
331 |
323 self.checkIsLoggedIn(django_args) |
332 self.checkIsLoggedIn(django_args) |
324 |
333 |
325 if not self.user: |
334 if not self.user: |
326 raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG_FMT) |
335 raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG) |
327 |
336 |
328 if user_logic.agreesToSiteToS(self.user): |
337 if user_logic.agreesToSiteToS(self.user): |
329 return |
338 return |
330 |
339 |
331 # Would not reach this point of site-wide ToS did not exist, since |
340 # Would not reach this point of site-wide ToS did not exist, since |
332 # agreesToSiteToS() call above always returns True if no ToS is in effect. |
341 # agreesToSiteToS() call above always returns True if no ToS is in effect. |
333 login_msg_fmt = DEF_AGREE_TO_TOS_MSG_FMT % { |
342 login_msg_fmt = DEF_AGREE_TO_TOS_MSG_FMT % { |
334 'tos_link': redirects.getToSRedirect(site_logic.getSingleton())} |
343 'tos_link': redirects.getToSRedirect(site_logic.getSingleton())} |
335 |
344 |
336 raise out_of_band.LoginRequest(message_fmt=login_msg_fmt) |
345 raise out_of_band.LoginRequest(message_fmt=login_msg_fmt) |
|
346 |
|
347 def checkIsUnusedAccount(self, django_args): |
|
348 """Raises an alternate HTTP response if Google Account has a User entity. |
|
349 |
|
350 Args: |
|
351 django_args: a dictionary with django's arguments |
|
352 |
|
353 Raises: |
|
354 AccessViolationResponse: |
|
355 * if a User exists for the logged-in Google Account, or |
|
356 * if a User has this Gooogle Account in their formerAccounts list |
|
357 """ |
|
358 |
|
359 self.checkIsLoggedIn(django_args) |
|
360 |
|
361 if self.user or user_logic.isFormerAccount(self.id): |
|
362 message_fmt = DEF_USER_ACCOUNT_INVALID_MSG_FMT % { |
|
363 'email' : self.id.email()} |
|
364 raise out_of_band.LoginRequest(message_fmt=message_fmt) |
|
365 |
|
366 return |
|
367 |
|
368 def checkHasUserEntity(self, django_args): |
|
369 """Raises an alternate HTTP response if Google Account has no User entity. |
|
370 |
|
371 Args: |
|
372 django_args: a dictionary with django's arguments |
|
373 |
|
374 Raises: |
|
375 AccessViolationResponse: |
|
376 * if no User exists for the logged-in Google Account, or |
|
377 * if no Google Account is logged in at all |
|
378 """ |
|
379 |
|
380 self.checkIsLoggedIn(django_args) |
|
381 |
|
382 if not self.user: |
|
383 raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG) |
|
384 |
|
385 return |
|
386 |
337 |
387 |
338 def checkIsDeveloper(self, django_args): |
388 def checkIsDeveloper(self, django_args): |
339 """Raises an alternate HTTP response if Google Account is not a Developer. |
389 """Raises an alternate HTTP response if Google Account is not a Developer. |
340 |
390 |
341 Args: |
391 Args: |