diff --git a/static/images/rj45.gif b/static/images/rj45.gif new file mode 100644 index 00000000..69630b10 Binary files /dev/null and b/static/images/rj45.gif differ diff --git a/users/forms.py b/users/forms.py index a3dcee57..982ad58f 100644 --- a/users/forms.py +++ b/users/forms.py @@ -41,6 +41,8 @@ from django.utils import timezone from django.contrib.auth.models import Group, Permission from django.utils.translation import ugettext_lazy as _ +from machines.models import Interface, Machine, Nas +from topologie.models import Port from preferences.models import OptionalUser from re2o.utils import remove_user_room, get_input_formats_help_text from re2o.mixins import FormRevMixin @@ -660,3 +662,53 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): model = User fields = ['email','local_email_enabled', 'local_email_redirect'] + +class InitialRegisterForm(forms.Form): + register_room = forms.BooleanField(required=False) + register_machine = forms.BooleanField(required=False) + + def __init__(self, *args, **kwargs): + switch_ip = kwargs.pop('switch_ip') + switch_port = kwargs.pop('switch_port') + client_mac = kwargs.pop('client_mac') + self.user = kwargs.pop('user') + if switch_ip and switch_port: + # Looking for a port + port = Port.objects.filter(switch__interface__ipv4__ipv4=switch_ip, port=switch_port).first() + # If a port exists, checking there is a room AND radius + if port: + if port.get_port_profile.radius_type != 'NO' and port.get_port_profile.radius_mode == 'STRICT' and hasattr(port, 'room'): + # Requesting user is not in this room ? + if self.user.room != port.room: + self.new_room = port.room + if client_mac and switch_ip: + # If this interface doesn't already exists + if not Interface.objects.filter(mac_address=client_mac): + self.mac_address = client_mac + self.nas_type = Nas.objects.filter(nas_type__interface__ipv4__ipv4=switch_ip).first() + super(InitialRegisterForm, self).__init__(*args, **kwargs) + if hasattr(self, 'new_room'): + self.fields['register_room'].label = _("New connection from Room %s. Is that yours ? If it is the case, type Ok" % self.new_room) + else: + self.fields.pop('register_room') + if hasattr(self, 'mac_address'): + self.fields['register_machine'].label = _("New connection from new device. Register It ? Say Yes to get internet connection from it (mac_address : %s)" % self.mac_address) + else: + self.fields.pop('register_machine') + + def clean_register_room(self): + if self.cleaned_data['register_room']: + if self.user.is_class_adherent: + remove_user_room(self.new_room) + user = self.user.adherent + user.room = self.new_room + user.save() + if self.user.is_class_club: + user = self.user.club + user.room = self.new_room + user.save() + + def clean_register_machine(self): + if self.cleaned_data['register_machine']: + if self.mac_address and self.nas_type: + self.user.autoregister_machine(self.mac_address, self.nas_type) diff --git a/users/templates/users/plugin_out.html b/users/templates/users/plugin_out.html new file mode 100644 index 00000000..a6ebf83f --- /dev/null +++ b/users/templates/users/plugin_out.html @@ -0,0 +1,41 @@ +{% extends "users/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} +{% load massive_bootstrap_form %} +{% load static %} +{% load i18n %} +{% block title %}{% trans "Users" %}{% endblock %} + +{% block content %} + +

Votre machine et votre chambre ont bien été enregistrées. Merci de débrancher et rebrancher votre cable RJ45 pour bénéficier d'une connexion filaire

+
rj45_in_out
+ +
+
+
+{% endblock %} + diff --git a/users/urls.py b/users/urls.py index 5515dd29..1e6ffa8c 100644 --- a/users/urls.py +++ b/users/urls.py @@ -109,6 +109,7 @@ urlpatterns = [ url(r'^mass_archive/$', views.mass_archive, name='mass-archive'), url(r'^$', views.index, name='index'), url(r'^index_clubs/$', views.index_clubs, name='index-clubs'), + url(r'^initial_register/$', views.initial_register, name='initial-register'), url(r'^rest/ml/std/$', views.ml_std_list, name='ml-std-list'), diff --git a/users/views.py b/users/views.py index af311ceb..86cfa767 100644 --- a/users/views.py +++ b/users/views.py @@ -105,7 +105,8 @@ from .forms import ( PassForm, ResetPasswordForm, ClubAdminandMembersForm, - GroupForm + GroupForm, + InitialRegisterForm ) @@ -1081,6 +1082,28 @@ def process_passwd(request, req): request ) +@login_required +def initial_register(request): + u_form = InitialRegisterForm(request.POST or None, user=request.user, switch_ip=request.GET.get('switch_ip', None), switch_port=request.GET.get('switch_port', None), client_mac=request.GET.get('client_mac', None)) + if not u_form.fields: + messages.error(request, _("Incorrect url, or already registered device")) + return redirect(reverse( + 'users:profil', + kwargs={'userid': str(request.user.id)} + )) + if u_form.is_valid(): + messages.success(request, _("Successfull register ! Please plug off and plug again your cable to get internet access")) + return form( + {}, + 'users/plugin_out.html', + request + ) + return form( + {'userform': u_form, 'action_name': _("Register device or room")}, + 'users/user.html', + request + ) + class JSONResponse(HttpResponse): """ Framework Rest """