2019-02-27 00:45:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2019-08-21 12:27:21 +00:00
|
|
|
from django.contrib.auth import authenticate
|
|
|
|
|
2019-11-01 12:34:56 +00:00
|
|
|
from . import errors
|
2019-02-27 00:45:00 +00:00
|
|
|
|
|
|
|
|
2019-08-21 12:27:21 +00:00
|
|
|
def check_user_valid(**kwargs):
|
|
|
|
password = kwargs.pop('password', None)
|
|
|
|
public_key = kwargs.pop('public_key', None)
|
|
|
|
username = kwargs.pop('username', None)
|
2019-11-05 10:46:29 +00:00
|
|
|
request = kwargs.get('request')
|
2019-08-21 12:27:21 +00:00
|
|
|
|
2019-12-09 08:12:48 +00:00
|
|
|
user = authenticate(request, username=username,
|
|
|
|
password=password, public_key=public_key)
|
|
|
|
if not user:
|
|
|
|
return None, errors.reason_password_failed
|
2019-11-05 10:46:29 +00:00
|
|
|
elif user.is_expired:
|
2019-11-05 11:05:29 +00:00
|
|
|
return None, errors.reason_user_inactive
|
2019-11-05 10:46:29 +00:00
|
|
|
elif not user.is_active:
|
|
|
|
return None, errors.reason_user_inactive
|
2019-08-21 12:27:21 +00:00
|
|
|
elif user.password_has_expired:
|
2019-11-05 10:46:29 +00:00
|
|
|
return None, errors.reason_password_expired
|
2019-08-21 12:27:21 +00:00
|
|
|
|
2019-12-09 08:12:48 +00:00
|
|
|
return user, ''
|