|
|
@ -5,6 +5,7 @@ from pyramid.renderers import render |
|
|
|
from pyramid.security import remember, forget |
|
|
|
from pyramid.security import remember, forget |
|
|
|
from pyramid.view import view_config |
|
|
|
from pyramid.view import view_config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ordr2.events import AccountActivation, PasswordReset |
|
|
|
from ordr2.models import User, Role |
|
|
|
from ordr2.models import User, Role |
|
|
|
from ordr2.schemas.account import UserSchema |
|
|
|
from ordr2.schemas.account import UserSchema |
|
|
|
|
|
|
|
|
|
|
@ -66,6 +67,7 @@ def change_column_view(context, request): |
|
|
|
renderer='ordr2:templates/admin/user_edit.jinja2' |
|
|
|
renderer='ordr2:templates/admin/user_edit.jinja2' |
|
|
|
) |
|
|
|
) |
|
|
|
def user_account_form(context, request): |
|
|
|
def user_account_form(context, request): |
|
|
|
|
|
|
|
''' display the user edit form ''' |
|
|
|
form = UserSchema.as_form(request) |
|
|
|
form = UserSchema.as_form(request) |
|
|
|
form_data = { |
|
|
|
form_data = { |
|
|
|
'user_name': context.model.user_name, |
|
|
|
'user_name': context.model.user_name, |
|
|
@ -79,34 +81,55 @@ def user_account_form(context, request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
@view_config( |
|
|
|
context='ordr2:resources.Account', |
|
|
|
context='ordr2:resources.UserAccount', |
|
|
|
name='settingsx', |
|
|
|
permission='edit', |
|
|
|
permission='settings', |
|
|
|
|
|
|
|
request_method='POST', |
|
|
|
request_method='POST', |
|
|
|
renderer='ordr2:templates/account/settings.jinja2' |
|
|
|
renderer='ordr2:templates/admin/user_edit.jinja2' |
|
|
|
) |
|
|
|
) |
|
|
|
def settingsx_form_processing(context, request): |
|
|
|
def user_account_form_processing(context, request): |
|
|
|
''' display the user settings form ''' |
|
|
|
''' process the user edit form ''' |
|
|
|
|
|
|
|
|
|
|
|
form = SettingsSchema.as_form(request) |
|
|
|
form = UserSchema.as_form(request) |
|
|
|
data = request.POST.items() |
|
|
|
data = request.POST.items() |
|
|
|
|
|
|
|
if 'delete' in request.POST: |
|
|
|
|
|
|
|
return HTTPFound(request.resource_url(context, 'delete')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif 'save' in request.POST: |
|
|
|
try: |
|
|
|
try: |
|
|
|
appstruct = form.validate(data) |
|
|
|
appstruct = form.validate(data) |
|
|
|
except deform.ValidationFailure as e: |
|
|
|
except deform.ValidationFailure as e: |
|
|
|
return {'form': form} |
|
|
|
return {'form': form} |
|
|
|
|
|
|
|
|
|
|
|
# form validation sucessful, change settings |
|
|
|
# form validation sucessful, change settings |
|
|
|
request.user.first_name = appstruct['general']['first_name'] |
|
|
|
was_active = context.model.is_active |
|
|
|
request.user.last_name = appstruct['general']['last_name'] |
|
|
|
context.model.first_name = appstruct['first_name'] |
|
|
|
request.user.email = appstruct['general']['email'] |
|
|
|
context.model.last_name = appstruct['last_name'] |
|
|
|
if appstruct['change_password']['new_password']: |
|
|
|
context.model.email = appstruct['email'] |
|
|
|
request.user.set_password(appstruct['change_password']['new_password']) |
|
|
|
context.model.role = Role[appstruct['role']] |
|
|
|
if len(appstruct['change_password']['new_password']) < 8: |
|
|
|
|
|
|
|
request.flash( |
|
|
|
if not was_active and context.model.is_active: |
|
|
|
'warning', |
|
|
|
# user account was activated, notify user |
|
|
|
'You should really consider using a longer password.' |
|
|
|
event = AccountActivation(request, context.model) |
|
|
|
|
|
|
|
request.registry.notify(event) |
|
|
|
|
|
|
|
text = 'An activation email was sent to <em>{}</em>'.format( |
|
|
|
|
|
|
|
appstruct['email'] |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
text = '' |
|
|
|
|
|
|
|
|
|
|
|
request.flash('success', 'Your account information has been updated.') |
|
|
|
msg = 'User account <em>{}</em> updated.'.format( |
|
|
|
|
|
|
|
context.model.user_name |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
request.flash('success', msg, text) |
|
|
|
|
|
|
|
|
|
|
|
return {'form': form} |
|
|
|
elif 'reset' in request.POST: |
|
|
|
|
|
|
|
token = context.model.generate_password_token() |
|
|
|
|
|
|
|
event = PasswordReset(request, context.model, token) |
|
|
|
|
|
|
|
request.registry.notify(event) |
|
|
|
|
|
|
|
msg = 'Password reset mail sent to {}.'.format(context.model.email) |
|
|
|
|
|
|
|
request.flash('success', msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif 'delete' in request.POST: |
|
|
|
|
|
|
|
return HTTPFound(context, 'delete') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HTTPFound(context.__parent__.url()) |
|
|
|