Exemplo n.º 1
0
def user_email_subscriptions(request, user, context):

    logging.debug(get_request_info(request))
    if request.method == 'POST':
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _('changes saved')
            if 'save' in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _('changes saved')
            elif 'stop_email' in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _('email updates canceled')
    else:
        #user may have been created by some app that does not know
        #about the email subscriptions, in that case the call below
        #will add any subscription settings that are missing
        #using the default frequencies
        user.add_missing_askbot_subscriptions()

        #initialize the form
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        'active_tab': 'users',
        'subscribed_tag_names': user.get_marked_tag_names('subscribed'),
        'page_class': 'user-profile-page',
        'tab_name': 'email_subscriptions',
        'page_title': _('profile - email subscriptions'),
        'email_feeds_form': email_feeds_form,
        'tag_filter_selection_form': tag_filter_form,
        'action_status': action_status,
        'user_languages': user.languages.split()
    }
    context.update(data)
    #todo: really need only if subscribed tags are enabled
    context.update(view_context.get_for_tag_editor())
    return render(
        request,
        'user_profile/user_email_subscriptions.html',
        context
    )
Exemplo n.º 2
0
def user_email_subscriptions(request, user, context):

    logging.debug(get_request_info(request))
    if request.method == 'POST':
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _('changes saved')
            if 'save' in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _('changes saved')
            elif 'stop_email' in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _('email updates canceled')
    else:
        #user may have been created by some app that does not know
        #about the email subscriptions, in that case the call below
        #will add any subscription settings that are missing
        #using the default frequencies
        user.add_missing_askbot_subscriptions()

        #initialize the form
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        'active_tab': 'users',
        'subscribed_tag_names': user.get_marked_tag_names('subscribed'),
        'page_class': 'user-profile-page',
        'tab_name': 'email_subscriptions',
        'page_title': _('profile - email subscriptions'),
        'email_feeds_form': email_feeds_form,
        'tag_filter_selection_form': tag_filter_form,
        'action_status': action_status,
        'user_languages': user.languages.split()
    }
    context.update(data)
    #todo: really need only if subscribed tags are enabled
    context.update(view_context.get_for_tag_editor())
    return render(
        request,
        'user_profile/user_email_subscriptions.html',
        context
    )
Exemplo n.º 3
0
def user_email_subscriptions(request, user, context):

    logging.debug(get_request_info(request))
    if request.method == "POST":
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _("changes saved")
            if "save" in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _("changes saved")
            elif "stop_email" in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _("email updates canceled")
    else:
        # user may have been created by some app that does not know
        # about the email subscriptions, in that case the call below
        # will add any subscription settings that are missing
        # using the default frequencies
        user.add_missing_askbot_subscriptions()

        # initialize the form
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        "active_tab": "users",
        "subscribed_tag_names": user.get_marked_tag_names("subscribed"),
        "page_class": "user-profile-page",
        "tab_name": "email_subscriptions",
        "tab_description": _("email subscription settings"),
        "page_title": _("profile - email subscriptions"),
        "email_feeds_form": email_feeds_form,
        "tag_filter_selection_form": tag_filter_form,
        "action_status": action_status,
        "user_languages": user.languages.split(),
    }
    context.update(data)
    return render(request, "user_profile/user_email_subscriptions.html", context)
Exemplo n.º 4
0
def user_email_subscriptions(request, user):

    logging.debug(get_request_info(request))
    if request.method == 'POST':
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _('changes saved')
            if 'save' in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _('changes saved')
            elif 'stop_email' in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _('email updates canceled')
    else:
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-page',
        'tab_name': 'email_subscriptions',
        'tab_description': _('email subscription settings'),
        'page_title': _('profile - email subscriptions'),
        'view_user': user,
        'email_feeds_form': email_feeds_form,
        'tag_filter_selection_form': tag_filter_form,
        'action_status': action_status,
    }
    return render_into_skin(
        'user_profile/user_email_subscriptions.html',
        data,
        request
    )
Exemplo n.º 5
0
def user_email_subscriptions(request, user):

    logging.debug(get_request_info(request))
    if request.method == 'POST':
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _('changes saved')
            if 'save' in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _('changes saved')
            elif 'stop_email' in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _('email updates canceled')
    else:
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        'active_tab': 'users',
        'page_class': 'user-profile-page',
        'tab_name': 'email_subscriptions',
        'tab_description': _('email subscription settings'),
        'page_title': _('profile - email subscriptions'),
        'view_user': user,
        'email_feeds_form': email_feeds_form,
        'tag_filter_selection_form': tag_filter_form,
        'action_status': action_status,
    }
    return render_into_skin(
        'user_profile/user_email_subscriptions.html',
        data,
        request
    )
Exemplo n.º 6
0
def user_email_subscriptions(request, user):

    logging.debug(get_request_info(request))
    if request.method == "POST":
        email_feeds_form = forms.EditUserEmailFeedsForm(request.POST)
        tag_filter_form = forms.TagFilterSelectionForm(request.POST, instance=user)
        if email_feeds_form.is_valid() and tag_filter_form.is_valid():

            action_status = None
            tag_filter_saved = tag_filter_form.save()
            if tag_filter_saved:
                action_status = _("changes saved")
            if "save" in request.POST:
                feeds_saved = email_feeds_form.save(user)
                if feeds_saved:
                    action_status = _("changes saved")
            elif "stop_email" in request.POST:
                email_stopped = email_feeds_form.reset().save(user)
                initial_values = forms.EditUserEmailFeedsForm.NO_EMAIL_INITIAL
                email_feeds_form = forms.EditUserEmailFeedsForm(initial=initial_values)
                if email_stopped:
                    action_status = _("email updates canceled")
    else:
        email_feeds_form = forms.EditUserEmailFeedsForm()
        email_feeds_form.set_initial_values(user)
        tag_filter_form = forms.TagFilterSelectionForm(instance=user)
        action_status = None

    data = {
        "active_tab": "users",
        "page_class": "user-profile-page",
        "tab_name": "email_subscriptions",
        "tab_description": _("email subscription settings"),
        "page_title": _("profile - email subscriptions"),
        "view_user": user,
        "email_feeds_form": email_feeds_form,
        "tag_filter_selection_form": tag_filter_form,
        "action_status": action_status,
    }
    return render_into_skin("user_profile/user_email_subscriptions.html", data, request)
Exemplo n.º 7
0
def signup_with_password(request):
    """Create a password-protected account
    template: authopenid/signup_with_password.html
    """

    logging.debug(get_request_info(request))
    next = get_next_url(request)
    login_form = forms.LoginForm(initial={'next': next})
    #this is safe because second decorator cleans this field
    provider_name = request.REQUEST['login_provider']

    if askbot_settings.USE_RECAPTCHA:
        RegisterForm = forms.SafeClassicRegisterForm
    else:
        RegisterForm = forms.ClassicRegisterForm

    logging.debug('request method was %s' % request.method)
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm(request.POST)

        #validation outside if to remember form values
        logging.debug('validating classic register form')
        form1_is_valid = form.is_valid()
        if form1_is_valid:
            logging.debug('classic register form validated')
        else:
            logging.debug('classic register form is not valid')
        form2_is_valid = email_feeds_form.is_valid()
        if form2_is_valid:
            logging.debug('email feeds form validated')
        else:
            logging.debug('email feeds form is not valid')
        if form1_is_valid and form2_is_valid:
            logging.debug('both forms are valid')
            next = form.cleaned_data['next']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            provider_name = form.cleaned_data['login_provider']

            User.objects.create_user(username, email, password)
            logging.debug('new user %s created' % username)
            if provider_name != 'local':
                raise NotImplementedError('must run create external user code')

            user = authenticate(username=username,
                                password=password,
                                provider_name=provider_name,
                                method='password')

            login(request, user)
            logging.debug('new user logged in')
            email_feeds_form.save(user)
            logging.debug('email feeds form saved')

            # send email
            #subject = _("Welcome email subject line")
            #message_template = get_emplate(
            #        'authopenid/confirm_email.txt'
            #)
            #message_context = Context({
            #    'signup_url': askbot_settings.APP_URL + reverse('user_signin'),
            #    'username': username,
            #    'password': password,
            #})
            #message = message_template.render(message_context)
            #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
            #        [user.email])
            #logging.debug('new password acct created, confirmation email sent!')
            return HttpResponseRedirect(next)
        else:
            #todo: this can be solved with a decorator, maybe
            form.initial['login_provider'] = provider_name
            logging.debug('create classic account forms were invalid')
    else:
        #todo: here we have duplication of get_password_login_provider...
        form = RegisterForm(initial={
            'next': next,
            'login_provider': provider_name
        })
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm()
    logging.debug('printing legacy signup form')

    major_login_providers = util.get_major_login_providers()
    minor_login_providers = util.get_minor_login_providers()
    context_data = {
        'form': form,
        'page_class': 'openid-signin',
        'email_feeds_form': email_feeds_form,
        'major_login_providers': major_login_providers.values(),
        'minor_login_providers': minor_login_providers.values(),
        'login_form': login_form
    }
    return render_into_skin('authopenid/signup_with_password.html',
                            context_data, request)
Exemplo n.º 8
0
def signup_with_password(request):
    """Create a password-protected account
    template: authopenid/signup_with_password.html
    """
    
    logging.debug(get_request_info(request))
    next = get_next_url(request)
    login_form = forms.LoginForm(initial = {'next': next})
    #this is safe because second decorator cleans this field
    provider_name = request.REQUEST['login_provider']

    if askbot_settings.USE_RECAPTCHA:
        RegisterForm = forms.SafeClassicRegisterForm
    else:
        RegisterForm = forms.ClassicRegisterForm

    logging.debug('request method was %s' % request.method)
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm(request.POST)
        
        #validation outside if to remember form values
        logging.debug('validating classic register form')
        form1_is_valid = form.is_valid()
        if form1_is_valid:
            logging.debug('classic register form validated')
        else:
            logging.debug('classic register form is not valid')
        form2_is_valid = email_feeds_form.is_valid()
        if form2_is_valid:
            logging.debug('email feeds form validated')
        else:
            logging.debug('email feeds form is not valid')
        if form1_is_valid and form2_is_valid:
            logging.debug('both forms are valid')
            next = form.cleaned_data['next']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            provider_name = form.cleaned_data['login_provider']
            
            User.objects.create_user(username, email, password)
            logging.debug('new user %s created' % username)
            if provider_name != 'local':
                raise NotImplementedError('must run create external user code')

            user = authenticate(
                        username = username,
                        password = password,
                        provider_name = provider_name,
                        method = 'password'
                    )

            login(request, user)
            logging.debug('new user logged in')
            email_feeds_form.save(user)
            logging.debug('email feeds form saved')
            
            # send email
            #subject = _("Welcome email subject line")
            #message_template = get_emplate(
            #        'authopenid/confirm_email.txt'
            #)
            #message_context = Context({ 
            #    'signup_url': askbot_settings.APP_URL + reverse('user_signin'),
            #    'username': username,
            #    'password': password,
            #})
            #message = message_template.render(message_context)
            #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, 
            #        [user.email])
            #logging.debug('new password acct created, confirmation email sent!')
            return HttpResponseRedirect(next)
        else:
            #todo: this can be solved with a decorator, maybe
            form.initial['login_provider'] = provider_name
            logging.debug('create classic account forms were invalid')
    else:
        #todo: here we have duplication of get_password_login_provider...
        form = RegisterForm(
                        initial={
                            'next':next,
                            'login_provider': provider_name
                        }
                    )
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm()
    logging.debug('printing legacy signup form')

    major_login_providers = util.get_enabled_major_login_providers()
    minor_login_providers = util.get_enabled_minor_login_providers()

    context_data = {
                'form': form, 
                'page_class': 'openid-signin',
                'email_feeds_form': email_feeds_form,
                'major_login_providers': major_login_providers.values(),
                'minor_login_providers': minor_login_providers.values(),
                'login_form': login_form
            }
    return render_into_skin(
                'authopenid/signup_with_password.html',
                context_data,
                request
            )
Exemplo n.º 9
0
def signup_with_password(request):
    """Create a password-protected account
    template: authopenid/signup_with_password.html
    """

    logging.debug(get_request_info(request))
    login_form = forms.LoginForm(initial={'next': get_next_url(request)})
    #this is safe because second decorator cleans this field
    provider_name = request.REQUEST['login_provider']

    if askbot_settings.USE_RECAPTCHA:
        RegisterForm = forms.SafeClassicRegisterForm
    else:
        RegisterForm = forms.ClassicRegisterForm

    logging.debug('request method was %s' % request.method)
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm(request.POST)

        #validation outside if to remember form values
        logging.debug('validating classic register form')
        form1_is_valid = form.is_valid()
        if form1_is_valid:
            logging.debug('classic register form validated')
        else:
            logging.debug('classic register form is not valid')
        form2_is_valid = email_feeds_form.is_valid()
        if form2_is_valid:
            logging.debug('email feeds form validated')
        else:
            logging.debug('email feeds form is not valid')
        if form1_is_valid and form2_is_valid:
            logging.debug('both forms are valid')
            next = form.cleaned_data['next']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            subscribe = email_feeds_form.cleaned_data['subscribe']

            if askbot_settings.REQUIRE_VALID_EMAIL_FOR == 'nothing':
                user = create_authenticated_user_account(username=username,
                                                         email=email,
                                                         password=password,
                                                         subscribe=subscribe)
                login(request, user)
                cleanup_post_register_session(request)
                return HttpResponseRedirect(get_next_url(request))
            else:
                request.session['username'] = username
                request.session['email'] = email
                request.session['password'] = password
                request.session['subscribe'] = subscribe
                #todo: generate a key and save it in the session
                key = util.generate_random_key()
                email = request.session['email']
                send_email_key(email,
                               key,
                               handler_url_name='verify_email_and_register')
                request.session['validation_code'] = key
                redirect_url = reverse('verify_email_and_register') + \
                                '?next=' + get_next_url(request)
                return HttpResponseRedirect(redirect_url)

        else:
            #todo: this can be solved with a decorator, maybe
            form.initial['login_provider'] = provider_name
            logging.debug('create classic account forms were invalid')
    else:
        #todo: here we have duplication of get_password_login_provider...
        form = RegisterForm(initial={
            'next': get_next_url(request),
            'login_provider': provider_name
        })
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm()
    logging.debug('printing legacy signup form')

    major_login_providers = util.get_enabled_major_login_providers()
    minor_login_providers = util.get_enabled_minor_login_providers()

    context_data = {
        'form': form,
        'page_class': 'openid-signin',
        'email_feeds_form': email_feeds_form,
        'major_login_providers': major_login_providers.values(),
        'minor_login_providers': minor_login_providers.values(),
        'login_form': login_form
    }
    return render_into_skin('authopenid/signup_with_password.html',
                            context_data, request)
Exemplo n.º 10
0
def signup_with_password(request):
    """Create a password-protected account
    template: authopenid/signup_with_password.html
    """
    logging.debug(get_request_info(request))
    next = get_next_url(request)
    # this is safe because second decorator cleans this field
    provider_name = request.REQUEST["login_provider"]

    if askbot_settings.USE_RECAPTCHA:
        RegisterForm = forms.SafeClassicRegisterForm
    else:
        RegisterForm = forms.ClassicRegisterForm

    logging.debug("request method was %s" % request.method)
    if request.method == "POST":
        form = RegisterForm(request.POST)
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm(request.POST)

        # validation outside if to remember form values
        logging.debug("validating classic register form")
        form1_is_valid = form.is_valid()
        if form1_is_valid:
            logging.debug("classic register form validated")
        else:
            logging.debug("classic register form is not valid")
        form2_is_valid = email_feeds_form.is_valid()
        if form2_is_valid:
            logging.debug("email feeds form validated")
        else:
            logging.debug("email feeds form is not valid")
        if form1_is_valid and form2_is_valid:
            logging.debug("both forms are valid")
            next = form.cleaned_data["next"]
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]
            email = form.cleaned_data["email"]
            provider_name = form.cleaned_data["login_provider"]

            User.objects.create_user(username, email, password)
            logging.debug("new user %s created" % username)
            if provider_name != "local":
                raise NotImplementedError("must run create external user code")

            user = authenticate(username=username, password=password, provider_name=provider_name, method="password")

            login(request, user)
            logging.debug("new user logged in")
            email_feeds_form.save(user)
            logging.debug("email feeds form saved")

            # send email
            # subject = _("Welcome email subject line")
            # message_template = ENV.get_template(
            #        'authopenid/confirm_email.txt'
            # )
            # message_context = Context({
            #    'signup_url': askbot_settings.APP_URL + reverse('user_signin'),
            #    'username': username,
            #    'password': password,
            # })
            # message = message_template.render(message_context)
            # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
            #        [user.email])
            # logging.debug('new password acct created, confirmation email sent!')
            return HttpResponseRedirect(next)
        else:
            # todo: this can be solved with a decorator, maybe
            form.initial["login_provider"] = provider_name
            logging.debug("create classic account forms were invalid")
    else:
        # todo: here we have duplication of get_password_login_provider...
        form = RegisterForm(initial={"next": next, "login_provider": provider_name})
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm()
    logging.debug("printing legacy signup form")
    context_data = {"form": form, "email_feeds_form": email_feeds_form}
    template = ENV.get_template("authopenid/signup_with_password.html")
    context = RequestContext(request, context_data)
    return HttpResponse(template.render(context))
Exemplo n.º 11
0
def signup_with_password(request):
    """Create a password-protected account
    template: authopenid/signup_with_password.html
    """
    
    logging.debug(get_request_info(request))
    next = get_next_url(request)
    login_form = forms.LoginForm(initial = {'next': next})
    #this is safe because second decorator cleans this field
    provider_name = request.REQUEST['login_provider']

    if askbot_settings.USE_RECAPTCHA:
        RegisterForm = forms.SafeClassicRegisterForm
    else:
        RegisterForm = forms.ClassicRegisterForm

    logging.debug('request method was %s' % request.method)
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm(request.POST)
        
        #validation outside if to remember form values
        logging.debug('validating classic register form')
        form1_is_valid = form.is_valid()
        if form1_is_valid:
            logging.debug('classic register form validated')
        else:
            logging.debug('classic register form is not valid')
        form2_is_valid = email_feeds_form.is_valid()
        if form2_is_valid:
            logging.debug('email feeds form validated')
        else:
            logging.debug('email feeds form is not valid')
        if form1_is_valid and form2_is_valid:
            logging.debug('both forms are valid')
            next = form.cleaned_data['next']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']
            subscribe = email_feeds_form.cleaned_data['subscribe']

            if askbot_settings.REQUIRE_VALID_EMAIL_FOR == 'nothing':
                user = create_authenticated_user_account(
                    username=username,
                    email=email,
                    password=password,
                    subscribe=subscribe
                )
                login(request, user)
                cleanup_post_register_session(request)
                return HttpResponseRedirect(next)
            else:
                request.session['username'] = username
                request.session['email'] = email
                request.session['password'] = password
                request.session['subscribe'] = subscribe
                #todo: generate a key and save it in the session
                key = util.generate_random_key()
                email = request.session['email']
                send_email_key(email, key, handler_url_name='verify_email_and_register')
                request.session['validation_code'] = key
                return HttpResponseRedirect(reverse('verify_email_and_register'))

        else:
            #todo: this can be solved with a decorator, maybe
            form.initial['login_provider'] = provider_name
            logging.debug('create classic account forms were invalid')
    else:
        #todo: here we have duplication of get_password_login_provider...
        form = RegisterForm(
                        initial={
                            'next':next,
                            'login_provider': provider_name
                        }
                    )
        email_feeds_form = askbot_forms.SimpleEmailSubscribeForm()
    logging.debug('printing legacy signup form')

    major_login_providers = util.get_enabled_major_login_providers()
    minor_login_providers = util.get_enabled_minor_login_providers()

    context_data = {
                'form': form, 
                'page_class': 'openid-signin',
                'email_feeds_form': email_feeds_form,
                'major_login_providers': major_login_providers.values(),
                'minor_login_providers': minor_login_providers.values(),
                'login_form': login_form
            }
    return render_into_skin(
                'authopenid/signup_with_password.html',
                context_data,
                request
            )
Exemplo n.º 12
0
def signup_with_password(request):
    """Create a password-protected account
    template: authopenid/signup_with_password.html
    """

    logging.debug(get_request_info(request))
    login_form = forms.LoginForm(initial={"next": get_next_url(request)})
    # this is safe because second decorator cleans this field
    provider_name = request.REQUEST["login_provider"]

    if askbot_settings.USE_RECAPTCHA:
        RegisterForm = forms.SafeClassicRegisterForm
    else:
        RegisterForm = forms.ClassicRegisterForm

    logging.debug("request method was %s" % request.method)
    if request.method == "POST":
        form = RegisterForm(request.POST)

        # validation outside if to remember form values
        logging.debug("validating classic register form")
        form1_is_valid = form.is_valid()
        if form1_is_valid:
            logging.debug("classic register form validated")
        else:
            logging.debug("classic register form is not valid")

        if form1_is_valid:
            logging.debug("both forms are valid")
            next = form.cleaned_data["next"]
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]
            email = form.cleaned_data["email"]

            if askbot_settings.REQUIRE_VALID_EMAIL_FOR == "nothing":
                user = create_authenticated_user_account(username=username, email=email, password=password)
                login(request, user)
                cleanup_post_register_session(request)
                return HttpResponseRedirect(get_next_url(request))
            else:
                email_verifier = UserEmailVerifier(key=generate_random_key())
                email_verifier.value = {
                    "username": username,
                    "login_provider_name": provider_name,
                    "email": email,
                    "password": password,
                }
                email_verifier.save()
                send_email_key(email, email_verifier.key, handler_url_name="verify_email_and_register")
                redirect_url = reverse("verify_email_and_register") + "?next=" + get_next_url(request)
                return HttpResponseRedirect(redirect_url)

        else:
            # todo: this can be solved with a decorator, maybe
            form.initial["login_provider"] = provider_name
            logging.debug("create classic account forms were invalid")
    else:
        # todo: here we have duplication of get_password_login_provider...
        form = RegisterForm(initial={"next": get_next_url(request), "login_provider": provider_name})
    logging.debug("printing legacy signup form")

    major_login_providers = util.get_enabled_major_login_providers()
    minor_login_providers = util.get_enabled_minor_login_providers()

    context_data = {
        "form": form,
        "page_class": "openid-signin",
        "major_login_providers": major_login_providers.values(),
        "minor_login_providers": minor_login_providers.values(),
        "login_form": login_form,
    }
    return render(request, "authopenid/signup_with_password.html", context_data)