コード例 #1
0
ファイル: registration.py プロジェクト: fason/stigmergy
def validate_registration(request):
    """validate registration data"""
    # step1 - email and password and captcha
    if email_errors(request):
        return email_errors(request, return_values = 3)

    # Password is generated by us

    # Captcha
    if not (settings.DEBUG and request.POST.get("ignorecaptcha", False)):
        if not captcha_valid(request, "register"):
            return (__('Captcha'), '1', __('Captcha challenge failed'))
        invalidate_captcha(request, "register")

    # step2 - languages
    if language_errors(request):
        return language_errors(request, return_values = 3)

    # step3 - location
    if location_errors(request):
        return location_errors(request, return_values = 3)

    # step4 - about me
    if contactinfo_errors(request):
        return contactinfo_errors(request, return_values = 3)
    if aboutme_errors(request):
        return aboutme_errors(request, return_values = 3)

    return (None, None, None)
コード例 #2
0
ファイル: views.py プロジェクト: fason/stigmergy
def edit(request, clicked):
    """edit profile"""
    if not valid_token(request):
        return token_splash_page(request)

    template_vars = {}
    if request.method == "POST":
        loginphrase = request.POST.get("password","")
        password = get_password_from_loginphrase(loginphrase)
        if request.user.check_password(password):
            if edit_captcha_ok(request):
                validation_errors =  contactinfo_errors(request) or \
                                     aboutme_errors(request) or \
                                     location_errors(request) or \
                                     language_errors(request) or \
                                     email_errors(request) or None
                if validation_errors:
                    validation_errors = ([contactinfo_errors(request)] + \
                                         [aboutme_errors(request)] + \
                                         [location_errors(request)] + \
                                         [language_errors(request)] + \
                                         [email_errors(request)])
                    for val_error in validation_errors:
                        if val_error is not None:
                            template_vars[val_error[-1]] = val_error[2]
                else:
                    save_edited_info(request)
                    # Get the newly encrypted data into the session again
                    populate_session(request, password)
                    return HttpResponseRedirect(
                        reverse('user.views.profile_forwarding')
                    )
            else:
                template_vars["captchaerror"] = True
                template_vars["captcha"] = CaptchaTestForm(request.POST)
        else:
            template_vars["passworderror"] = __("Wrong passphrase.")
    else:
        if edit_needs_captcha(request):
            template_vars["captcha"] = CaptchaTestForm()
            
    template_vars['contact_info'] = request.POST.get("contact_info", False)
    template_vars['about_me'] = request.POST.get("about_me", False)
    template_vars['email'] = request.POST.get("email", False)
    template_vars['user'] = request.user
    profile_ = request.user.get_profile()
    restore_profile_from_session(request, profile_)
    template_vars['profile'] = profile_

    for num, lang in enumerate(profile_.get_langs_spoken()):
        template_vars['lang_'+str(num)] = \
            request.POST.get("lang_" + str(num), lang)

    template_vars['use_maps_single'] = True
    template_vars['cityDict'] = {
        'latitude' : request.POST.get("latitude", profile_.latitude),
        'longitude' : request.POST.get("longitude", profile_.longitude),
    }
    template_vars["clicked"] = clicked
    template_vars['title'] = __('Edit the information about you')
    template_path = "user/edit_profile.html"

    return render_to_response(template_path, template_vars,
                              context_instance=RequestContext(request))