22"""This file contains the actual implementation of the commands."""
33
44# Django imports
5+ from django .conf import settings
56from django .contrib .auth import get_user_model
67from django .core .management .base import CommandError
78from django .db .models import Count
@@ -12,6 +13,41 @@ def check_admin_notification(stdout):
1213 email addresses."""
1314 stdout .write ('[.] check_admin_notification()' )
1415
16+ user_model = get_user_model ()
17+
18+ # extract the list of usernames
19+ username_list = [x [0 ] for x in settings .DAE_ADMIN_SIGNUP_NOTIFICATION ]
20+
21+ # check, if all listed accounts have verified email addresses
22+ verified_email = (
23+ # get listed accounts
24+ user_model .objects .filter (
25+ # this really complex statement is used, to not reference the
26+ # 'username' field directly, to be as pluggable as possible
27+ ** {'{}__in' .format (user_model .USERNAME_FIELD ): username_list }
28+ )
29+ # this filter only delivers accounts with verified email addresses
30+ # TODO: restart development here! How to access the related objects
31+ # additional properties?
32+ .filter (user_model .enhancement .email_verification_status )
33+ )
34+
35+ # TODO: debug output, REMOVE ME!
36+ print (verified_email )
37+
38+ # determine, which accounts do have unverified email addresses
39+ if len (username_list ) > len (verified_email ):
40+ unverified_email = []
41+ for u in username_list :
42+ if u not in verified_email :
43+ unverified_email .append (u )
44+
45+ raise CommandError (
46+ "The following accounts do not have a verified email address: {}. "
47+ "Administrative notifications will only be sent to verfified email "
48+ "addresses."
49+ )
50+
1551
1652def check_email_uniqueness ():
1753 """This function checks, if all email addresses are unique."""
0 commit comments