move pwd change to method

Signed-off-by: Ludovic Stephan <lstephan@clipper.ens.fr>
This commit is contained in:
Ludovic Stephan 2017-01-10 12:58:35 -02:00
parent 7dc7d57a5e
commit 6315ddf6b8
2 changed files with 10 additions and 8 deletions

View file

@ -154,6 +154,7 @@ class Account(models.Model):
# - Enregistre User, CofProfile à partir de "data"
# - Enregistre Account
def save(self, data = {}, *args, **kwargs):
if self.pk and data:
# Account update
@ -200,6 +201,12 @@ class Account(models.Model):
self.cofprofile = cof
super(Account, self).save(*args, **kwargs)
def change_pwd(self, pwd):
pwd_sha256 = hashlib.sha256(pwd.encode('utf-8'))\
.hexdigest()
self.password = pwd_sha256
self.save()
# Surcharge de delete
# Pas de suppression possible
# Cas à régler plus tard

View file

@ -421,10 +421,7 @@ def account_update(request, trigramme):
if (request.user.has_perm('kfet.change_account_password')
and pwd_form.is_valid()):
pwd = pwd_form.cleaned_data['pwd1']
pwd_sha256 = hashlib.sha256(pwd.encode('utf-8'))\
.hexdigest()
Account.objects.filter(pk=account.pk).update(
password=pwd_sha256)
account.change_pwd(pwd)
messages.success(request, 'Mot de passe mis à jour')
# Checking perm to manage perms
@ -459,6 +456,7 @@ def account_update(request, trigramme):
'Informations du compte %s mises à jour'
% account.trigramme)
# Modification de ses propres informations
if request.user == account.user:
missing_perm = False
account.refresh_from_db()
@ -476,10 +474,7 @@ def account_update(request, trigramme):
if request.user.has_perm('kfet.is_team') \
and pwd_form.is_valid():
pwd = pwd_form.cleaned_data['pwd1']
pwd_sha256 = hashlib.sha256(pwd.encode('utf-8'))\
.hexdigest()
Account.objects.filter(pk=account.pk).update(
password=pwd_sha256)
account.change_pwd(pwd)
messages.success(
request, 'Votre mot de passe a été mis à jour')