Django python auth
Published: 2020-10-20 08:10:24

# python is easy peasy

@python

### ###here is the code###
#python code
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
from django.contrib import messages
from plyer import notification

# Create your views here.

def index(request):
    if request.method == 'POST':
        UserName = request.POST['UserName']
        email = request.POST['email']
        First_name = request.POST['first_name']
        Last_name = request.POST['last_name']
        password = request.POST['password']
        user = User.objects.create_user(UserName, email, password)
        user.last_name = Last_name
        user.first_name = First_name
        user.save()
        user = authenticate(username=UserName, password=password)
        if user is not None:
            messages.add_message(request, messages.SUCCESS, 'You have been login successfully.')
            login(request, user)
            notification.notify(
                title = 'You have been login successfully.',
                message = f'You have been login successfully {request.user}.',
                app_icon = None,
                timeout = 30,
            )
            return redirect('/')
        else:
            messages.add_message(request, messages.ERROR, 'Choose unique User Name.')
            return redirect('/')


    return render(request, 'user_auth/index.html')

#end python
#user_auth/index.html code
<form method="POST">
  {% csrf_token %}
  <section class="text-gray-700 body-font relative">
    <div class="container px-5 py-24 mx-auto flex sm:flex-no-wrap flex-wrap">
      <div
        class="lg:w-2/3 md:w-1/2 bg-gray-300 rounded-lg overflow-hidden sm:mr-10 p-10 flex items-end justify-start relative"
      >
        <iframe
          width="100%"
          height="100%"
          class="absolute inset-0"
          frameborder="0"
          title="map"
          marginheight="0"
          marginwidth="0"
          scrolling="no"
          src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d1671.679236762!2d74.00624571258193!3d19.848714052321643!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3bddba681b3b55d7%3A0x36fcc11f1a5dad95!2sShri%20Gajanan%20Maharaj%20Mandir!5e0!3m2!1sen!2sin!4v1603173692429!5m2!1sen!2sin"
          style="filter: grayscale(1) contrast(1.2) opacity(0.4)"
        ></iframe>

        <div class="bg-white relative flex flex-wrap py-6">
          <div class="lg:w-1/2 px-6">
            <h2
              class="title-font font-medium text-gray-900 tracking-widest text-sm"
            >
              anything
            </h2>
            <p class="leading-relaxed">
              Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi
              laboriosam rem necessitatibus illo tenetur, excepturi ea repellat
              eos eveniet sint quod voluptatum tempore suscipit molestiae
              nesciunt quidem id incidunt hic.
            </p>
          </div>
          <div class="lg:w-1/2 px-6 mt-4 lg:mt-0">
            <h2
              class="title-font font-medium text-gray-900 tracking-widest text-sm"
            >
              EMAIL
            </h2>
            <a class="text-blue-500 leading-relaxed"
              >Avhadatharva@outlook.com</a
            >
            <h2
              class="title-font font-medium text-gray-900 tracking-widest text-sm mt-4"
            >
              PHONE
            </h2>
            <p class="leading-relaxed">9420691433</p>
          </div>
        </div>
      </div>
      <div
        class="lg:w-1/3 md:w-1/2 bg-white flex flex-col md:ml-auto w-full md:py-8 mt-8 md:mt-0"
      >
        <input
          class="bg-white rounded border border-gray-400 focus:outline-none focus:border-blue-500 text-base px-4 py-2 mb-4"
          placeholder="UserName"
          name="UserName"
          type="text"
        />
        <input
          class="bg-white rounded border border-gray-400 focus:outline-none focus:border-blue-500 text-base px-4 py-2 mb-4"
          name="email"
          placeholder="Email"
          type="email"
        />
        <div class="grid sm:grid-cols-1 md:grid-cols-2">
          <input
            class="bg-white rounded border border-gray-400 focus:outline-none focus:border-blue-500 text-base px-4 py-2 mb-4"
            name="first_name"
            placeholder="first name"
            type="text"
          />
          <input
            class="bg-white rounded border border-gray-400 focus:outline-none focus:border-blue-500 text-base px-4 py-2 mb-4"
            placeholder="last name"
            name="last_name"
            type="text"
          />
        </div>
        <input
          class="bg-white rounded border border-gray-400 focus:outline-none focus:border-blue-500 text-base px-4 py-2 mb-4"
          placeholder="password"
          type="password"
          name="password"
        />
        <button
          class="text-white bg-blue-500 border-0 py-2 px-6 focus:outline-none hover:bg-blue-600 rounded text-lg"
        >
          Button
        </button>
      </div>
    </div>
  </section>
</form>
#end user_auth/index.html code

#base.html code
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>I insta Non realtime chatapp</title>
    <link rel="stylesheet"style.css" />
    <link
      href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
    <link rel="shortcut icon" href="/static/logo.png" type="image/x-icon" />
  </head>
  <body>
    <nav class="shadow-xl text-gray-700 body-font">
      <div
        class="container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center"
      >
        <a
          class="flex title-font font-medium items-center text-gray-900 mb-4 md:mb-0"
          href="/"
        >
          <img
            src="/static/nav-logo.png"
            alt="logo"
            class="w-10 h-10 text-white p-2 rounded-full"
          />
          <span class="ml-3 text-xl">I insta</span>
        </a>
        <nav
          class="md:ml-auto flex flex-wrap items-center text-base justify-center"
        >
          <a class="mr-5 text-gray-900" href="/">Home</a>
          {% if request.user.is_anonymous %}
            {% else %}
            <a class="mr-5 hover:text-gray-900" href="/">Add Your Post</a>
            <a class="mr-5 hover:text-gray-900" href="/">Your Profile</a>
          {% endif %}
          <a class="mr-5 hover:text-gray-900" href="/contact/"
            >Have any issue contact??</a
          >
        </nav>
        {% if request.user.is_anonymous %}
        <a
          class="inline-flex items-center bg-gray-200 border-0 py-1 px-3 focus:outline-none hover:bg-gray-300 rounded text-base mt-4 md:mt-0"
        >
          Login
          <svg
            fill="none"
            stroke="currentColor"
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            class="w-4 h-4 ml-1"
            viewBox="0 0 24 24"
          >
            <path d="M5 12h14M12 5l7 7-7 7"></path>
          </svg>
        </a>
        <a
          class="inline-flex items-center bg-gray-200 border-0 py-1 px-3 focus:outline-none hover:bg-gray-300 rounded text-base mt-4 md:mt-0"
        >
          Sign in
          <svg
            fill="none"
            stroke="currentColor"
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            class="w-4 h-4 ml-1"
            viewBox="0 0 24 24"
          >
            <path d="M5 12h14M12 5l7 7-7 7"></path>
          </svg>
        </a>
        {% else %}
        <a
          class="inline-flex items-center bg-gray-200 border-0 py-1 px-3 focus:outline-none hover:bg-gray-300 rounded text-base mt-4 md:mt-0"
        >
          Logout
          <svg
            fill="none"
            stroke="currentColor"
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            class="w-4 h-4 ml-1"
            viewBox="0 0 24 24"
          >
            <path d="M5 12h14M12 5l7 7-7 7"></path>
          </svg>
        </a>
        {% endif %}
      </div>
    </nav>
    {% if messages %}
        {% for message in messages %}
        {% if message.tags %}
        <div class="bg-{{message.tags}}-100 border border-{{message.tags}}-400 text-{{message.tags}}-700 px-4 py-3 alert rounded relative" role="alert">
          <span class="block sm:inline">{{ message }}</span>
          <span class="absolute top-0 bottom-0 right-0 px-4 py-3">
            <svg class="fill-current h-6 w-6 text-{{message.tags}}-500 close" role="button" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><title>Close</title><path d="M14.348 14.849a1.2 1.2 0 0 1-1.697 0L10 11.819l-2.651 3.029a1.2 1.2 0 1 1-1.697-1.697l2.758-3.15-2.759-3.152a1.2 1.2 0 1 1 1.697-1.697L10 8.183l2.651-3.031a1.2 1.2 0 1 1 1.697 1.697l-2.758 3.152 2.758 3.15a1.2 1.2 0 0 1 0 1.698z"/></svg>
          </span>
        </div>
        {% endif %}
        {% endfor %}
    {% endif %}
    
    {% block body %} {% endblock body %}
    <footer class="shadow-xl hover:shadow-2xl bottom text-gray-700 body-font">
      <div
        class="container px-5 py-8 mx-auto flex items-center sm:flex-row flex-col"
      >
        <a
          class="flex title-font font-medium items-center md:justify-start justify-center text-gray-900"
          href="/"
        >
          <img
            src="/static/nav-logo.png"
            alt="logo"
            class="w-10 h-10 text-white p-2 rounded-full"
          />
          <span class="ml-3 text-xl">I insta</span>
        </a>
        <p
          class="text-sm text-gray-500 sm:ml-4 sm:pl-4 sm:border-l-2 sm:border-gray-200 sm:py-2 sm:mt-0 mt-4"
        >
          All Rights Reserved, I insta &copy; 2020 | Website Powered by Atharva Avhad's team
        </span>
        <samp class="text-gray-900 mx-5"><a href="https://github.com/tech-atharva/i_insta.git" target="_git_link"><h1>Follow on me github <i class="fab fa-github"></i></h1></a></samp>
      </div>
    </footer>
  </body>
  <script>
    var message = document.querySelector('.alert')
    var closes = document.querySelector('.close')
    closes.addEventListener('click', e=>{
      message.classList.toggle('dismis')
    })
  </script>
</html>

#base.html code

#css code
html, body {
  display: -webkit-box !important;
  display: -ms-flexbox !important;
  display: flex !important;
  -webkit-box-orient: vertical !important;
  -webkit-box-direction: normal !important;
      -ms-flex-direction: column !important;
          flex-direction: column !important;
  height: 100% !important;
  color: #4199e1 !important;
}

.bottom {
  margin: auto auto;
  margin-bottom: 0% !important;
}

.dismis {
  display: none !important;
  -webkit-transition: all 0.2s linear !important;
  transition: all 0.2s linear !important;
}
/*# sourceMappingURL=style.css.map */
#end css code