Commit c89f0529de5c7180ee8d9ce2d52a7b89f686795c
Committed by
GitHub
Exists in
master
and in
5 other branches
Merge pull request #152 from amadeusproject/master
Moving changes from master until now to dev
Showing
9 changed files
with
102 additions
and
51 deletions
Show diff stats
core/forms.py
1 | 1 | from django import forms |
2 | 2 | from django.utils.translation import ugettext_lazy as _ |
3 | 3 | from users.models import User |
4 | +from pycpfcnpj import cpfcnpj | |
5 | +import re | |
6 | + | |
7 | + | |
4 | 8 | |
5 | 9 | class RegisterUserForm(forms.ModelForm): |
6 | 10 | |
7 | - password = forms.CharField(label='Senha', widget=forms.PasswordInput) | |
8 | - password2 = forms.CharField(label = 'Confirmacao de Senha', widget = forms.PasswordInput) | |
11 | + password = forms.CharField(label=_('Password'), widget=forms.PasswordInput) | |
12 | + password2 = forms.CharField(label = _('Password confirmation'), widget = forms.PasswordInput) | |
9 | 13 | # birth_date = forms.DateField(widget=forms.SelectDateWidget()) |
10 | 14 | MIN_LENGTH = 8 |
11 | 15 | |
16 | + def validate_cpf(self, cpf): | |
17 | + cpf = ''.join(re.findall('\d', str(cpf))) | |
18 | + # print(cpf) | |
19 | + | |
20 | + # if (not cpf) or (len(cpf) < 11): | |
21 | + # return False | |
22 | + | |
23 | + # #Get only the first 9 digits and generate other 2 | |
24 | + # _int = map(int, cpf) | |
25 | + # integer = list(map(int, cpf)) | |
26 | + # new = integer[:9] | |
27 | + | |
28 | + # while len(new) < 11: | |
29 | + # r = sum([(len(new) + 1 - i)* v for i, v in enumerate(new)]) % 11 | |
30 | + | |
31 | + # if r > 1: | |
32 | + # f = 11 - r | |
33 | + # else: | |
34 | + # f = 0 | |
35 | + # new.append(f) | |
36 | + | |
37 | + # #if generated number is the same(original) the cpf is valid | |
38 | + # new2 = list(new) | |
39 | + # if new2 == _int: | |
40 | + # return cpf | |
41 | + # else: | |
42 | + # return False | |
43 | + if cpfcnpj.validate(cpf): | |
44 | + return True | |
45 | + return False | |
46 | + | |
12 | 47 | def clean_email(self): |
13 | 48 | email = self.cleaned_data['email'] |
14 | 49 | if User.objects.filter(email = email).exists(): |
15 | 50 | raise forms.ValidationError(_('There is already a registered User with this e-mail')) |
16 | 51 | return email |
17 | 52 | |
53 | + def clean_cpf(self): | |
54 | + cpf = self.cleaned_data['cpf'] | |
55 | + if User.objects.filter(cpf = cpf).exists(): | |
56 | + raise forms.ValidationError(_('There is already a registeres User with this CPF')) | |
57 | + if not self.validate_cpf(cpf): | |
58 | + raise forms.ValidationError(_('Please enter a valid CPF')) | |
59 | + return cpf | |
60 | + | |
18 | 61 | def clean_password(self): |
19 | 62 | password = self.cleaned_data.get('password') |
20 | 63 | ... | ... |
core/static/css/base/amadeus.css
... | ... | @@ -271,6 +271,14 @@ a.alert_message:hover{color : grey} |
271 | 271 | display: none; |
272 | 272 | } |
273 | 273 | |
274 | +/*Logo register user*/ | |
275 | +#logo{ | |
276 | + max-width: 30%; | |
277 | + margin-top: 1em; | |
278 | + margin-bottom: 1em; | |
279 | +} | |
280 | +/*====================== ========*/ | |
281 | + | |
274 | 282 | .accordion { |
275 | 283 | background: #c0c0c0; |
276 | 284 | } | ... | ... |
core/templates/index.html
... | ... | @@ -21,30 +21,25 @@ |
21 | 21 | </div> |
22 | 22 | </div> |
23 | 23 | </div> |
24 | - <div class="row"> | |
25 | - {% for breadcrumb in breadcrumbs %} | |
26 | - <a href="{{ breadcrumb.url }}">{{ breadcrumb.text }}</a> | |
27 | - {% endfor %} | |
28 | - </div> | |
29 | 24 | |
30 | 25 | <div class="row "> |
31 | 26 | <div class="col-md-8 col-md-offset-2 col-sm-8 col-sm-offset-2 col-xs-8 col-xs-offset-2 col-lg-8 col-lg-offset-2 col-xl-8 col-xl-offset-2"> |
32 | - {% if message %} | |
33 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
34 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
35 | - <span aria-hidden="true">×</span> | |
36 | - </button> | |
37 | - <ul> | |
38 | - <li>{{ message }}</li> | |
39 | - </ul> | |
40 | - </div> | |
41 | - {% endif %} | |
27 | + {% if messages %} | |
28 | + {% for message in messages %} | |
29 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
30 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
31 | + <span aria-hidden="true">×</span> | |
32 | + </button> | |
33 | + <p>{{ message }}</p> | |
34 | + </div> | |
35 | + {% endfor %} | |
36 | + {% endif %} | |
42 | 37 | <div class="card"> |
43 | 38 | <div class="card-block"> |
44 | 39 | <form id="form-login" class="form-group" method="post" action=""> |
45 | - {% csrf_token %} | |
46 | - <div class="form-group is-empty"> | |
47 | - <label for="inputEmail" class="col-md-4 col-xs-4 col-sm-4 col-lg-4 control-label"> {% trans 'Username' %}</label> | |
40 | + {% csrf_token %} | |
41 | + <div class="form-group is-empty"> | |
42 | + <label for="inputEmail" class="col-md-4 col-xs-4 col-sm-4 col-lg-4 control-label"> {% trans 'Username' %}</label> | |
48 | 43 | <div class="col-md-8 col-xs-8 col-lg-8 col-sm-8"> |
49 | 44 | <input form="form-login" type="text" name="username" class="form-control" id="inputEmail" placeholder="Username" value="{% if username %}{{username}}{% endif %}"> |
50 | 45 | </div> | ... | ... |
core/templates/register_user.html
... | ... | @@ -44,6 +44,8 @@ |
44 | 44 | </button> |
45 | 45 | </span> |
46 | 46 | </div> |
47 | + {% elif field.auto_id == 'id_cpf' %} | |
48 | + {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} | |
47 | 49 | {% else %} |
48 | 50 | {% render_field field class='form-control' %} |
49 | 51 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> |
... | ... | @@ -68,7 +70,7 @@ |
68 | 70 | <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> |
69 | 71 | </div> |
70 | 72 | <div class="col-md-offset-3 col-md-2 col-sm-2 col-xs-2"> |
71 | - <a href="{% url 'core:home' %}" class="btn btn-sm btn-success" >{% trans 'Register' %}</a> | |
73 | + <a href="{% url 'core:home' %}" class="btn btn-sm btn-success" >{% trans 'Cancel' %}</a> | |
72 | 74 | </div> |
73 | 75 | |
74 | 76 | </form> |
... | ... | @@ -79,4 +81,5 @@ |
79 | 81 | </div> |
80 | 82 | |
81 | 83 | <br clear="all" /> |
84 | + <script src="{% static 'js/base/amadeus.js' %}"></script> | |
82 | 85 | {% endblock %} | ... | ... |
core/views.py
... | ... | @@ -80,7 +80,7 @@ def login(request): |
80 | 80 | login_user(request, user) |
81 | 81 | return redirect(reverse("app:index")) |
82 | 82 | else: |
83 | - context["message"] = _("E-mail or password are incorrect!") | |
83 | + messages.add_message(request, messages.ERROR, _('E-mail or password are incorrect.')) | |
84 | 84 | context["username"] = username |
85 | 85 | elif request.user.is_authenticated: |
86 | 86 | return redirect(reverse('app:index')) | ... | ... |
requirements.txt
1 | 1 | click==6.6 |
2 | +deps==0.1.0 | |
2 | 3 | Django==1.10 |
3 | -django-autoslug==1.9.3 | |
4 | 4 | django-bootstrap-breadcrumbs==0.8 |
5 | 5 | django-discover-runner==1.0 |
6 | 6 | django-role-permissions==1.2.1 |
... | ... | @@ -10,6 +10,8 @@ itsdangerous==0.24 |
10 | 10 | Jinja2==2.8 |
11 | 11 | MarkupSafe==0.23 |
12 | 12 | Pillow==3.3.1 |
13 | -psycopg2==2.6.2 | |
13 | +pkg-resources==0.0.0 | |
14 | +pycpfcnpj==1.0.2 | |
14 | 15 | six==1.10.0 |
16 | +slugify==0.0.1 | |
15 | 17 | Werkzeug==0.11.11 | ... | ... |
users/forms.py
... | ... | @@ -5,6 +5,7 @@ from django import forms |
5 | 5 | from django.utils.translation import ugettext_lazy as _ |
6 | 6 | from rolepermissions.shortcuts import assign_role |
7 | 7 | from django.contrib.auth.forms import UserCreationForm |
8 | +from core.forms import RegisterUserForm | |
8 | 9 | from .models import User |
9 | 10 | |
10 | 11 | |
... | ... | @@ -25,26 +26,26 @@ class ProfileForm(forms.ModelForm): |
25 | 26 | 'password':forms.PasswordInput |
26 | 27 | } |
27 | 28 | |
28 | -class UserForm(UserCreationForm): | |
29 | - # def save(self, commit=True): | |
30 | - # super(UserForm, self).save() | |
31 | - # | |
32 | - # #if not self.instance.image: | |
33 | - # # self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
34 | - # | |
35 | - # # self.instance.set_password(self.cleaned_data['password']) | |
36 | - # # self.instance.save() | |
37 | - # | |
38 | - # if self.instance.is_staff: | |
39 | - # assign_role(self.instance, 'system_admin') | |
40 | - # elif self.instance.type_profile == 2: | |
41 | - # assign_role(self.instance, 'student') | |
42 | - # elif self.instance.type_profile == 1: | |
43 | - # assign_role(self.instance, 'professor') | |
44 | - # | |
45 | - # self.instance.save() | |
46 | - # | |
47 | - # return self.instance | |
29 | +class UserForm(RegisterUserForm): | |
30 | + def save(self, commit=True): | |
31 | + super(UserForm, self).save() | |
32 | + | |
33 | + if not self.instance.image: | |
34 | + self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
35 | + | |
36 | + self.instance.set_password(self.cleaned_data['password1']) | |
37 | + self.instance.save() | |
38 | + | |
39 | + if self.instance.is_staff: | |
40 | + assign_role(self.instance, 'system_admin') | |
41 | + elif self.instance.type_profile == 2: | |
42 | + assign_role(self.instance, 'student') | |
43 | + elif self.instance.type_profile == 1: | |
44 | + assign_role(self.instance, 'professor') | |
45 | + | |
46 | + self.instance.save() | |
47 | + | |
48 | + return self.instance | |
48 | 49 | |
49 | 50 | class Meta: |
50 | 51 | model = User | ... | ... |
users/templates/list_users.html
... | ... | @@ -26,7 +26,7 @@ |
26 | 26 | {% block content %} |
27 | 27 | {% if messages %} |
28 | 28 | {% for message in messages %} |
29 | - <div class="alert alert-{{ message.tag }} alert-dismissible" role="alert"> | |
29 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
30 | 30 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
31 | 31 | <span aria-hidden="true">×</span> |
32 | 32 | </button> | ... | ... |
users/templates/users/create.html
... | ... | @@ -14,10 +14,9 @@ |
14 | 14 | |
15 | 15 | |
16 | 16 | {% block content %} |
17 | - <script src="{% static 'js/base/amadeus.js' %}"></script> | |
18 | 17 | {% if messages %} |
19 | 18 | {% for message in messages %} |
20 | - <div class="alert alert-success alert-dismissible" role="alert"> | |
19 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
21 | 20 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
22 | 21 | <span aria-hidden="true">×</span> |
23 | 22 | </button> |
... | ... | @@ -49,8 +48,8 @@ |
49 | 48 | </div> |
50 | 49 | {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} |
51 | 50 | <div class="checkbox"> |
52 | - <label> | |
53 | - <input type="checkbox" name="checkbox"><span class="checkbox-material"><span class="check"></span></span> {{field.label}} | |
51 | + <label for="{{ field.auto_id }}"> | |
52 | + {% render_field field %}<span class="checkbox-material"><span class="check"></span></span> {{field.label}} | |
54 | 53 | </label> |
55 | 54 | </div> |
56 | 55 | {% elif field.auto_id == 'id_cpf' %} |
... | ... | @@ -76,7 +75,7 @@ |
76 | 75 | </div> |
77 | 76 | {% endfor %} |
78 | 77 | <div class="col-md-offset-2 col-md-2 col-sm-2 col-xs-2"> |
79 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
78 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" onclick="validarCpfSemAlert(id_cpf, CPF, idElementoMensagemErro)'" /> | |
80 | 79 | </div> |
81 | 80 | <div class="col-md-offset-3 col-md-2 col-sm-2 col-xs-2"> |
82 | 81 | <a href="{% url 'users:manage' %}" class="btn btn-sm btn-default" >{% trans 'Cancel' %}</a> |
... | ... | @@ -91,5 +90,5 @@ |
91 | 90 | {% endblock %} |
92 | 91 | |
93 | 92 | {% block javascript %} |
94 | - | |
93 | + <script src="{% static 'js/base/amadeus.js' %}"></script> | |
95 | 94 | {% endblock %} | ... | ... |