Esempio n. 1
0
def login_view(request):
    if request.method == "POST":
        form = AuthenticateForm(data=request.POST)
        if form.is_valid():
            login(request, form.get_user())
            #Success
            return redirect('/')
Esempio n. 2
0
def login_view(request):
	if request.method == 'POST':
		form = AuthenticateForm(data=request.POST)
		if form.is_valid():
			login(request, form.get_user())
			return redirect('/')
		else:
			return index(request, auth_form=form)
Esempio n. 3
0
def login_view(request): #logs the user in
    if request.method == 'POST': # expects a HTTP POST request for the login (since the form's method is POST)
        form = AuthenticateForm(data=request.POST)
        if form.is_valid(): #If form validation is successful, login the user using the login() method which starts the session and then redirects to the root url.
            login(request, form.get_user())
            # Success
            return redirect('/')
        else:
            # Failure
            return index(request, auth_form=form) #pass the instance of the auth_form received from the user to the index function and list the errors
    return redirect('/') #if the request isn't POST then the user is redirected to the root url
Esempio n. 4
0
def login_view(request):
    if request.method == 'POST':
        form = AuthenticateForm(data=request.POST)
        if form.is_valid():
            login(request, form.get_user())
            # Success
            return redirect('/')
        else:
            # Failure
            return index(request, auth_form=form)
    return redirect('/')
Esempio n. 5
0
def index(request, auth_form=None, user_form=None):
    # User is logged in
    if request.user.is_authenticated():
        ribbit_form = RibbitForm()
        user = request.user
        ribbits_self = Ribbit.objects.filter(user=user.id)
        ribbits_buddies = Ribbit.objects.filter(
            user__userprofile__in=user.profile.follows.all)
        ribbits = ribbits_self | ribbits_buddies

        return render(
            request, 'buddies.html', {
                'ribbit_form': ribbit_form,
                'user': user,
                'ribbits': ribbits,
                'next_url': '/',
            })
    else:
        # User is not logged in
        auth_form = auth_form or AuthenticateForm()
        user_form = user_form or UserCreateForm()

        return render(request, 'home.html', {
            'auth_form': auth_form,
            'user_form': user_form,
        })
Esempio n. 6
0
def index(request, auth_form=None, user_form=None):
    # User is logged in
    if request.user.is_authenticated():
        bookPasser_form = bookPasserForm()
        user = request.user
        bookPassers_self = bookPasser.objects.filter(user=user.id)
        bookPassers_buddies = bookPasser.objects.filter(
            user__userprofile__in=user.profile.follows.all)
        bookPassers = bookPassers_self | bookPassers_buddies

        return render(
            request, 'buddies.html', {
                'bookPasser_form': bookPasser_form,
                'user': user,
                'bookPassers': bookPassers,
                'next_url': '/',
            })
    else:
        # User is not logged in
        auth_form = auth_form or AuthenticateForm()
        user_form = user_form or UserCreateForm()

        return render(request, 'home.html', {
            'auth_form': auth_form,
            'user_form': user_form,
        })

    bookpasser.objects.all().delete()
Esempio n. 7
0
def index(request, auth_form=None, user_form=None):
    #User is logged in
    context = RequestContext(request)
    context_dict = {}
    if request.user.is_authenticated():
        ribbit_form = RibbitForm()
        user = request.user
        ribbits_self = Ribbit.objects.filter(user=user.id)
        ribbits_buddies = Ribbit.objects.filter(
            user__userprofile__in=user.profile.follows.all)
        ribbits = ribbits_self | ribbits_buddies
        context_dict['ribbit_form'] = ribbit_form
        context_dict['user'] = user
        context_dict['ribbits'] = ribbits
        context_dict['next_url'] = '/'

        return render(request, 'buddies.html', context_dict)

    else:
        #User is not logged in
        auth_form = auth_form or AuthenticateForm()
        user_form = user_form or UserCreateForm()

        return render(request, 'home.html', {
            'auth_form': auth_form,
            'user_form': user_form,
        })