|
|
|
@ -1,13 +1,18 @@
@@ -1,13 +1,18 @@
|
|
|
|
|
import colander |
|
|
|
|
import deform |
|
|
|
|
|
|
|
|
|
from ordr2.models import Role |
|
|
|
|
|
|
|
|
|
from . import CSRFSchema |
|
|
|
|
from .helpers import ( |
|
|
|
|
deferred_unique_email_validator, |
|
|
|
|
deferred_unique_username_validator |
|
|
|
|
deferred_unique_username_validator, |
|
|
|
|
deferred_password_validator |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ROLES = [(role.name, role.value.capitalize()) for role in Role] |
|
|
|
|
|
|
|
|
|
# schema for user registration |
|
|
|
|
|
|
|
|
|
class RegistrationSchema(CSRFSchema): |
|
|
|
@ -45,3 +50,89 @@ class RegistrationSchema(CSRFSchema):
@@ -45,3 +50,89 @@ class RegistrationSchema(CSRFSchema):
|
|
|
|
|
settings.update(override) |
|
|
|
|
return super().as_form(request, **settings) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# schema for user settings |
|
|
|
|
|
|
|
|
|
class UserSchema(CSRFSchema): |
|
|
|
|
''' user settings schema ''' |
|
|
|
|
|
|
|
|
|
user_name = colander.SchemaNode( |
|
|
|
|
colander.String(), |
|
|
|
|
widget=deform.widget.TextInputWidget( |
|
|
|
|
template='textinput_disabled.pt' |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
first_name = colander.SchemaNode( |
|
|
|
|
colander.String() |
|
|
|
|
) |
|
|
|
|
last_name = colander.SchemaNode( |
|
|
|
|
colander.String() |
|
|
|
|
) |
|
|
|
|
email = colander.SchemaNode( |
|
|
|
|
colander.String(), |
|
|
|
|
validator=deferred_unique_email_validator |
|
|
|
|
) |
|
|
|
|
role = colander.SchemaNode( |
|
|
|
|
colander.String(), |
|
|
|
|
widget=deform.widget.SelectWidget(values=ROLES) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def as_form(cls, request, **override): |
|
|
|
|
settings = { |
|
|
|
|
'buttons': ('Save changes', 'Cancel'), |
|
|
|
|
'css_class': 'form-horizontal', |
|
|
|
|
} |
|
|
|
|
settings.update(override) |
|
|
|
|
return super().as_form(request, **settings) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChangePasswordSchema(CSRFSchema): |
|
|
|
|
''' change password of an account ''' |
|
|
|
|
|
|
|
|
|
new_password = colander.SchemaNode( |
|
|
|
|
colander.String(), |
|
|
|
|
widget=deform.widget.CheckedPasswordWidget(), |
|
|
|
|
missing='' |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def as_form(cls, request, **override): |
|
|
|
|
settings = { |
|
|
|
|
'buttons': ('Change Password', 'Cancel'), |
|
|
|
|
'css_class': 'form-horizontal' |
|
|
|
|
} |
|
|
|
|
settings.update(override) |
|
|
|
|
return super().as_form(request, **settings) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConfirmSettingsSchema(CSRFSchema): |
|
|
|
|
''' confirm changes with current password ''' |
|
|
|
|
|
|
|
|
|
current_password = colander.SchemaNode( |
|
|
|
|
colander.String(), |
|
|
|
|
widget=deform.widget.PasswordWidget(), |
|
|
|
|
description='Enter your current password to confirm changes', |
|
|
|
|
validator=deferred_password_validator |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SettingsSchema(CSRFSchema): |
|
|
|
|
general = UserSchema() |
|
|
|
|
change_password = ChangePasswordSchema() |
|
|
|
|
confirm_changes = ConfirmSettingsSchema() |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def as_form(cls, request, **override): |
|
|
|
|
settings = { |
|
|
|
|
'buttons': ('Save Settings', 'Cancel'), |
|
|
|
|
'css_class': 'form-horizontal user-settings' |
|
|
|
|
} |
|
|
|
|
settings.update(override) |
|
|
|
|
form = super().as_form(request, **settings) |
|
|
|
|
# disable the role field for user settings |
|
|
|
|
form['general']['role'].widget.template='select_disabled.pt' |
|
|
|
|
form['general']['role'].widget=deform.widget.TextInputWidget( |
|
|
|
|
template='textinput_disabled.pt' |
|
|
|
|
) |
|
|
|
|
return form |
|
|
|
|