Giter Club home page Giter Club logo

django-iitg-auth's Introduction

django-iitg-auth

https://img.shields.io/pypi/v/django-iitg-auth.svg?style=plastic https://travis-ci.org/narenchoudhary/django-iitg-auth.svg?branch=master

django-iitg-auth is a reusable Django application which provides a custom authencation backend for authenticating with IIT Guwahati webmail servers, a login form and a utility view.

Installation

django-iitg-auth can be installed using following pip command.

pip install django-iitg-auth

Usage: Authentication Backend

Add 'iitgauth' to INSTALLED_APPS settings of the project.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    ...
    ...
    'iitgauth',
]

Add 'iitgauth.auth.WebMailAuthenticationBackend' to AUTHENTICATION_BACKENDS in settings.py.

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'iitgauth.auth.WebMailAuthenticationBackend',
]

This is all the configuration required to use the webmail authentication backend.

Note that authenticate method of the backend requires following credentials:
  • username
  • password
  • login server
  • port (default is set to 995)

Following snippet shows how webmail authentication can be done in a custom view.

from django.contrib.auth import authenticate
from django.views.generic import View

class LoginView(View):

    def get(self, request):
        # get request handling logic
        #

    def post(self, request):
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data('username')
            password = form.cleaned_data('password')
            login_server = form.cleaned_data('login_server')

            # open a socket to login server and query validity of credentials
            user = auth.authenticate(username=username, password=password,
                        login_server=login_server, port=995)
            #
            # rest of authentication logic
            #
       else:
           # invalid form hadling

Usage: WebmailLoginForm and WebmailLoginView

A ready-to-use form (WebmailLoginForm) and a class based view (WebmailLoginView) are also available. Using this form and view is not necessary. You can write your own custom login form and view to use with webmail authentication backend as explained above.

This form works exactly similar to Django's built-in AuthenticationForm. Only difference is WebmailLoginForm has one extra field, .i.e. Login Server field.

WebmailLoginForm has 3 fields:
  • username
  • password
  • login_server

WebmailLoginView is a FormView which renders WebmailLoginForm on GET and redirects to success_url on successful authentication.

Example Project

A demo project is available in django-iitg-auth-example repository.

django-iitg-auth's People

Contributors

narenchoudhary avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

django-iitg-auth's Issues

Add instructions for running example project

Add instructions for running demo project in the documentation. A valid User must be created for demo project to run, otherwise the login form gives No user found for given credentials. error. This information isn't documented anywhere.

Example app not working?

Could you confirm if the example app is working?
Reproduce -

git clone https://github.com/narenchoudhary/django-iitg-auth.git
python setup.py install
cd example/
python manage.py migrate
python manage.py runserver

The login does not work, and an error No user found for given credentials. is produced for correct credentials

Documentation bug

In iitgauth/forms/forms.py line 15,
Its probably "except" and not "expect"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.