python - How can I login to HTML login page with my email address in Django -


i create html login page , authenticate through views.py. want login email address only. when use other email addresses , can able login.i set custom_authentication in views.py.

template login.html

{% load staticfiles %}   <!doctype html> <!--[if lt ie 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if ie 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if ie 8]> <html class="lt-ie9" lang="en"> <![endif]--> <!--[if gt ie 8]><!--> <html lang="en"> <!--<![endif]--> <head> <title>s.p.m school</title>   <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">         <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">         <link rel="stylesheet" href="{% static 'css/style.css' %}">         <link href="//fonts.googleapis.com/css?family=lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">            <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>   <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>     <meta charset="utf-8">   <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1">    <link rel="stylesheet" href="css/style.css">   <!--[if lt ie 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <style> table, th, td {     border: 0px solid black; } </style> <script> function validateform() {     var mail = document.forms["myform"]["email"].value; var psd = document.forms["myform"]["password"].value;     var atpos = mail.indexof("@");     var dotpos = mail.lastindexof(".");     if (atpos<1 || dotpos<atpos+2 || dotpos+2>=mail.length) {         alert("not valid e-mail address");         return false;     } if (psd == null || psd == "") {         alert("not valid password");         return false;     }  }   </script>  </head> <body>   <div id="page">   <div id="header">     <div id="section">   {% if user.is_authenticated %} <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a> {% endif %}        <div class="headline">       <font size="10": color="white"><center>s.p.m.l.p school</center></font>       </div>         <span>303nishanth@gmail.com <br />       <br />       +91 9961685892</span> </div>      <ul>       <li class="#"><a href="/">home</a></li>       <li><a href="{% url 'about' %}">about us</a></li>       <li><a href="{% url 'event' %}">event</a></li>       <li><a href="{% url 'calendar' %}">school calendar</a></li>       <li><a href="{% url 'contact' %}">contact us</a></li>     </ul>  <br><br>   <section class="container">     <div class="login">       <div id="section"><br><br>       <h1><center>login as<font color="red"> admin</font></center></h1><br>        </div>           <form name="myform" action="{% url 'class_info' %}" onsubmit="return validateform();" method="post">             <input type='hidden' name='csrfmiddlewaretoken' value='wu5esidelr8esvdgxmhmfnccmsldhyk5' />          {%csrf_token%}        <div class="text">         <p><center><input type="text" name="email"  placeholder="username or email"></p></center>         <p><center><input type="password" name="password" placeholder="password"></p></center>         <p class="remember_me">             </p>         <center><p class="submit"><input type="submit" name="commit" value="login"></p></center>       </form>     </div>     </section>   </body> </html> 

views.py

def login(request):     return render(request, 'blog/login.html')  def custom_auth(username=none, password=none):     user = none     if username == '303nishanth@gmail.com': # email allowed        user = authenticate(username=email, password=psd)     return user  def login_submit(request):     context = {}      email = request.post.get('email','')     psd = request.post.get('password', '')      user = custom_auth(username=email, password=psd)     if user not none:         # password verified user             if user.is_active:                 context['message'] = "user valid, active , authenticated"                 return render (request,'class_info.html',context)                else:                     context['message']= "the password valid, account has been disabled!"     else:         # authentication system unable verify username , password             context['message']= "the username , password incorrect."      return render (request,'login.html',context) 


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -