Changeset fd6da93 in OpenWorkouts-current for ow/views/user.py
- Timestamp:
- Feb 26, 2019, 11:11:43 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- a4e4799
- Parents:
- d411dae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/user.py
rd411dae rfd6da93 22 22 from ..models.root import OpenWorkouts 23 23 from ..views.renderers import OWFormRenderer 24 from ..utilities import timedelta_to_hms, get_verification_token 24 from ..utilities import ( 25 timedelta_to_hms, 26 get_verification_token, 27 get_available_locale_names 28 ) 25 29 from ..mail import send_verification_email 26 30 … … 76 80 password = request.POST.get('password', None) 77 81 if password is not None and user.check_password(password): 82 # look for the value of locale for this user, to set the 83 # LOCALE cookie, so the UI appears on the pre-selected lang 84 default_locale = request.registry.settings.get( 85 'pyramid.default_locale_name') 86 locale = getattr(user, 'locale', default_locale) 87 request.response.set_cookie('_LOCALE_', locale) 88 # log in the user and send back to the place he wanted to 89 # visit 78 90 headers = remember(request, str(user.uid)) 91 request.response.headers.extend(headers) 79 92 redirect_url = return_to or request.resource_url(user) 80 return HTTPFound(location=redirect_url, headers=headers) 93 return HTTPFound(location=redirect_url, 94 headers=request.response.headers) 81 95 else: 82 96 message = _('Wrong password') … … 100 114 @view_config(context=OpenWorkouts, name='logout') 101 115 def logout(context, request): 116 request.response.delete_cookie('_LOCALE_') 102 117 headers = forget(request) 103 return HTTPFound(location=request.resource_url(context), headers=headers) 118 request.response.headers.extend(headers) 119 return HTTPFound(location=request.resource_url(context), 120 headers=request.response.headers) 104 121 105 122 … … 319 336 renderer='ow:templates/edit_profile.pt') 320 337 def edit_profile(context, request): 338 default_locale = request.registry.settings.get( 339 'pyramid.default_locale_name') 340 available_locale_names = get_available_locale_names() 341 current_locale = request.cookies.get('_LOCALE_', default_locale) 321 342 # if not given a file there is an empty byte in POST, which breaks 322 343 # our blob storage validator. … … 340 361 # reindex 341 362 request.root.reindex(context) 363 # set the cookie for the locale/lang 364 request.response.set_cookie('_LOCALE_', form.data['locale']) 365 current_locale = form.data['locale'] 342 366 # Saved, send the user to the public view of her profile 343 return HTTPFound(location=request.resource_url(context, 'profile')) 367 return HTTPFound(location=request.resource_url(context, 'profile'), 368 headers=request.response.headers) 344 369 345 370 # prevent crashes on the form … … 348 373 349 374 return {'form': OWFormRenderer(form), 350 'timezones': common_timezones} 375 'timezones': common_timezones, 376 'available_locale_names': available_locale_names, 377 'current_locale': current_locale} 351 378 352 379
Note: See TracChangeset
for help on using the changeset viewer.