python - Introducing the login required decorator on my pagelogin view -
how can protect the login_dash.html page redirected on login after being successful. not sure apply @login_required decorator since redirect html page. help/contribution community highly appreciated.
below views code snippet:
def logins(request): context =requestcontext(request) if request.method == 'post': username = request.post['username'] password = request.post['password'] user = authenticate(username=username, password=password) if user not none: # account active? have been disabled. if user.is_active: # if account valid , active, can log user in. # we'll send user homepage. login(request, user) return render(request,'login-dash.html') #if accounts.accttype == business: #return render_to_response('business.html') #else: #return render_to_response('login-dash.html') else: # inactive account used - no logging in! messages.success(request, "go email , activate account") return httpresponse("your account disabled.") else: # bad login details provided. can't log user in. print "invalid login details: {0}, {1}".format(username, password) return httpresponse("invalid login details supplied.") # request not http post, display login form. # scenario http get. else: # no context variables pass template system, hence # blank dictionary object... #transaction_list = get_list_or_404(transactions) messages.success(request, "you have succefully logged in quickpay account.") transaction_list ={"transactions": transactions.objects.all()} #yes = picture.objects.filter(vote='yes').count() return render(request,'login-dash.html', transaction_list)
you have use @login_required
on views want logged-in people see.
for example, don't need @login_required
login view want people able login,
def user_login(request): if request.method == "post": username = request.post.get('username') password = request.post.get('password') user = authenticate(username=username, password=password) if user: if user.is_active: login(request, user) return httpresponseredirect('/app/') else: return httpresponse("your account disabled.") else: print "invalid login details: {0}, {1}".format(username, password) return httpresponse("invalid login credentials.") else: return render(request, 'app/login.html', {})
but logout, want people see logout when logged in.
@login_required def user_logout(request): logout(request) return httpresponseredirect('/app/')
so, plan needs @login_required
, doesn't.
Comments
Post a Comment