Commit 7362ac04d99f9e77f8a62f3e3331b8c329a6513f
1 parent
4fb1b007
Exists in
master
and in
3 other branches
Adding register page
Showing
6 changed files
with
121 additions
and
8 deletions
Show diff stats
amadeus/views.py
1 | +from django.http import Http404 | |
1 | 2 | from django.shortcuts import redirect |
2 | 3 | |
3 | 4 | def index(request): |
4 | 5 | if request.user.is_authenticated: |
5 | - return Http404('<h1>Page not found</h1>') | |
6 | + raise Http404('<h1>Page not found</h1>') | |
6 | 7 | else: |
7 | 8 | return redirect('users:login') |
8 | 9 | \ No newline at end of file | ... | ... |
users/forms.py
... | ... | @@ -28,7 +28,7 @@ class Validation(forms.ModelForm): |
28 | 28 | |
29 | 29 | return password2 |
30 | 30 | |
31 | -class RegisterUserForm(ValidationRegister): | |
31 | +class RegisterUserForm(Validation): | |
32 | 32 | password = forms.CharField(label=_('Password'), widget=forms.PasswordInput) |
33 | 33 | password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput) |
34 | 34 | |
... | ... | @@ -45,4 +45,4 @@ class RegisterUserForm(ValidationRegister): |
45 | 45 | |
46 | 46 | class Meta: |
47 | 47 | model = User |
48 | - fields = ['username', 'name', 'last_name', 'social_name',] | |
48 | + fields = ['email', 'username', 'last_name', 'social_name',] | ... | ... |
users/templates/users/login.html
... | ... | @@ -57,7 +57,7 @@ |
57 | 57 | <button type="submite" class="btn btn-success btn-raised btn-block" form="form-login" style="position: initial;"> {% trans 'Log in' %} </button> |
58 | 58 | </div> |
59 | 59 | <div class="col-md-5 col-xs-6 col-sm-6 col-lg-5 text-center"> |
60 | - <a class="btn btn-default btn-raised btn-block" href="#" formaction="#" style="position: initial;">{% trans 'Sign Up' %}</a> | |
60 | + <a class="btn btn-default btn-raised btn-block" href="{% url 'users:signup' %}" formaction="#" style="position: initial;">{% trans 'Sign Up' %}</a> | |
61 | 61 | </div> |
62 | 62 | </div> |
63 | 63 | <div class="row"> | ... | ... |
... | ... | @@ -0,0 +1,88 @@ |
1 | +{% extends 'base.html' %} | |
2 | + | |
3 | +{% load static i18n %} | |
4 | +{% load widget_tweaks %} | |
5 | + | |
6 | +{% block nav %} | |
7 | +{% endblock %} | |
8 | + | |
9 | +{% block sidebar %} | |
10 | +{% endblock sidebar %} | |
11 | + | |
12 | +{% block content %} | |
13 | + {% if messages %} | |
14 | + {% for message in messages %} | |
15 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
16 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
17 | + <span aria-hidden="true">×</span> | |
18 | + </button> | |
19 | + <p>{{ message }}</p> | |
20 | + </div> | |
21 | + {% endfor %} | |
22 | + {% endif %} | |
23 | + | |
24 | + <div class="row"> | |
25 | + <div class="col-sm-7 col-sm-offset-4 col-md-6 col-md-offset-4 col-xs-8 col-xs-offset-3 col-lg-6 col-lg-offset-4 col-xl-6 col-xl-offset-4 "> | |
26 | + <div class="col-sm-9 col-sm-offset-2 col-md-8 col-md-offset-2 col-xs-9 col-xs-offset-2 col-lg-8 col-lg-offset-2 col-xl-8 col-xl-offset-2"> | |
27 | + <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block logo-login " alt="logo amadeus"> | |
28 | + </div> | |
29 | + </div> | |
30 | + </div> | |
31 | + | |
32 | + <div class="row"> | |
33 | + <div class="col-lg-8 col-lg-offset-3 col-md-8 col-md-offset-3 col-sm-9 col-sm-offset-3 col-xs-10 col-xs-offset-2"> | |
34 | + <div class="card"> | |
35 | + <div class="card-body"> | |
36 | + <div class="row"> | |
37 | + <div class="col-md-12 text-center"> | |
38 | + <h2 style="color:#43a251"><strong>{% trans "User Register" %}</strong></h2> | |
39 | + </div> | |
40 | + </div> | |
41 | + | |
42 | + <form class="{% if form.has_error %} has-error {% endif %} is-fileinput" method="post" enctype="multipart/form-data"> | |
43 | + {% csrf_token %} | |
44 | + {% for field in form %} | |
45 | + <div class="col-md-10 col-md-offset-1 col-sm-12 col-xs-12 col-lg-10 col-lg-offset-1"> | |
46 | + <div class="row form-group"> | |
47 | + <div class="col-md-3 col-sm-3 col-xs-5 col-lg-3 text-right"> | |
48 | + {% if field.field.required %} | |
49 | + <label for="{{ field.auto_id }}" class="control-label">{{ field.label }}<span>*</span></label> | |
50 | + {% else %} | |
51 | + <label for="{{ field.auto_id }}" class="control-label">{{ field.label }}</label> | |
52 | + {% endif %} | |
53 | + </div> | |
54 | + <div class="col-md-9 col-sm-9 col-xs-7 col-lg-9"> | |
55 | + {% render_field field class='form-control' %} | |
56 | + <span class="help-block">{{ field.help_text }}</span> | |
57 | + {% if field.errors %} | |
58 | + <div class="row"> | |
59 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
60 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
61 | + <span aria-hidden="true">×</span> | |
62 | + </button> | |
63 | + <ul> | |
64 | + {% for error in field.errors %} | |
65 | + <li>{{ error }}</li> | |
66 | + {% endfor %} | |
67 | + </ul> | |
68 | + </div> | |
69 | + </div> | |
70 | + {% endif %} | |
71 | + </div> | |
72 | + </div> | |
73 | + </div> | |
74 | + {% endfor %} | |
75 | + <div class="row"> | |
76 | + <div class="col-md-5 col-xs-6 col-sm-6 col-lg-5 col-lg-offset-1 col-md-offset-1 text-center"> | |
77 | + <input type="submit" value="{% trans 'Register' %}" class="btn btn-raised btn-primary" /> | |
78 | + </div> | |
79 | + <div class="col-md-5 col-xs-6 col-sm-6 col-lg-5 text-center"> | |
80 | + <a href="{% url 'users:login' %}" class="btn btn-Success btn-raised" >{% trans 'Login' %}</a> | |
81 | + </div> | |
82 | + </div> | |
83 | + </form> | |
84 | + </div> | |
85 | + </div> | |
86 | + </div> | |
87 | + </div> | |
88 | +{% endblock %} | |
0 | 89 | \ No newline at end of file | ... | ... |
users/urls.py
1 | 1 | from django.conf.urls import url |
2 | +from django.contrib.auth import views as auth_views | |
2 | 3 | |
3 | 4 | from . import views |
4 | 5 | |
5 | 6 | urlpatterns = [ |
6 | 7 | url(r'^login/$', views.login, name='login'), |
7 | - | |
8 | + url(r'^logout/$', auth_views.logout, {'next_page': 'users:login'}, name='logout'), | |
9 | + url(r'^signup/$', views.RegisterUser.as_view(), name = 'signup'), | |
8 | 10 | ] | ... | ... |
users/views.py
1 | +from django.http import Http404 | |
1 | 2 | from django.shortcuts import get_object_or_404,redirect, render |
2 | 3 | from django.db.models import Q |
3 | 4 | from django.views import generic |
... | ... | @@ -13,7 +14,7 @@ from itertools import chain |
13 | 14 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
14 | 15 | |
15 | 16 | from .models import User |
16 | - | |
17 | +from .forms import RegisterUserForm | |
17 | 18 | |
18 | 19 | #API IMPORTS |
19 | 20 | from rest_framework import viewsets |
... | ... | @@ -220,10 +221,31 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl |
220 | 221 | |
221 | 222 | # return context |
222 | 223 | |
224 | +class RegisterUser(generic.edit.CreateView): | |
225 | + model = User | |
226 | + form_class = RegisterUserForm | |
227 | + template_name = 'users/register.html' | |
228 | + | |
229 | + success_url = reverse_lazy('users:login') | |
230 | + | |
231 | + def get_context_data(self, **kwargs): | |
232 | + context = super(RegisterUser, self).get_context_data(**kwargs) | |
233 | + context['title'] = _('Sign Up') | |
234 | + | |
235 | + return context | |
236 | + | |
237 | + def form_valid(self, form): | |
238 | + form.save() | |
239 | + | |
240 | + assign_role(form.instance, 'student') | |
241 | + | |
242 | + messages.success(self.request, _('User successfully registered!')) | |
243 | + | |
244 | + return super(RegisterUser, self).form_valid(form) | |
223 | 245 | |
224 | 246 | def login(request): |
225 | 247 | context = {} |
226 | - context['title'] = 'Log In' | |
248 | + context['title'] = _('Log In') | |
227 | 249 | |
228 | 250 | if request.POST: |
229 | 251 | username = request.POST['email'] |
... | ... | @@ -236,7 +258,7 @@ def login(request): |
236 | 258 | messages.add_message(request, messages.ERROR, _('E-mail or password are incorrect.')) |
237 | 259 | context["username"] = username |
238 | 260 | elif request.user.is_authenticated: |
239 | - return redirect(reverse('users:login')) | |
261 | + raise Http404('<h1>Page not found</h1>') | |
240 | 262 | |
241 | 263 | return render(request,"users/login.html",context) |
242 | 264 | ... | ... |