def profile_create(request): try: request.user.get_profile() return http.HttpResponseRedirect(reverse('dashboard')) except UserProfile.DoesNotExist: pass form = forms.CreateProfileForm(request.POST) if form.is_valid(): profile = form.save(commit=False) profile.user = request.user profile.id = profile.user.id profile.user.email = profile.email profile.user.save() profile.confirmation_code = profile.generate_confirmation_code() profile.save() path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) msg = _('Thanks! We have sent an email to %s with ' 'instructions for completing your ' 'registration.') % profile.email messages.info(request, msg) return http.HttpResponseRedirect(reverse('dashboard')) else: messages.error(request, _('There are errors in this form. Please ' 'correct them and resubmit.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, 'domain': Site.objects.get_current().domain, }, context_instance=RequestContext(request))
def profile_edit_openids_complete(request): openid_response = openid_views.parse_openid_response(request) yours_msg = _('The identity %s has already been claimed by you.') theirs_msg = _('The identity %s has already been claimed by another user.') if openid_response: if openid_response.status == openid_views.SUCCESS: url = openid_response.identity_url try: user_openid = UserOpenID.objects.get( claimed_id__exact=url) except UserOpenID.DoesNotExist: user_openid = UserOpenID(user=request.user, claimed_id=openid_response.identity_url, display_id=openid_response.endpoint.getDisplayIdentifier()) user_openid.save() messages.info(request, _('The identity %s has been saved.') % url) else: if user_openid.user == request.user: messages.error(request, yours_msg % url) else: messages.error(request, theirs_msg % url) elif openid_response.status == openid_views.FAILURE: messages.error(request, _('OpenID authentication failed: %s') % openid_response.message) elif openid_response.status == openid_views.CANCEL: return messages.error(request, _('Authentication cancelled.')) else: return messages.error( _('Unknown OpenID response type: %r') % openid_response.status) else: return messages.error(_('This is an OpenID relying party endpoint.')) return http.HttpResponseRedirect(reverse('users_profile_edit_openids'))
def direct_signup_adopter(request, slug): project = get_object_or_404(Project, slug=slug) profile = request.user.get_profile() if request.method != 'POST': return http.HttpResponseForbidden( _('This page can not be accessed with a get request.')) try: participation = project.participants().get(user=profile) except Participation.DoesNotExist: return http.HttpResponseForbidden( _('You need to be active in this challenge to become an adopter.')) if participation.organizing: return http.HttpResponseForbidden( _('Organizers do not need to adopt the challenges.')) completed_count = PerUserTaskCompletion.objects.filter( page__project=project, page__deleted=False, unchecked_on__isnull=True, user=profile).count() tasks_count = Page.objects.filter(project=project, listed=True, deleted=False).count() if completed_count != tasks_count: return http.HttpResponseForbidden( _('You need to complete all tasks before becoming an adopter.')) if participation.adopter: return http.HttpResponseForbidden( _('You already adopted this challenge.')) participation.adopter = True participation.save() msg = _('Thanks! ') msg += _('You are now listed among the peers who offered their help.') messages.info(request, msg) return http.HttpResponseRedirect(project.get_absolute_url())
def profile_create(request): try: request.user.get_profile() return http.HttpResponseRedirect(reverse('dashboard')) except UserProfile.DoesNotExist: pass form = forms.CreateProfileForm(request.POST) if form.is_valid(): profile = form.save(commit=False) profile.user = request.user profile.id = profile.user.id profile.user.email = profile.email profile.user.save() profile.confirmation_code = profile.generate_confirmation_code() profile.save() path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) msg = _('Thanks! We have sent an email to %s with ' 'instructions for completing your ' 'registration.') % profile.email messages.info(request, msg) request.session['send_registration_event'] = True return http.HttpResponseRedirect(reverse('dashboard')) else: messages.error(request, _('There are errors in this form. Please ' 'correct them and resubmit.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, 'domain': Site.objects.get_current().domain, }, context_instance=RequestContext(request))
def dashboard(request): """Personalized dashboard for authenticated users.""" try: profile = request.user.get_profile() except UserProfile.DoesNotExist: user = request.user username = '' if user.username[:10] != 'openiduser': username = user.username form = CreateProfileForm( initial={ 'full_name': ' '.join((user.first_name, user.last_name)), 'email': user.email, 'username': username, }) messages.info( request, _('Please fill out your profile to finish registration.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request)) show_welcome = not profile.discard_welcome activities = Activity.objects.dashboard(request.user.get_profile()) activities = filter_activities(request, activities) context = { 'profile': profile, 'profile_view': False, 'show_welcome': show_welcome, 'domain': Site.objects.get_current().domain, 'dashboard_url': reverse('dashboard'), } context.update(get_pagination_context(request, activities)) return render_to_response('dashboard/dashboard.html', context, context_instance=RequestContext(request))
def profile_create(request): if request.method != 'POST': return http.HttpResponseRedirect(reverse('dashboard_index')) try: request.user.get_profile() return http.HttpResponseRedirect(reverse('dashboard_index')) except UserProfile.DoesNotExist: pass form = forms.CreateProfileForm(request.POST) if form.is_valid(): profile = form.save(commit=False) profile.user = request.user profile.confirmation_code = profile.generate_confirmation_code() profile.save() path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) auth.logout(request) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(profile.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse('dashboard_index')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request))
def decorator(*args, **kwargs): request = args[0] if request.user.is_authenticated(): messages.info(request, _("You are already logged into an account.")) return HttpResponseRedirect(reverse('dashboard')) return func(*args, **kwargs)
def decorator(*args, **kwargs): request = args[0] if request.user.is_authenticated(): messages.info(request, _("You are already logged into an account.")) return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) return func(*args, **kwargs)
def profile_create(request): try: request.user.get_profile() return http.HttpResponseRedirect(reverse("dashboard")) except UserProfile.DoesNotExist: pass form = forms.CreateProfileForm(request.POST) if form.is_valid(): profile = form.save(commit=False) profile.user = request.user profile.id = profile.user.id profile.user.email = profile.email profile.user.save() profile.confirmation_code = profile.generate_confirmation_code() profile.save() path = reverse( "users_confirm_registration", kwargs={"username": profile.username, "token": profile.confirmation_code} ) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) auth.logout(request) msg = _( "Thanks! We have sent an email to {0} with " "instructions for completing your " "registration." ).format(profile.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse("splash")) else: messages.error(request, _("There are errors in this form. Please " "correct them and resubmit.")) return render_to_response( "dashboard/setup_profile.html", {"form": form, "domain": Site.objects.get_current().domain}, context_instance=RequestContext(request), )
def dashboard(request): """Personalized dashboard for authenticated users.""" try: profile = request.user.get_profile() except UserProfile.DoesNotExist: user = request.user username = '' if user.username[:10] != 'openiduser': username = user.username form = CreateProfileForm(initial={ 'full_name': ' '.join((user.first_name, user.last_name)), 'email': user.email, 'username': username, }) messages.info(request, _('Please fill out your profile to finish registration.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request)) show_welcome = not profile.discard_welcome activities = Activity.objects.dashboard( request.user.get_profile()) activities = filter_activities(request, activities) context = { 'profile': profile, 'profile_view': False, 'show_welcome': show_welcome, 'domain': Site.objects.get_current().domain, 'dashboard_url': reverse('dashboard'), } context.update(get_pagination_context(request, activities)) return render_to_response('dashboard/dashboard.html', context, context_instance=RequestContext(request))
def login(request): """Log the user in. Lifted most of this code from zamboni.""" if 'next' in request.GET: request = _clean_next_url(request) request.session['next'] = request.GET['next'] logout(request) r = auth_views.login(request, template_name='users/signin.html', authentication_form=forms.AuthenticationForm) if isinstance(r, http.HttpResponseRedirect): # Succsesful log in according to django. Now we do our checks. I do # the checks here instead of the form's clean() because I want to use # the messages framework and it's not available in the request there user = request.user.get_profile() if user.confirmation_code: logout(request) log.info(u'Attempt to log in with unconfirmed account (%s)' % user) msg1 = _(('A link to activate your user account was sent by email ' 'to your address {0}. You have to click it before you ' 'can log in.').format(user.email)) url = request.build_absolute_uri( reverse('users_confirm_resend', kwargs=dict(username=user.username))) msg2 = _(('If you did not receive the confirmation email, make ' 'sure your email service did not mark it as "junk ' 'mail" or "spam". If you need to, you can have us ' '<a href="%s">resend the confirmation message</a> ' 'to your email address mentioned above.') % url) messages.error(request, msg1) messages.info(request, msg2, safe=True) return render_to_response('users/signin.html', { 'form': auth_forms.AuthenticationForm(), }, context_instance=RequestContext(request)) if request.POST.get('remember_me', None): request.session.set_expiry(settings.SESSION_COOKIE_AGE) log.debug(u'User signed in with remember_me option') next_param = request.session.get('next', None) if next_param: del request.session['next'] if not next_param.startswith('/'): next_param = '/%s' % (next_param,) return http.HttpResponseRedirect(next_param) elif request.method == 'POST': messages.error(request, _('Incorrect email or password.')) # run through auth_views.login again to render template with messages. r = auth_views.login(request, template_name='users/signin.html', authentication_form=forms.AuthenticationForm) return r
def register(request): """Present user registration form and handle registrations.""" request = _process_redirect(request) if request.method == 'POST': form = forms.RegisterForm(data=request.POST) if form.is_valid(): django_user = form.save(commit=False) user = create_profile(django_user) user.set_password(form.cleaned_data['password']) user.generate_confirmation_code() user.full_name = form.cleaned_data['full_name'] user.preflang = form.cleaned_data['preflang'] user.save() log.info(u"Registered new account for user (%s)", user) messages.success( request, _('Congratulations! Your user account ' 'was successfully created.')) path = reverse('users_confirm_registration', kwargs={ 'username': user.username, 'token': user.confirmation_code, }) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(user.email) messages.info(request, msg) response = login(request) request.session['send_registration_event'] = True return response else: messages.error( request, _('There are errors in this form. Please ' 'correct them and resubmit.')) else: form = forms.RegisterForm() redirect_field_value = request.session.get(REDIRECT_FIELD_NAME, reverse('dashboard')) return render_to_response( 'users/register.html', { 'form': form, 'domain': Site.objects.get_current().domain, 'redirect_field_name': REDIRECT_FIELD_NAME, 'redirect_field_value': urllib2.quote(redirect_field_value), }, context_instance=RequestContext(request))
def confirm_resend(request, username): """Resend a confirmation code.""" profile = get_object_or_404(UserProfile, username=username) if profile.confirmation_code: path = reverse( "users_confirm_registration", kwargs={"username": profile.username, "token": profile.confirmation_code} ) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) msg = _("A confirmation code has been sent to the email address " "associated with your account.") messages.info(request, msg) return http.HttpResponseRedirect(reverse("users_login"))
def confirm_resend(request): """Resend a confirmation code.""" profile = request.user.get_profile() if profile.confirmation_code: path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url, new_user=False) msg = _('A link to confirm your email address was sent ' 'to %s.') messages.info(request, msg % profile.email) return http.HttpResponseRedirect(reverse('preferences_email'))
def contact_organizers(request, slug): project = get_object_or_404(Project, slug=slug) if request.method == "POST": form = project_forms.ProjectContactOrganizersForm(request.POST) if form.is_valid(): form.save(sender=request.user) messages.info(request, _("Message successfully sent.")) return http.HttpResponseRedirect(project.get_absolute_url()) else: form = project_forms.ProjectContactOrganizersForm() form.fields["project"].initial = project.pk return render_to_response( "projects/contact_organizers.html", {"form": form, "project": project}, context_instance=RequestContext(request) )
def unconfirmed_account_notice(request, user): log.info(u'Attempt to log in with unconfirmed account (%s)' % user) msg1 = _('A link to activate your user account was sent by email ' 'to your address %s. You have to click it before you ' 'can log in.') % user.email url = request.build_absolute_uri( reverse('users_confirm_resend', kwargs=dict(username=user.username))) msg2 = _('If you did not receive the confirmation email, make ' 'sure your email service did not mark it as "junk ' 'mail" or "spam". If you need to, you can have us ' '<a href="%s">resend the confirmation message</a> ' 'to your email address mentioned above.') % url messages.error(request, msg1) messages.info(request, msg2, safe=True)
def register(request): """Present user registration form and handle registrations.""" request = _process_redirect(request) if request.method == 'POST': form = forms.RegisterForm(data=request.POST) if form.is_valid(): django_user = form.save(commit=False) user = create_profile(django_user) user.set_password(form.cleaned_data['password']) user.generate_confirmation_code() user.full_name = form.cleaned_data['full_name'] user.preflang = form.cleaned_data['preflang'] user.save() log.info(u"Registered new account for user (%s)", user) messages.success(request, _('Congratulations! Your user account ' 'was successfully created.')) path = reverse('users_confirm_registration', kwargs={ 'username': user.username, 'token': user.confirmation_code, }) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(user.email) messages.info(request, msg) response = login(request) request.session['send_registration_event'] = True return response else: messages.error(request, _('There are errors in this form. Please ' 'correct them and resubmit.')) else: form = forms.RegisterForm() redirect_field_value = request.session.get( REDIRECT_FIELD_NAME, reverse('dashboard')) return render_to_response('users/register.html', { 'form': form, 'domain': Site.objects.get_current().domain, 'redirect_field_name': REDIRECT_FIELD_NAME, 'redirect_field_value': urllib2.quote(redirect_field_value), }, context_instance=RequestContext(request))
def unconfirmed_account_notice(request, user): log.info(u'Attempt to log in with unconfirmed account (%s)' % user) msg1 = _(('A link to activate your user account was sent by email ' 'to your address {0}. You have to click it before you ' 'can log in.').format(user.email)) url = request.build_absolute_uri( reverse('users_confirm_resend', kwargs=dict(username=user.username))) msg2 = _(('If you did not receive the confirmation email, make ' 'sure your email service did not mark it as "junk ' 'mail" or "spam". If you need to, you can have us ' '<a href="%s">resend the confirmation message</a> ' 'to your email address mentioned above.') % url) messages.error(request, msg1) messages.info(request, msg2, safe=True)
def confirm_resend(request, username): """Resend a confirmation code.""" profile = get_object_or_404(UserProfile, username=username) if profile.confirmation_code: path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) msg = _('A confirmation code has been sent to the email address ' 'associated with your account.') messages.info(request, msg) return http.HttpResponseRedirect(reverse('users_login'))
def contact_organizers(request, slug): project = get_object_or_404(Project, slug=slug) if request.method == 'POST': form = project_forms.ProjectContactOrganizersForm(request.POST) if form.is_valid(): form.save(sender=request.user) messages.info(request, _("Message successfully sent.")) return http.HttpResponseRedirect(project.get_absolute_url()) else: form = project_forms.ProjectContactOrganizersForm() form.fields['project'].initial = project.pk return render_to_response('projects/contact_organizers.html', { 'form': form, 'project': project, }, context_instance=RequestContext(request))
def dashboard(request, page=1): """Personalized dashboard for authenticated users.""" try: profile = request.user.get_profile() except UserProfile.DoesNotExist: user = request.user username = '' if user.username[:10] != 'openiduser': username = user.username form = CreateProfileForm( initial={ 'full_name': ' '.join((user.first_name, user.last_name)), 'email': user.email, 'username': username, }) messages.info( request, _('Please fill out your profile to finish registration.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request)) current_projects = profile.get_current_projects() users_following = profile.following() users_followers = profile.followers() activities = Activity.objects.dashboard(request.user.get_profile()) paginator = Paginator(activities, 25) try: current_page = paginator.page(page) except EmptyPage: raise Http404 show_welcome = not profile.discard_welcome return render_to_response('dashboard/dashboard.html', { 'current_projects': current_projects, 'users_following': users_following, 'users_followers': users_followers, 'show_welcome': show_welcome, 'paginator': paginator, 'page_num': page, 'next_page': int(page) + 1, 'prev_page': int(page) - 1, 'num_pages': paginator.num_pages, 'page': current_page, 'domain': Site.objects.get_current().domain, }, context_instance=RequestContext(request))
def register(request): """Present user registration form and handle registrations.""" if REDIRECT_FIELD_NAME in request.GET: request = _clean_redirect_url(request) request.session[REDIRECT_FIELD_NAME] = request.GET[REDIRECT_FIELD_NAME] if request.method == 'POST': form = forms.RegisterForm(data=request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(form.cleaned_data['password']) user.generate_confirmation_code() user.save() user.create_django_user() log.info(u"Registered new account for user (%s)", user) messages.success( request, _('Congratulations! Your user account ' 'was successfully created.')) path = reverse('users_confirm_registration', kwargs={ 'username': user.username, 'token': user.confirmation_code, }) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(user.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse('users_login')) else: messages.error( request, _('There are errors in this form. Please ' 'correct them and resubmit.')) else: form = forms.RegisterForm() return render_to_response('users/register.html', { 'form': form, }, context_instance=RequestContext(request))
def dashboard(request): """Personalized dashboard for authenticated users.""" try: profile = request.user.get_profile() current_projects = profile.get_current_projects(only_public=False) users_following = profile.following() users_followers = profile.followers() interests = profile.tags.filter(category='interest').exclude( slug='').order_by('name') desired_topics = profile.tags.exclude(slug='').filter( category='desired_topic').order_by('name') links = Link.objects.filter(user=profile, project__isnull=True).order_by('index') except UserProfile.DoesNotExist: user = request.user username = '' if user.username[:10] != 'openiduser': username = user.username form = CreateProfileForm(initial={ 'full_name': ' '.join((user.first_name, user.last_name)), 'email': user.email, 'username': username, }) messages.info(request, _('Please fill out your profile to finish registration.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request)) show_welcome = not profile.discard_welcome activities = Activity.objects.dashboard( request.user.get_profile()) activities = filter_activities(request, activities) context = { 'profile': profile, 'current_projects': current_projects, 'users_following': users_following, 'users_followers': users_followers, 'interests': interests, 'desired_topics': desired_topics, 'links': links, 'show_welcome': show_welcome, 'domain': Site.objects.get_current().domain, 'dashboard_url': reverse('dashboard'), } context.update(get_pagination_context(request, activities)) return render_to_response('dashboard/dashboard.html', context, context_instance=RequestContext(request))
def contact_followers(request, slug): user = request.user.get_profile() project = get_object_or_404(Project, slug=slug) if project.created_by != user: return http.HttpResponseForbidden() if request.method == "POST": form = project_forms.ProjectContactUsersForm(request.POST) if form.is_valid(): form.save(sender=request.user) messages.info(request, _("Message successfully sent.")) return http.HttpResponseRedirect(reverse("projects_show", kwargs={"slug": project.slug})) else: form = project_forms.ProjectContactUsersForm() form.fields["project"].initial = project.pk return render_to_response( "projects/contact_users.html", {"form": form, "project": project}, context_instance=RequestContext(request) )
def contact_entrants(request, slug): challenge = get_object_or_404(Challenge, slug=slug) if request.method == 'POST': form = ChallengeContactForm(request.POST) if form.is_valid(): form.save(sender=request.user) messages.info(request, _('Message sent successfully.')) return HttpResponseRedirect(reverse('challenges_show', kwargs={ 'slug': challenge.slug, })) else: form = ChallengeContactForm() form.fields['challenge'].initial = challenge.pk return render_to_response('challenges/contact_entrants.html', { 'form': form, 'challenge': challenge, }, context_instance=RequestContext(request))
def email(request): profile = request.user.get_profile() email = profile.user.email if request.method == "POST": form = forms.EmailEditForm(profile.username, request.POST, request.FILES, instance=profile) if form.is_valid(): profile = form.save(commit=False) profile.user.email = profile.email profile.user.save() profile.confirmation_code = profile.generate_confirmation_code() profile.save() path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url, new_user=False) msg1 = _('A link to confirm your email address was sent ' 'to %s.') % profile.email messages.info(request, msg1) form = forms.EmailEditForm(profile.username, instance=profile) else: form = forms.EmailEditForm(profile.username, instance=profile) if profile.confirmation_code and not form.is_bound: url = request.build_absolute_uri(reverse('users_confirm_resend')) msg2 = _('If you did not receive the confirmation email, make ' 'sure your email service did not mark it as "junk ' 'mail" or "spam". If you need to, you can have us ' '<a href="%s">resend the confirmation message</a> ' 'to your email address.') % url messages.info(request, msg2, safe=True) return render_to_response('users/settings_email.html', { 'profile': profile, 'email': email, 'form': form, 'email_tab': True, }, context_instance=RequestContext(request))
def dashboard(request, page=1): """Personalized dashboard for authenticated users.""" try: profile = request.user.get_profile() except UserProfile.DoesNotExist: user = request.user username = '' if user.username[:10] != 'openiduser': username = user.username form = CreateProfileForm(initial={ 'full_name': ' '.join((user.first_name, user.last_name)), 'email': user.email, 'username': username, }) messages.info(request, _('Please fill out your profile to finish registration.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request)) current_projects = profile.get_current_projects() users_following = profile.following() users_followers = profile.followers() activities = Activity.objects.dashboard(request.user.get_profile()) paginator = Paginator(activities, 25) try: current_page = paginator.page(page) except EmptyPage: raise Http404 show_welcome = not profile.discard_welcome return render_to_response('dashboard/dashboard.html', { 'current_projects': current_projects, 'users_following': users_following, 'users_followers': users_followers, 'show_welcome': show_welcome, 'paginator': paginator, 'page_num': page, 'next_page': int(page) + 1, 'prev_page': int(page) - 1, 'num_pages': paginator.num_pages, 'page': current_page, 'domain': Site.objects.get_current().domain, }, context_instance=RequestContext(request))
def register(request): """Present user registration form and handle registrations.""" if REDIRECT_FIELD_NAME in request.GET: request = _clean_redirect_url(request) request.session[REDIRECT_FIELD_NAME] = request.GET[REDIRECT_FIELD_NAME] if request.method == 'POST': form = forms.RegisterForm(data=request.POST) if form.is_valid(): django_user = form.save(commit=False) user = create_profile(django_user) user.set_password(form.cleaned_data['password']) user.generate_confirmation_code() user.full_name = form.cleaned_data['full_name'] user.preflang = form.cleaned_data['preflang'] user.newsletter = form.cleaned_data['newsletter'] user.save() log.info(u"Registered new account for user (%s)", user) messages.success(request, _('Congratulations! Your user account ' 'was successfully created.')) path = reverse('users_confirm_registration', kwargs={ 'username': user.username, 'token': user.confirmation_code, }) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(user.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse('users_login')) else: messages.error(request, _('There are errors in this form. Please ' 'correct them and resubmit.')) else: form = forms.RegisterForm() return render_to_response('users/register.html', { 'form': form, }, context_instance=RequestContext(request))
def register(request): """Present user registration form and handle registrations.""" request = _process_redirect(request) if request.method == "POST": form = forms.RegisterForm(data=request.POST) if form.is_valid(): django_user = form.save(commit=False) user = create_profile(django_user) user.set_password(form.cleaned_data["password"]) user.generate_confirmation_code() user.full_name = form.cleaned_data["full_name"] user.preflang = form.cleaned_data["preflang"] user.newsletter = form.cleaned_data["newsletter"] user.save() log.info(u"Registered new account for user (%s)", user) messages.success(request, _("Congratulations! Your user account " "was successfully created.")) path = reverse( "users_confirm_registration", kwargs={"username": user.username, "token": user.confirmation_code} ) url = request.build_absolute_uri(path) user.email_confirmation_code(url) msg = _( "Thanks! We have sent an email to {0} with " "instructions for completing your " "registration." ).format(user.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse("users_login")) else: messages.error(request, _("There are errors in this form. Please " "correct them and resubmit.")) else: form = forms.RegisterForm() return render_to_response( "users/register.html", {"form": form, "domain": Site.objects.get_current().domain}, context_instance=RequestContext(request), )
def contact_followers(request, slug): user = request.user.get_profile() project = get_object_or_404(Project, slug=slug) if project.created_by != user: return http.HttpResponseForbidden() if request.method == 'POST': form = project_forms.ProjectContactUsersForm(request.POST) if form.is_valid(): form.save(sender=request.user) messages.info(request, _("Message successfully sent.")) return http.HttpResponseRedirect(reverse('projects_show', kwargs={ 'slug': project.slug, })) else: form = project_forms.ProjectContactUsersForm() form.fields['project'].initial = project.pk return render_to_response('projects/contact_users.html', { 'form': form, 'project': project, }, context_instance=RequestContext(request))
def contact_participants(request, slug): user = request.user.get_profile() project = get_object_or_404(Project, slug=slug) if project.created_by != user: return http.HttpResponseForbidden() if request.method == 'POST': form = project_forms.ProjectContactUsersForm(request.POST) if form.is_valid(): form.save(sender=request.user) messages.info(request, _("Message successfully sent.")) return http.HttpResponseRedirect(reverse('projects_show', kwargs={ 'slug': project.slug, })) else: form = project_forms.ProjectContactUsersForm() form.fields['project'].initial = project.pk return render_to_response('projects/contact_users.html', { 'form': form, 'project': project, }, context_instance=RequestContext(request))
def dashboard(request): """Personalized dashboard for authenticated users.""" try: profile = request.user.get_profile() return HttpResponseRedirect(reverse("users_profile_view", kwargs={"username": request.user.username})) except UserProfile.DoesNotExist: user = request.user username = "" if user.username[:10] != "openiduser": username = user.username form = CreateProfileForm( initial={ "full_name": " ".join((user.first_name, user.last_name)), "email": user.email, "username": username, } ) messages.info(request, _("Please fill out your profile to finish registration.")) return render_to_response( "dashboard/setup_profile.html", {"form": form}, context_instance=RequestContext(request) ) show_welcome = not profile.discard_welcome activities = Activity.objects.dashboard(request.user.get_profile()) activities = filter_activities(request, activities) context = { "profile": profile, "current_projects": current_projects, "users_following": users_following, "users_followers": users_followers, "interests": interests, "desired_topics": desired_topics, "links": links, "show_welcome": show_welcome, "domain": Site.objects.get_current().domain, "dashboard_url": reverse("dashboard"), } context.update(get_pagination_context(request, activities)) return render_to_response("dashboard/dashboard.html", context, context_instance=RequestContext(request))
def profile_create(request): if request.method != 'POST': return http.HttpResponseRedirect(reverse('dashboard_index')) try: request.user.get_profile() return http.HttpResponseRedirect(reverse('dashboard_index')) except UserProfile.DoesNotExist: pass form = forms.CreateProfileForm(request.POST) if form.is_valid(): profile = form.save(commit=False) profile.user = request.user profile.confirmation_code = profile.generate_confirmation_code() profile.save() path = reverse('users_confirm_registration', kwargs={ 'username': profile.username, 'token': profile.confirmation_code, }) url = request.build_absolute_uri(path) profile.email_confirmation_code(url) auth.logout(request) msg = _('Thanks! We have sent an email to {0} with ' 'instructions for completing your ' 'registration.').format(profile.email) messages.info(request, msg) return http.HttpResponseRedirect(reverse('dashboard_index')) else: messages.error( request, _('There are errors in this form. Please ' 'correct them and resubmit.')) return render_to_response('dashboard/setup_profile.html', { 'form': form, }, context_instance=RequestContext(request))
def badges_manage_complete(request): msg = render_to_string( 'badges/success_msg.html', dict(obi_url=settings.MOZBADGES['hub'], email=request.user.email)) messages.info(request, msg) return http.HttpResponseRedirect(reverse('users_badges_manage'))
def badges_manage_complete(request): msg = render_to_string('badges/success_msg.html', dict( obi_url=settings.MOZBADGES['hub'], email=request.user.email)) messages.info(request, msg) return http.HttpResponseRedirect(reverse('users_badges_manage'))
def edit_pages(request, slug): project = get_object_or_404(Project, slug=slug) pages = project.pages.filter(deleted=False, listed=True).order_by("index") if project.is_organizing(request.user): form_cls = OwnersPageForm else: form_cls = PageForm pages = pages.filter(collaborative=True) PageFormSet = modelformset_factory(Page, extra=0, fields=form_cls.Meta.fields, can_order=True, can_delete=True) preview = "show_preview" in request.POST edit_mode = "edit_mode" in request.POST add_page = "add_page" in request.POST save_action = not preview and not edit_mode and not add_page final_save = "final_save" in request.POST if request.method == "POST": post_data = request.POST try: total_forms_count = int(post_data["form-TOTAL_FORMS"]) except ValueError, KeyError: total_forms_count = 0 if add_page: total_forms_count += 1 post_data = post_data.copy() post_data["form-TOTAL_FORMS"] = total_forms_count formset = PageFormSet(post_data, queryset=pages) forms = formset.forms if formset.is_valid(): forms = formset.ordered_forms if save_action: profile = request.user.get_profile() current_order = list(pages.values_list("index", flat=True)) new_forms_count = total_forms_count - len(current_order) if new_forms_count > 0: try: first_available_index = project.pages.order_by("-index")[0].index + 1 except IndexError: first_available_index = 1 current_order.extend(xrange(first_available_index, first_available_index + new_forms_count + 1)) for form in forms: instance = form.save(commit=False) if save_action: instance.author = profile # FIXME: Starting with Django 1.4 it is possible to # specify initial values on model formsets so we could include # the minor_update and collaborative form fields in the future. if instance.id: old_page = Page.objects.get(id=instance.id) old_version = PageVersion( title=old_page.title, content=old_page.content, author=old_page.author, date=old_page.last_update, page=instance, ) old_version.save() instance.minor_update = True instance.last_update = datetime.datetime.now() else: instance.project = project if project.category != Project.STUDY_GROUP: instance.collaborative = False if form.cleaned_data["ORDER"]: instance.index = current_order[form.cleaned_data["ORDER"] - 1] instance.save() for form in formset.deleted_forms: instance = form.instance instance.deleted = True if save_action and instance.id: old_page = Page.objects.get(id=instance.id) old_version = PageVersion( title=old_page.title, content=old_page.content, author=old_page.author, date=old_page.last_update, page=instance, ) old_version.save() old_page.deleted = True old_page.author = profile old_page.last_update = datetime.datetime.now() old_page.save() if final_save: return http.HttpResponseRedirect(project.get_absolute_url()) elif save_action: return http.HttpResponseRedirect(reverse("edit_pages", kwargs=dict(slug=project.slug))) else: if add_page: messages.info(request, _("Please fill out the new task.")) else: messages.error(request, _("Please correct errors below.")) preview = False