Browse Source

added user registration schema

master
Holger Frey 7 years ago
parent
commit
16516be8ef
  1. 50
      ordr2/schemas/account.py
  2. 22
      ordr2/templates/deform/readonly/textinput.pt

50
ordr2/schemas/account.py

@ -0,0 +1,50 @@
import colander
import deform
from ordr2.models import Role
from . import CSRFSchema
from .helpers import (
deferred_unique_email_validator,
deferred_unique_username_validator,
deferred_password_validator
)
# schema for user registration
class RegistrationSchema(CSRFSchema):
''' new user registration '''
username = colander.SchemaNode(
colander.String(),
widget=deform.widget.TextInputWidget(
readonly=True
),
description='automagically generated for you',
validator = deferred_unique_username_validator,
)
first_name = colander.SchemaNode(
colander.String()
)
last_name = colander.SchemaNode(
colander.String()
)
email = colander.SchemaNode(
colander.String(),
validator=deferred_unique_email_validator
)
password = colander.SchemaNode(
colander.String(),
widget=deform.widget.CheckedPasswordWidget()
)
@classmethod
def as_form(cls, request, **override):
settings = {
'buttons': ('Create Account', 'Cancel'),
'css_class': 'form registration'
}
settings.update(override)
return super().as_form(request, **settings)

22
ordr2/templates/deform/readonly/textinput.pt

@ -0,0 +1,22 @@
<span tal:define="name name|field.name;
css_class css_class|field.widget.css_class;
oid oid|field.oid;
mask mask|field.widget.mask;
mask_placeholder mask_placeholder|field.widget.mask_placeholder;
style style|field.widget.style;
"
tal:omit-tag="">
<input type="text" name="${name}" value="${cstruct}"
tal:attributes="class string: form-control ${css_class or ''};
style style"
id="${oid}"
readonly="readonly"/>
<script tal:condition="mask" type="text/javascript">
deform.addCallback(
'${oid}',
function (oid) {
$("#" + oid).mask("${mask}",
{placeholder:"${mask_placeholder}"});
});
</script>
</span>