Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. from django.db import models
  2.  
  3. class userProfile(models.Model):
  4. usermail = models.CharField(max_length=264)
  5. username = models.CharField(max_length=264)
  6. userpass = models.CharField(max_length=264)
  7.  
  8. class companyProfile(models.Model):
  9. companymail = models.CharField(max_length=264)
  10. companyname = models.CharField(max_length=264)
  11. companypass = models.CharField(max_length=264)
  12.  
  13. from django import forms
  14. from Pruebas_app.models import companyProfile, userProfile
  15.  
  16. class registerCompany(forms.Form):
  17. companypassconf = forms.CharField()
  18. class Meta():
  19. model = companyProfile
  20. fields = ['companymail','companyname', 'companypass']
  21. labels = {'companymail': '', 'companyname': '', }
  22. widgets = { 'companypass': forms.PasswordInput(),}
  23.  
  24. class registerUser(forms.Form):
  25. userpassconf = forms.CharField()
  26. class Meta():
  27. model = companyProfile
  28. fields = ['usermail','username', 'userpass']
  29. labels = {'usermail': '', 'username': '', }
  30. widgets = {'userpass': forms.PasswordInput(),}
  31.  
  32. <form action="{ url 'user_register'}" method="post">
  33. <input type="text" name="username">
  34. <input type="email" name="usermail">
  35. <input type="password" name="userpass">
  36. <input type="password" name="userpassconf">
  37. <input type="submit" value="Register">
  38. </form>
  39. <form action="{ url 'company_register'}" method="post">
  40. <input type="text" name="companyname">
  41. <input type="email" name="companymail">
  42. <input type="password" name="companypass">
  43. <input type="password" name="companypassconf">
  44. <input type="submit" value="Register">
  45. </form>
  46.  
  47. from django.shortcuts import render
  48. from Pruebas import forms
  49. from Pruebas.forms import registerCompany, registerUser
  50. from django.http import HttpResponse
  51.  
  52. def user_register(request):
  53. form = forms.registerUser()
  54. regd = False
  55. passmatch = True
  56. if request.method == "POST":
  57. form = registerUser(request.POST)
  58. if form.is_valid():
  59. form_data = form.cleaned_data
  60. print (form_data.get("userpass"))
  61. if form_data.get("userpass") == form_data.get("userpassconf"):
  62. passmatch = True
  63. form.save()
  64. regd = True
  65. print("saved")
  66. else:
  67. passmatch = False
  68. else:
  69. print("error")
  70. red = 'Pruebas/register.html'
  71. regd = False
  72. return render(request, 'Pruebas/register.html', {'registered': regd, "matchPass": passmatch})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement