Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. from django.conf.urls import url
  2. from django.views.generic import ListView, TemplateView
  3.  
  4. from .models import Dreamreal
  5. from . import views
  6. urlpatterns = [
  7. url(r'^connection/login/$', views.login),
  8. url(r'^connection/$', TemplateView.as_view(template_name =
  9. 'login.html')),
  10. url(r'^login/$', views.login, name = 'login')
  11. ]
  12.  
  13. from .forms import LoginForm
  14. from . import models
  15.  
  16. def login(request):
  17. username = "not logged in"
  18.  
  19. if request.POST:
  20. # GET THE POSTED FORM
  21. MyLoginForm = LoginForm(request.POST)
  22. if MyLoginForm.is_valid():
  23. username = MyLoginForm.cleaned_data['username']
  24. else:
  25. MyLoginForm = LoginForm()
  26.  
  27. return render(request, 'loggedin.html', {'username' : username})
  28.  
  29. from django import forms
  30. from .models import Dreamreal
  31.  
  32. class LoginForm(forms.Form):
  33. username = forms.CharField(max_length = 100)
  34. password = forms.CharField(widget = forms.PasswordInput())
  35.  
  36. # METHOD TO VERIFY IF USER IS IN DB
  37. def clean_message(self):
  38. username = self.cleaned_data.get("username")
  39. dbuser = Dreamreal.objects.filter(name = 'username')
  40.  
  41. if not dbuser:
  42. raise forms.ValidationError("User does not exist in our db!")
  43.  
  44. return username
  45.  
  46. from django.db import models
  47. class Dreamreal(models.Model):
  48. website = models.CharField(max_length = 50)
  49. mail = models.CharField(max_length = 50)
  50. name = models.CharField(max_length = 50)
  51. phonenumber = models.IntegerField()
  52.  
  53. class Meta:
  54. db_table = 'dreamreal'
  55.  
  56. <html>
  57. <head>
  58. <title>LOG IN</title>
  59. </head>
  60. <body>
  61. <form name="form" action="/connection/login/" method="POST">
  62. {% csrf_token %}
  63. <div style="max-width: 470px;">
  64. <center><input type="text" name="username"
  65. placeholder="username" style="margin-left: 20%;" required>
  66. </center>
  67. </div>
  68. <br>
  69. <div style="max-width: 470px;">
  70. <center><input type="password" name="password"
  71. placeholder="password" style="margin-left: 20%;"></center>
  72. </div>
  73. <br>
  74. <div style="max-width: 470px;">
  75. <center><button style = "border:0px; background-color:#4285F4;
  76. margin-top:8%; height:35px; width:80%;margin-left:19%;" type =
  77. "submit" value = "Login" >
  78. <strong>Login</strong>
  79. </button></center>
  80. </div>
  81.  
  82. </form>
  83.  
  84. </body>
  85. </html>
  86.  
  87. {% extends 'base.html' %}
  88. <html>
  89. <head>
  90. <title>{% block title%}{{ username }}{% endblock %}</title>
  91. </head>
  92. <body>
  93. {% block content %}
  94. You are : <strong>{{ username }}</strong>
  95. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement