2017-09-22 23:31:46 +02:00
|
|
|
import hashlib
|
|
|
|
|
2017-09-21 23:39:27 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
|
|
|
|
from kfet.models import Account
|
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
|
|
|
|
|
|
def get_kfet_generic_user():
|
|
|
|
"""
|
|
|
|
Return the user related to the kfet generic account.
|
|
|
|
"""
|
|
|
|
return Account.objects.get_generic().user
|
|
|
|
|
|
|
|
|
|
|
|
def setup_kfet_generic_user(**kwargs):
|
|
|
|
"""
|
|
|
|
First steps of setup of the kfet generic user are done in a migration, as
|
|
|
|
it is more robust against database schema changes.
|
|
|
|
Following steps cannot be done from migration.
|
|
|
|
"""
|
|
|
|
generic = get_kfet_generic_user()
|
|
|
|
generic.user_permissions.add(
|
|
|
|
Permission.objects.get(
|
|
|
|
content_type__app_label='kfet',
|
2017-10-26 11:16:56 +02:00
|
|
|
content_type__model='account',
|
2017-09-21 23:39:27 +02:00
|
|
|
codename='is_team',
|
|
|
|
)
|
|
|
|
)
|
2017-09-22 23:31:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def hash_password(password):
|
|
|
|
return hashlib.sha256(password.encode('utf-8')).hexdigest()
|