SHARE
TWEET

Untitled

a guest Oct 17th, 2017 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def login_user(request):
  2. if request.user.is_authenticated():
  3.     return redirect('/')
  4. if request.method == 'POST':
  5.     name = request.POST['name']
  6.     password = request.POST['password']
  7.     user = auth.authenticate(name=name, password=password)
  8.     if user is not None:
  9.         login(request, user)
  10.         return redirect('/')
  11. return render(request, 'login/login.html', locals())
  12.  
  13. {% extends 'base.html' %}
  14. {% block content %}
  15. <form role="form" id="login_user_form">{% csrf_token %}
  16.   <div class="form-group">
  17.     <label for="name">Email</label>
  18.     <input type="text" class="form-control" id="name" placeholder="Username">
  19.   </div>
  20.   <div class="form-group">
  21.     <label for="password">Пароль</label>
  22.     <input type="password" class="form-control" id="password" placeholder="Password">
  23.   </div>
  24.   <button type="submit" class="btn btn-default">Отправить</button>
  25. </form>
  26. {% endblock %}
  27. {% block script %}
  28. <script type="text/javascript">
  29.     $(document).on('submit' , '#login_user_form', function (e) {
  30.         e.preventDefault();
  31.  
  32.  
  33.         $.ajax({
  34.             type:'POST',
  35.             url:'login',
  36.             data:{
  37.                 name:$('#name').val(),
  38.                 email:$('#password').val(),
  39.             },
  40.             success:function () {
  41.  
  42.             }
  43.         });
  44.     });
  45. </script>
  46. {% endblock %}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top