Advertisement
Guest User

wc

a guest
Nov 2nd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. from django.contrib.auth.forms import AuthenticationForm
  2. from django import forms
  3. from django.contrib.auth import authenticate
  4. #from django.contrib.auth.models import User
  5.  
  6.  
  7. class LoginAuth(AuthenticationForm):
  8.     username = forms.CharField(max_length=30, label='Username',
  9.                                widget=forms.TextInput(attrs={
  10.                                    'id': 'username', 'name': 'username'
  11.                                }))
  12.     password = forms.CharField(max_length=30, label='Password',
  13.                                widget=forms.PasswordInput(attrs={
  14.                                    'id': 'password', 'name': 'password'
  15.                                }))
  16.  
  17.     def login_auth(self):
  18.         user = authenticate(username = self.username, password = self.password)
  19.         if user is not None:
  20.             if user.is_active and user.is_staff is True:
  21.                 return 'admin'
  22.             elif user.is_active and user.is_staff is False:
  23.                 return 'ordinary'
  24.             else:
  25.                 return 'deny'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement