Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django import forms
- from django.contrib.auth.forms import AuthenticationForm
- GROUP = (
- ('', '--------------'),
- ('red_server'),
- ('blue_server'),
- )
- class LoginForm(AuthenticationForm):
- group = forms.ChoiceField(choices=GROUP, required=True,
- help_text="Choose one of the groups to login." )
- field_order = ['group', 'username', 'password']
- from django.contrib.auth.models import User
- from django.conf import settings
- def client_for(username, password=None, group=None):
- """
- Get a connection for the given user.
- """
- auth_server = settings.AUTH_SERVER[group]
- # here goes the server authentication code
- class UnixBackend(object):
- """
- Authenticate the given user as a Unix account on a remote host.
- """
- def authenticate(self, username=None, password=None):
- try:
- client_for(username, password, group)
- except paramiko.AuthenticationException:
- return None
- try:
- user = User.objects.get(username=username)
- except User.DoesNotExist:
- # Create a new user if the user does not exist yet
- user = User(username=username)
- user.is_staff = False
- user.is_active = True
- user.save()
- return user
- def get_user(self, user_id):
- try:
- return User.objects.get(pk=user_id)
- except User.DoesNotExist:
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement