Exemple #1
0
def submit_talk(request, scope, template_name='talk/submit-talk.html'):
    """Allows user to edit profile
    """

    scope_entity = Event.objects.get(scope=scope)

    user = request.user
    if user.is_authenticated():
        try:
            profile = user.get_profile()
        except:
            profile, new = UserProfile.objects.get_or_create(
                user=user, scope=scope_entity)
            if new:
                profile.save()

    message = None

    if request.method == 'POST':
        talk_form = TalkSubmitForm(data=request.POST)

        register_form = RegisterForm(data=request.POST, files=request.FILES)

        if request.POST.get('action', None) == 'login':
            login_form = AuthenticationForm(data=request.POST)
            if login_form.is_valid():

                from django.contrib.auth import login
                login(request, login_form.get_user())

                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                                          msg=u'You have been logged in.')

        if request.POST.get('action', None) == 'register':
            # add the new user
            if register_form.is_valid():

                user = scipycon_createuser(request, register_form.data)

        if talk_form.is_valid():
            if user.is_authenticated():
                title = talk_form.data.get('title')
                talk = Talk.objects.create(
                    slug=slugify(title),
                    scope=scope_entity,
                    speaker=User.objects.get(pk=user.id),
                    authors_bio=talk_form.data.get('authors_bio'),
                    contact=talk_form.data.get('contact'),
                    title=talk_form.data.get('title'),
                    abstract=talk_form.data.get('abstract'),
                    topic=talk_form.data.get('topic'),
                    duration=talk_form.data.get('duration'),
                    audience=talk_form.data.get('audience'),
                    approved=False,
                    #                    tags = talk_form.data.get('tags')
                )
                talk.save()
                # Saved, ... redirect back to account
                redirect_to = reverse('scipycon_edit_talk',
                                      kwargs={
                                          'scope': scope,
                                          'id': talk.id
                                      })
                return set_message_cookie(
                    redirect_to, msg=u'Thanks, your talk has been submitted.')
            else:
                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                                          msg=u'Something is wrong here.')

    else:
        talk_form = TalkSubmitForm()
        register_form = RegisterForm()
    login_form = AuthenticationForm()

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'params': {
                    'scope': scope
                },
                'talk_form': talk_form,
                'register_form': register_form,
                'message': message,
                'login_form': login_form
            }))
Exemple #2
0
def submit_talk(request, scope, template_name='talk/submit-talk.html'):
    """Allows user to edit profile
    """

    scope_entity = Event.objects.get(scope=scope)

    user = request.user
    if user.is_authenticated():
        try:
            profile = user.get_profile()
        except:
            profile, new = UserProfile.objects.get_or_create(
                user=user, scope=scope_entity)
            if new:
                profile.save()

    message = None

    if request.method == 'POST':
        talk_form = TalkSubmitForm(data=request.POST)

        register_form = RegisterForm(data=request.POST, files=request.FILES)

        if request.POST.get('action', None) == 'login':
            login_form = AuthenticationForm(data=request.POST)
            if login_form.is_valid():

                from django.contrib.auth import login
                login(request, login_form.get_user())

                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                        msg = u'You have been logged in.')

        if request.POST.get('action', None) == 'register':
            # add the new user
            if register_form.is_valid():

                user = scipycon_createuser(request, register_form.data)

        if talk_form.is_valid():
            if user.is_authenticated():
                title = talk_form.data.get('title')
                talk = Talk.objects.create(
                    slug = slugify(title),
                    scope = scope_entity,
                    speaker = User.objects.get(pk=user.id),
                    authors_bio = talk_form.data.get('authors_bio'),
                    contact = talk_form.data.get('contact'),
                    title = talk_form.data.get('title'),
                    abstract = talk_form.data.get('abstract'),
                    topic = talk_form.data.get('topic'),
                    duration = talk_form.data.get('duration'),
                    audience = talk_form.data.get('audience'),
                    approved = False,
#                    tags = talk_form.data.get('tags')
                    )
                talk.save()
                # Saved, ... redirect back to account
                redirect_to = reverse('scipycon_edit_talk', 
                                      kwargs={'scope': scope, 'id': talk.id})
                return set_message_cookie(redirect_to,
                        msg = u'Thanks, your talk has been submitted.')
            else:
                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                        msg = u'Something is wrong here.')

    else:
        talk_form = TalkSubmitForm()
        register_form = RegisterForm()
    login_form = AuthenticationForm()


    return render_to_response(template_name, RequestContext(request, {
        'params': {'scope': scope},
        'talk_form': talk_form,
        'register_form' : register_form,
        'message' : message,
        'login_form' : login_form
    }))
Exemple #3
0
def login(request, scope, template_name="user/login.html"):
    """Custom view to login or register/login a user.
       Integration of register and login form
       It uses Django's standard AuthenticationForm, though.
    """

    user = request.user
    if user.is_authenticated():
        redirect_to = reverse("scipycon_account", kwargs={'scope': scope})
        return set_message_cookie(redirect_to,
                msg = u"Redirected to account from login form.")

    # Using Djangos default AuthenticationForm
    login_form = AuthenticationForm()
    register_form = RegisterForm()

    if request.POST.get("action") == "login":
        login_form = AuthenticationForm(data=request.POST)

        if login_form.is_valid():
            redirect_to = request.POST.get("next")
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = reverse('scipycon_account',
                                      kwargs={'scope': scope})

            from django.contrib.auth import login
            login(request, login_form.get_user())

            return set_message_cookie(redirect_to, msg = u"You have been logged in.")

    elif request.POST.get("action") == "register":
        register_form = RegisterForm(data=request.POST)
        if register_form.is_valid():

            user = scipycon_createuser(request, register_form.data, scope)

            redirect_to = request.POST.get("next")
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = reverse('scipycon_account',
                                      kwargs={'scope': scope})

            return set_message_cookie(
                redirect_to, msg = u"You have been registered and logged in.")

    # Get next_url
    next_url = request.REQUEST.get("next")
    if next_url is None:
        next_url = request.META.get("HTTP_REFERER")
    if next_url is None:
        next_url = reverse('scipycon_account', kwargs={'scope': scope})

    # Get just the path of the url.
    # See django.contrib.auth.views.login for more
    next_url = urlparse(next_url)
    next_url = next_url[2]

    try:
        login_form_errors = login_form.errors["__all__"]
    except KeyError:
        login_form_errors = None

    return render_to_response(template_name, RequestContext(request, {
        'params': {'scope': scope},
        'login_form' : login_form,
        'login_form_errors' : login_form_errors,
        'register_form' : register_form,
        'next_url' : next_url,
    }))