def change_email(request, activation_key=None, email_template_name='registration/email_change_email.txt', form_template_name='registration/email_change_form.html', confirm_template_name='registration/email_change_done.html', extra_context=None): extra_context = extra_context or {} if not settings.EMAILCHANGE_ENABLED: raise PermissionDenied if activation_key: try: try: email_change = EmailChange.objects.get( activation_key=activation_key) except EmailChange.DoesNotExist: logger.error("[change-email] Invalid or used activation " "code, %s", activation_key) raise Http404 if ( request.user.is_authenticated() and request.user == email_change.user or not request.user.is_authenticated() ): user = EmailChange.objects.change_email(activation_key) msg = _(astakos_messages.EMAIL_CHANGED) messages.success(request, msg) transaction.commit() return HttpResponseRedirect(reverse('edit_profile')) else: logger.error("[change-email] Access from invalid user, %s %s", email_change.user, request.user.log_display) raise PermissionDenied except ValueError, e: messages.error(request, e) transaction.rollback() return HttpResponseRedirect(reverse('index')) return render_response(confirm_template_name, modified_user=user if 'user' in locals() else None, context_instance=get_context(request, extra_context))
def change_email(request, activation_key=None, email_template_name='registration/email_change_email.txt', form_template_name='registration/email_change_form.html', confirm_template_name='registration/email_change_done.html', extra_context=None): extra_context = extra_context or {} if not settings.EMAILCHANGE_ENABLED: raise PermissionDenied if activation_key: try: try: email_change = EmailChange.objects.get( activation_key=activation_key) except EmailChange.DoesNotExist: logger.error( "[change-email] Invalid or used activation " "code, %s", activation_key) raise Http404 if (request.user.is_authenticated() and request.user == email_change.user or not request.user.is_authenticated()): user = EmailChange.objects.change_email(activation_key) msg = _(astakos_messages.EMAIL_CHANGED) messages.success(request, msg) transaction.commit() return HttpResponseRedirect(reverse('edit_profile')) else: logger.error("[change-email] Access from invalid user, %s %s", email_change.user, request.user.log_display) raise PermissionDenied except ValueError, e: messages.error(request, e) transaction.rollback() return HttpResponseRedirect(reverse('index')) return render_response( confirm_template_name, modified_user=user if 'user' in locals() else None, context_instance=get_context(request, extra_context))
def handle_third_party_auto_signup(request, provider, provider_info, identifier, user_info): """Create AstakosUser for third party user without requiring signup form. Handle third party signup by automatically creating an AstakosUser. This is performed when the user's profile is automatically set by the provider. """ try: email = user_info['email'] first_name = user_info['first_name'] last_name = user_info['last_name'] except KeyError as e: raise Exception("Invalid user info. Missing '%s'", str(e)) has_signed_terms = not get_latest_terms() user = auth.make_user(email=email, first_name=first_name, last_name=last_name, has_signed_terms=has_signed_terms) provider_data = { 'affiliation': user_info.get('affiliation', provider), 'info': provider_info } provider = auth_providers.get_provider(module=provider, user_obj=user, identifier=identifier, **provider_data) provider.add_to_user() # Handle user activation activation_backend = activation_backends.get_backend() result = activation_backend.handle_registration(user) activation_backend.send_result_notifications(result, user) # Commit user entry transaction.commit() return user
**form_kwargs) if form.is_valid(): user = form.create_user() result = activation_backend.handle_registration(user) if result.status == \ activation_backend.Result.PENDING_MODERATION: # user should be warned that his account is not active yet status = messages.WARNING else: status = messages.SUCCESS message = result.message activation_backend.send_result_notifications(result, user) # commit user entry transaction.commit() if user and user.is_active: # activation backend directly activated the user # log him in next = request.POST.get('next', '') response = prepare_response(request, user, next=next) return response messages.add_message(request, status, message) return HttpResponseRedirect(reverse(on_success)) ldap_login_form = None if 'ldap' in settings.IM_MODULES: ldap_login_form = LDAPLoginForm(request)