diff --git a/re2o/urls.py b/re2o/urls.py index c864afae..c9f34474 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -18,4 +18,5 @@ from django.contrib import admin urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^users/', include('users.urls')), + url(r'^search/', include('search.urls')), ] diff --git a/users/forms.py b/users/forms.py new file mode 100644 index 00000000..f748e896 --- /dev/null +++ b/users/forms.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + + +from django import forms + + +class PassForm(forms.Form): + passwd = forms.CharField(label=u'Nouveau mot de passe', max_length=255, widget=forms.PasswordInput) diff --git a/users/urls.py b/users/urls.py index 82396778..12c1e2f1 100644 --- a/users/urls.py +++ b/users/urls.py @@ -5,5 +5,8 @@ from . import views urlpatterns = [ url(r'^new_user/$', views.new_user, name='new_user'), url(r'^edit_info/(?P[0-9]+)$', views.edit_info, name='edit_info'), + url(r'^state/(?P[0-9]+)$', views.state, name='state'), + url(r'^password/(?P[0-9]+)$', views.password, name='password'), ] + diff --git a/users/views.py b/users/views.py index 87242c40..5b9fe2ad 100644 --- a/users/views.py +++ b/users/views.py @@ -1,13 +1,14 @@ # App de gestion des users pour re2o # Goulven Kermarec, Gabriel Détraz # Gplv2 -from django.shortcuts import render +from django.shortcuts import render, redirect from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import Context, RequestContext, loader +from django.contrib import messages from users.models import User, UserForm, InfoForm, PasswordForm, StateForm - +from users.forms import PassForm def form(ctx, template, request): c = ctx @@ -28,8 +29,33 @@ def edit_info(request, userid): try: user = User.objects.get(pk=userid) except User.DoesNotExist: - user = None + messages.error(request, u"Utilisateur inexistant" ) + return redirect("/users/") user = InfoForm(request.POST or None, instance=user) if user.is_valid(): user.save() return form({'userform': user}, 'users/user.html', request) + +def state(request, userid): + try: + user = User.objects.get(pk=userid) + except User.DoesNotExist: + messages.error(request, u"Utilisateur inexistant" ) + return redirect("/users/") + user = StateForm(request.POST or None, instance=user) + if user.is_valid(): + user.save() + return form({'userform': user}, 'users/user.html', request) + +def password(request, userid): + try: + user = User.objects.get(pk=userid) + except User.DoesNotExist: + messages.error(request, u"Utilisateur inexistant" ) + return redirect("/users/") + user_form = PassForm(request.POST or None) + if user_form.is_valid(): + user.pwd_ssha = user_form.cleaned_data['passwd'] + user.pwd_ntlm = user_form.cleaned_data['passwd'] + user.save() + return form({'userform': user_form}, 'users/user.html', request)