1 # Create your views here.
2 from django import http
3 from django.contrib.auth.decorators import login_required
4 from django.contrib.auth import update_session_auth_hash
5 from django.contrib import messages
6 from django.shortcuts import render
7 from django.utils.translation import ugettext as _
8 from django.views.decorators.http import require_POST
9 from accounts.forms import UserBasicForm, UserPasswordForm
10 from .models import Service
13 def account_profile(request, basic_form=None, pass_form=None):
14 return render(request, "account/profile.html", {
15 "basic_form": basic_form or UserBasicForm(instance=request.user),
16 "pass_form": pass_form or UserPasswordForm(),
17 "services": Service.objects.all(),
23 def account_change_basic_profile(request):
24 form = UserBasicForm(request.POST, instance=request.user)
28 messages.add_message(request, messages.INFO, _("Profile has been changed."))
29 return http.HttpResponseRedirect('/accounts/')
31 return account_profile(request, basic_form=form)
35 def account_change_password(request):
36 form = UserPasswordForm(request.POST)
39 request.user.set_password(form.cleaned_data['new_password'])
41 update_session_auth_hash(request, request.user)
43 messages.add_message(request, messages.INFO, _("Password has been changed."))
44 return http.HttpResponseRedirect('/accounts/')
46 return account_profile(request, pass_form=form)