title: How to Login, Logout and User Registration through in build Authentication method?
body: <p>view.py</p>
  
  <pre><code>from django.contrib.auth import authenticate, login, logout
  from django.contrib.auth.decorators import login_required
  from django.contrib import messages
  
  # Create your views here.
  def signin(request):
      if request.method=='POST':
          username=request.POST['username']
          password=request.POST['password']
          user=authenticate(username=username,password=password)
          if user !=None:
              login(request,user)
          else:
              return HttpResponseRedirect('signin')
      else:
          messages.add_message(request, messages.ERROR, "Incorrect user or password")
      return render(request,'customer/login.html')
  
  def signout(request):
      logout(request)
  
  @login_required(login_url='customer/login.html')
  def createcustomer(request):
      if request.method == 'POST':
          form = CustomerForm(request.POST)
          if form.is_valid():
              customer_save=Customer.objects.create(
                  fname=form.cleaned_data['fname'],
                  lname = form.cleaned_data['lname'],
                  email= form.cleaned_data['email'],
                  address= form.cleaned_data['address'],
                  city=form.cleaned_data['city'],
                  state=form.cleaned_data['state'],
                  zip=form.cleaned_data['zip'],
                  uname=form.cleaned_data['uname'],
                  password=form.cleaned_data['password'],
                  age=form.cleaned_data['age'],
                  mobile=form.cleaned_data['mobile'],
                  phone=form.cleaned_data['phone'],
              )
              customer_save.save()
  
              return HttpResponseRedirect('thanks')
      else:
          form = CustomerForm()
  
      return render(request, 'customer/createcustomer.html', {'form': form})
  </code></pre>
  
  <p>login.html</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Edit Custmer Tasks&lt;/title&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;title&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="container-fluid" style="background-color: #f2f2f2;border:solid;" &gt;
      &lt;div class="col-md-4"&gt;&lt;/div&gt;
      &lt;div class="col-md-4"&gt;
          &lt;form class="login-page" method="post" action=""&gt;
  
              &lt;div class="input-group margin-bottom-20"&gt;
                  &lt;span class="input-group-addon"&gt;
                      &lt;i class="fa fa-user"&gt;&lt;/i&gt;
                  &lt;/span&gt;
                  &lt;input type="text" name="username" class="form-control" placeholder="Username/Email"&gt;
              &lt;/div&gt;
              &lt;div class="input-group margin-bottom-20"&gt;
                  &lt;span class="input-group-addon"&gt;
                      &lt;i class="fa fa-lock"&gt;&lt;/i&gt;
                  &lt;/span&gt;
                  &lt;input type="password" name="password" class="form-control" placeholder="Password"&gt;
              &lt;/div&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;label class="checkbox"&gt;
                          &lt;input type="checkbox"&gt;Stay signed in&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;button class="btn btn-primary pull-right" type="submit"&gt;Login&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>url.py</p>
  
  <pre><code>from  views import signin
  from django.contrib.auth import views as auth_views
  from django.conf.urls import url
  from django.contrib.auth.views import login
  from views import createcustomer, customerlist, customerdetails,thanks,   editcustomer, createtasks, listtasks, edittasks, viewtasks, customertable, tasktable
  from  views import signin
  from django.contrib.auth import views as auth_views
  
  urlpatterns = [
  url(r'^signin$', signin, name="signin"),
  url(r'^customer/login/$', auth_views.login),
  #url(r'^login/$', login, name="login"),
  url(r'^create/$', createcustomer, name="createcustomer"),
  url(r'^list/$', customerlist, name="customerlist"),
  url(r'^edit/(?P&lt;pk&gt;[0-9]+)/', editcustomer, name="editcustomer"),
  url(r'^view/(?P&lt;id&gt;[0-9]+)/', customerdetails, name="customerdetails"),
   ......
  ]
  </code></pre>
  
  <p>What I am Doing is:
  I want to add a customer from a web page to database, but i want that only registerd person can post the Customer details in database. So i want to add new authenticate user using authnticate method. Login the authenticate user, then uthenticate user cand add after login.</p>
  
  <p>Basically i want a simple sign in, sign out and registrasion using Authentication. 
  Please comment or send me mail (rochanmohyalsharma@gmail.com) if you want other code</p>