Beispiel #1
0
    def post(request):
        """
        static method for post
        """

        if 'submitLogin' in request.POST:

            form = LoginForm(request.POST)

            if form.is_valid():
                username = form.cleaned_data['username'].encode('ascii', 'ignore')
                password = form.cleaned_data['password'].encode('ascii', 'ignore')

                user = Authentification.isValidUser(username, password)

                # checks if user exists
                if user is not None:
                    request.session['active_User'] = user

                    # sets the session expiration in seconds
                    request.session.set_expiry(60*60*24*7)  # sets session to 7 days

                    return HttpResponseRedirect('/feedreader/')

                # user does not exists
                else:
                    #return HttpResponseRedirect('/feedreader/')
                    frmLogin = LoginForm()
                    error = "Incorrect username or password"
                    return render_to_response('index.html', {'login': frmLogin, 'user': '******', 'error': error},
                                          context_instance=RequestContext(request))

            # invalid form
            else:
                frmLogin = LoginForm()
                error = "You have entered invalid data. Please try again."
                return render_to_response('index.html', {'login': frmLogin, 'user': '******', 'error': error},
                                          context_instance=RequestContext(request))

        elif 'submitSearch' in request.POST:
            searchValue = request.POST['submitSearch']
            values = searchValue.replace(' ', '+')

            return HttpResponseRedirect('/feedreader/search/?keywords=' + values)

        else:
            return HttpResponseRedirect('/feedreader/')
Beispiel #2
0
    def post(request):
        """
        static method for post
        """

        form = RegistrationForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username'].encode('ascii', 'ignore')
            password = form.cleaned_data['password'].encode('ascii', 'ignore')
            email = form.cleaned_data['email'].encode('ascii', 'ignore')

            if Authentification.userExists(username):
                errorMessage = "Username already exists. Please correct these fields and resubmit the form."
                error = "<div class='alert alert-error'><strong>%s</strong></div>" % errorMessage
                error = mark_safe(error)
                return render_to_response('register.html', {'registration': form, 'error': error},
                                          context_instance=RequestContext(request))

            user = User.objects.create_user(username, email, password)

            # checks if user exists
            if user is not None:
                request.session['active_User'] = user

                # sets the session expiration in seconds
                request.session.set_expiry(600)
                return HttpResponseRedirect('/feedreader/')

        else:
            errorMessage = "One or more required fields were not filled in correctly. " \
                        "Please correct these fields and resubmit the form."

            error = "<div class='alert alert-error'><strong>%s</strong></div>" % errorMessage
            error = mark_safe(error)
            return render_to_response('register.html', {'registration': form, 'error': error},
                                      context_instance=RequestContext(request))