159 |
159 |
account.awaiting_confirmation = False
|
160 |
160 |
account.store()
|
161 |
161 |
|
162 |
|
if account.awaiting_moderation:
|
163 |
|
r += TextsDirectory.get_html_text('account-created-waiting-activation')
|
164 |
|
else:
|
165 |
|
r += TextsDirectory.get_html_text('account-created')
|
166 |
|
passwords_cfg = get_cfg('passwords', {})
|
167 |
|
if passwords_cfg.get('can_change', False):
|
168 |
|
# TODO: offer a chance to change password ?
|
169 |
|
pass
|
|
162 |
r += TextsDirectory.get_html_text('account-created')
|
|
163 |
passwords_cfg = get_cfg('passwords', {})
|
|
164 |
if passwords_cfg.get('can_change', False):
|
|
165 |
# TODO: offer a chance to change password ?
|
|
166 |
pass
|
170 |
167 |
|
171 |
168 |
identities_cfg = get_cfg('identities', {})
|
172 |
169 |
if identities_cfg.get('notify-on-register', False):
|
... | ... | |
225 |
222 |
r += form.render()
|
226 |
223 |
r += htmltext('</div>')
|
227 |
224 |
|
228 |
|
if identities_cfg.get('creation') in ('self', 'moderated'):
|
|
225 |
if identities_cfg.get('creation') == 'self':
|
229 |
226 |
r += htmltext('<div id="register">')
|
230 |
227 |
ident_methods = get_cfg('identification', {}).get('methods', [])
|
231 |
228 |
if len(ident_methods) > 1:
|
... | ... | |
264 |
261 |
|
265 |
262 |
def login_submit_account_user(self, account, user, form=None):
|
266 |
263 |
|
267 |
|
if account.awaiting_moderation:
|
268 |
|
if form:
|
269 |
|
form.set_error('username', _('This account is waiting for moderation'))
|
270 |
|
return
|
271 |
|
|
272 |
264 |
if account.awaiting_confirmation:
|
273 |
265 |
if form:
|
274 |
266 |
form.set_error('username', _('This account is waiting for confirmation'))
|
... | ... | |
582 |
574 |
if password:
|
583 |
575 |
account.set_password(password)
|
584 |
576 |
account.user_id = user.id
|
585 |
|
if identities_cfg.get('creation') == 'moderated':
|
586 |
|
account.awaiting_moderation = True
|
587 |
577 |
|
588 |
578 |
if identities_cfg.get('email-confirmation', False):
|
589 |
579 |
if not user.email:
|
... | ... | |
599 |
589 |
if identities_cfg.get('notify-on-register', False):
|
600 |
590 |
notify_admins_user_registered(account)
|
601 |
591 |
|
602 |
|
if account.awaiting_moderation:
|
603 |
|
return self.moderation_notification()
|
604 |
|
|
605 |
592 |
if passwords_cfg.get('generate', True):
|
606 |
593 |
if not user.email:
|
607 |
594 |
get_logger().error(
|
... | ... | |
621 |
608 |
# XXX: display a message instead of immediate redirect ?
|
622 |
609 |
return redirect(get_publisher().get_root_url() + 'login/')
|
623 |
610 |
|
624 |
|
def moderation_notification(self):
|
625 |
|
template.html_top(_('Account created, waiting for moderation'))
|
626 |
|
r = TemplateIO(html=True)
|
627 |
|
|
628 |
|
r += htmltext('<div class="ident-content">')
|
629 |
|
r += htmltext('<p>')
|
630 |
|
r += _('A site administrator will now review then activate your account.')
|
631 |
|
r += htmltext('</p>')
|
632 |
|
|
633 |
|
r += htmltext('<p>')
|
634 |
|
r += _('You will then get your password by email.')
|
635 |
|
r += htmltext('</p>')
|
636 |
|
|
637 |
|
r += htmltext('<p>')
|
638 |
|
r += htmltext('<a href="%s">%s</a>') % (get_publisher().get_root_url(), _('Back to home page'))
|
639 |
|
r += htmltext('</p>')
|
640 |
|
r += htmltext('</div>')
|
641 |
|
|
642 |
|
return r.getvalue()
|
643 |
|
|
644 |
611 |
def confirmation_notification(self, account, user, password):
|
645 |
612 |
self.email_confirmation_notification(account, user, password)
|
646 |
613 |
|
... | ... | |
767 |
734 |
value = identities_cfg.get('creation', 'admin'),
|
768 |
735 |
options = [(str('admin'), _('Site Administrator')),
|
769 |
736 |
(str('self'), _('Self-registration')),
|
770 |
|
(str('moderated'), _('Moderated user registration'))])
|
|
737 |
])
|
771 |
738 |
form.add(CheckboxWidget, 'email-confirmation',
|
772 |
739 |
title = _('Require email confirmation for new accounts'),
|
773 |
740 |
value = identities_cfg.get('email-confirmation', False))
|
... | ... | |
1042 |
1009 |
autocomplete = 'off')
|
1043 |
1010 |
self.add(CheckboxWidget, 'awaiting_confirmation', value.get('awaiting_confirmation'),
|
1044 |
1011 |
title = _('Awaiting Confirmation'), required = False)
|
1045 |
|
self.add(CheckboxWidget, 'awaiting_moderation', value.get('awaiting_moderation'),
|
1046 |
|
title = _('Awaiting Moderation'), required = False)
|
1047 |
1012 |
self.add(CheckboxWidget, 'disabled', value.get('disabled'),
|
1048 |
1013 |
title = _('Disabled Account'), required = False)
|
1049 |
1014 |
|
... | ... | |
1051 |
1016 |
value = {
|
1052 |
1017 |
'username': self.get('username'),
|
1053 |
1018 |
'password': self.get('password'),
|
1054 |
|
'awaiting_moderation': self.get('awaiting_moderation'),
|
1055 |
1019 |
'awaiting_confirmation': self.get('awaiting_confirmation'),
|
1056 |
1020 |
'disabled': self.get('disabled'),
|
1057 |
1021 |
}
|
... | ... | |
1151 |
1115 |
account.hashing_algo = passwords_cfg.get('hashing_algo')
|
1152 |
1116 |
account.set_password(value.get('password'))
|
1153 |
1117 |
account.awaiting_confirmation = value.get('awaiting_confirmation')
|
1154 |
|
account.awaiting_moderation = value.get('awaiting_moderation')
|
1155 |
1118 |
account.disabled = value.get('disabled')
|
1156 |
1119 |
account.user_id = user.id
|
1157 |
1120 |
try:
|
... | ... | |
1178 |
1141 |
except KeyError:
|
1179 |
1142 |
return None
|
1180 |
1143 |
return {'username': account.id, 'password': account.password,
|
1181 |
|
'awaiting_moderation': account.awaiting_moderation,
|
1182 |
1144 |
'awaiting_confirmation': account.awaiting_confirmation,
|
1183 |
1145 |
'disabled': account.disabled,
|
1184 |
1146 |
}
|
1185 |
1147 |
|
1186 |
|
@classmethod
|
1187 |
|
def register(cls):
|
1188 |
|
rdb = get_publisher_class().backoffice_directory_class
|
1189 |
|
if rdb:
|
1190 |
|
rdb.register_directory('accounts', AccountsDirectory())
|
1191 |
|
|
1192 |
|
def menu_entry_check_display(k):
|
1193 |
|
identities_cfg = get_cfg('identities', {})
|
1194 |
|
if identities_cfg.get('creation') != 'moderated':
|
1195 |
|
return False
|
1196 |
|
user = get_request().user
|
1197 |
|
if not user:
|
1198 |
|
return False
|
1199 |
|
if not user.is_admin:
|
1200 |
|
return False
|
1201 |
|
return True
|
1202 |
|
|
1203 |
|
rdb.register_menu_item('accounts/', _('Accounts'),
|
1204 |
|
check_display_function=menu_entry_check_display)
|
1205 |
|
|
1206 |
1148 |
|
1207 |
1149 |
class AccountDirectory(Directory):
|
1208 |
1150 |
_q_exports = ['', 'accept', 'reject', 'email']
|
... | ... | |
1267 |
1209 |
else:
|
1268 |
1210 |
password = self.account.password
|
1269 |
1211 |
|
1270 |
|
self.account.awaiting_moderation = False
|
1271 |
1212 |
self.account.store()
|
1272 |
1213 |
|
1273 |
1214 |
try:
|
... | ... | |
1342 |
1283 |
|
1343 |
1284 |
|
1344 |
1285 |
|
1345 |
|
class AccountsDirectory(AccessControlled, Directory):
|
1346 |
|
_q_exports = ['']
|
1347 |
|
|
1348 |
|
def _q_access(self):
|
1349 |
|
user = get_request().user
|
1350 |
|
if not user:
|
1351 |
|
raise errors.AccessUnauthorizedError()
|
1352 |
|
if not user.is_admin:
|
1353 |
|
raise errors.AccessForbiddenError(
|
1354 |
|
public_msg = _('You are not allowed to access Accounts Management'),
|
1355 |
|
location_hint = 'backoffice')
|
1356 |
|
|
1357 |
|
get_response().breadcrumb.append(('accounts/', _('Accounts Management')))
|
1358 |
|
|
1359 |
|
def _q_index(self):
|
1360 |
|
html_top('accounts', _('Accounts Management'))
|
1361 |
|
r = TemplateIO(html=True)
|
1362 |
|
r += htmltext('<h2>%s</h2>') % _('New accounts waiting for moderation')
|
1363 |
|
|
1364 |
|
r += htmltext('<ul class="biglist">')
|
1365 |
|
for account in PasswordAccount.select(order_by = 'id'):
|
1366 |
|
if account.awaiting_confirmation:
|
1367 |
|
continue
|
1368 |
|
if not account.awaiting_moderation:
|
1369 |
|
continue
|
1370 |
|
if not account.user:
|
1371 |
|
# user has been removed; this is so wrong we remove account now
|
1372 |
|
account.remove_self()
|
1373 |
|
continue
|
1374 |
|
r += htmltext('<li>')
|
1375 |
|
r += htmltext('<strong class="label">%s</strong>') % account.user.display_name
|
1376 |
|
r += htmltext('<p class="details">')
|
1377 |
|
r += _('Username:')
|
1378 |
|
r += ' '
|
1379 |
|
r += account.id
|
1380 |
|
r += htmltext('</p>')
|
1381 |
|
|
1382 |
|
r += htmltext('<p class="commands">')
|
1383 |
|
r += command_icon('%s/' % account.id, 'view')
|
1384 |
|
if account.user.email:
|
1385 |
|
r += command_icon('%s/email' % account.id, 'email', label = _('Reply by email'))
|
1386 |
|
r += command_icon('%s/accept' % account.id, 'accept',
|
1387 |
|
label = _('Accept'), icon = 'stock_yes_16.png')
|
1388 |
|
r += command_icon('%s/reject' % account.id, 'reject',
|
1389 |
|
label = _('Reject'), icon = 'stock_no_16.png', popup = True)
|
1390 |
|
r += htmltext('</p>')
|
1391 |
|
r += htmltext('</li>')
|
1392 |
|
r += htmltext('</ul>')
|
1393 |
|
return r.getvalue()
|
1394 |
|
|
1395 |
|
def _q_lookup(self, component):
|
1396 |
|
try:
|
1397 |
|
account = PasswordAccount.get(component)
|
1398 |
|
except KeyError:
|
1399 |
|
return None
|
1400 |
|
return AccountDirectory(account)
|
1401 |
|
|
1402 |
1286 |
EmailsDirectory.register('password-subscription-notification',
|
1403 |
1287 |
N_('Subscription notification for password account'),
|
1404 |
1288 |
N_('Available variables: email, website, token_url, token, admin_email, username, password'),
|
... | ... | |
1536 |
1420 |
'''))
|
1537 |
1421 |
|
1538 |
1422 |
|
1539 |
|
TextsDirectory.register('account-created-waiting-activation',
|
1540 |
|
N_('Text when account confirmed by user but waiting moderator approval'),
|
1541 |
|
category = N_('Identification'),
|
1542 |
|
default = N_('''<p>
|
1543 |
|
Your account has been created. In order to be effective
|
1544 |
|
it must be activated by a moderator. You will receive an
|
1545 |
|
email when this is done.
|
1546 |
|
</p>'''))
|
1547 |
|
|
1548 |
1423 |
TextsDirectory.register('account-created',
|
1549 |
1424 |
N_('Text when account confirmed by user'),
|
1550 |
1425 |
category = N_('Identification'),
|
1551 |
|
-
|