Revision 1808f7bc snf-astakos-app/astakos/im/management/commands/user-add.py
b/snf-astakos-app/astakos/im/management/commands/user-add.py | ||
---|---|---|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
1 |
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
|
|
2 | 2 |
# |
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
... | ... | |
40 | 40 |
from django.core.exceptions import ValidationError |
41 | 41 |
|
42 | 42 |
from astakos.im.models import AstakosUser, get_latest_terms |
43 |
from astakos.im.auth import make_local_user |
|
43 | 44 |
|
44 | 45 |
|
45 | 46 |
class Command(BaseCommand): |
... | ... | |
84 | 85 |
except ValidationError: |
85 | 86 |
raise CommandError("Invalid email") |
86 | 87 |
|
87 |
if get_latest_terms() is not None: |
|
88 |
has_signed_terms = False |
|
89 |
date_signed_terms = None |
|
90 |
else: |
|
91 |
has_signed_terms = True |
|
92 |
date_signed_terms = datetime.now() |
|
88 |
has_signed_terms = not(get_latest_terms()) |
|
93 | 89 |
|
94 | 90 |
try: |
95 |
u = AstakosUser(email=email, |
|
96 |
first_name=first_name, |
|
97 |
last_name=last_name, |
|
98 |
has_signed_terms=has_signed_terms, |
|
99 |
date_signed_terms=date_signed_terms, |
|
100 |
is_superuser=options['is_superuser']) |
|
101 |
u.set_password(password) |
|
102 |
u.save() |
|
91 |
user = make_local_user( |
|
92 |
email, first_name=first_name, last_name=last_name, |
|
93 |
password=password, has_signed_terms=has_signed_terms) |
|
94 |
if options['is_superuser']: |
|
95 |
user.is_superuser = True |
|
96 |
user.save() |
|
103 | 97 |
|
104 | 98 |
except BaseException, e: |
105 | 99 |
raise CommandError(e) |
... | ... | |
111 | 105 |
self.stdout.write('\n') |
112 | 106 |
|
113 | 107 |
try: |
114 |
u.add_auth_provider('local') |
|
115 |
map(u.add_permission, options['permissions']) |
|
116 |
map(u.add_group, options['groups']) |
|
108 |
map(user.add_permission, options['permissions']) |
|
109 |
map(user.add_group, options['groups']) |
|
117 | 110 |
except BaseException, e: |
118 | 111 |
raise CommandError(e) |
Also available in: Unified diff