Giter VIP home page Giter VIP logo

djangoautherization's Introduction

DjangoAutherization

  • This authentication based app in django2

url.py main project

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/',include('accounts.urls')),

]

views.py


def register(request):
    
    if request.method == 'POST':

        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        username = request.POST['username']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        email = request.POST['email']

        if password1 == password2:
            if User.objects.filter(username=username).exists():
                messages.info(request,'UserName taken')
                return redirect('register')
                # print("UserName taken")
            elif User.objects.filter(email=email).exists():
                messages.info(request,'Email taken')
                # print("email taken")
                return redirect('register')
            else:
                user = User.objects.create_user(username=username,password=password1,email=email,first_name=first_name)
                user.save();
                print('user created')

        else:
            print('Password Not matching ..')
            return redirect('register')

        return redirect('index')

    else:
        return render(request, 'register.html')

def login(request):
     #Check for the method
    if request.method == 'POST':
        # tAKING THE USERNAME AND PASSSWORD FROM THE DATABASE IF AVAILABLE
        username = request.POST['username']
        messages.info(request,username)  # FOR DISPLAYING THE MSG TO USER
        password = request.POST['password'] 

        #CHECK FOR THE THE AUTH
        user = auth.authenticate(username=username, password=password)

        #CHECK FOR USER PRESENCE
        if user is not None:
            auth.login(request,user)
            print("user is logged in")
            return redirect('index')

        else:
            messages.info(request,'invalid Credentials')
            return redirect('login')

    else:
        return render(request,'login.html')

def logout(request):
    auth.logout(request)
    return redirect('index')


url.py

urlpatterns = [
    path('', views.index, name='index'),
    path('register/',views.register,name='register'),
    path('login/',views.login,name='login'),
    path('logout/',views.logout,name='logout')
]

For more reference visit follow:-

Youtube

django auth docs

djangoautherization's People

Contributors

sd8917 avatar sgpritam avatar

Watchers

James Cloos avatar  avatar

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.