diff --git a/ordr2/schemas/account.py b/ordr2/schemas/account.py
index 2fe4ece..10b97a7 100644
--- a/ordr2/schemas/account.py
+++ b/ordr2/schemas/account.py
@@ -12,8 +12,9 @@ class RegistrationSchema(CSRFSchema):
user_name = colander.SchemaNode(
colander.String(),
- widget=deform.widget.TextInputWidget(disabled=True),
- description='automagically generated for you'
+ widget=deform.widget.TextInputWidget(),
+ description='automagically generated for you',
+ missing=''
)
first_name = colander.SchemaNode(
colander.String()
@@ -34,7 +35,7 @@ class RegistrationSchema(CSRFSchema):
def as_form(cls, request, **override):
settings = {
'buttons': ('Create Account', 'Cancel'),
- 'css_class': 'form-horizontal'
+ 'css_class': 'form-horizontal registration'
}
settings.update(override)
return super().as_form(request, **settings)
diff --git a/ordr2/templates/account/register_sucessful.jinja2 b/ordr2/templates/account/register_sucessful.jinja2
new file mode 100644
index 0000000..32abf8d
--- /dev/null
+++ b/ordr2/templates/account/register_sucessful.jinja2
@@ -0,0 +1,32 @@
+{% extends "ordr2:templates/layout.jinja2" %}
+{% import 'ordr2:templates/macros.jinja2' as macros with context %}
+
+{% block subtitle %} Register {% endblock subtitle %}
+
+{% block content %}
+
+
+
+
+
+
+
+ Registration successful!!
+
+
+
+
+ {{ macros.flash_messages() }}
+
+
Not so fast!
+
+ Before you can log in your account has first to be activated by an admin.
+ So lean back and read through the FAQ Page.
+ Maybe the information will help you use this software better.
+
+
+
+
+
+
+{% endblock content %}
diff --git a/ordr2/templates/deform/mapping_item.pt b/ordr2/templates/deform/mapping_item.pt
index 11eccc6..2a9585b 100644
--- a/ordr2/templates/deform/mapping_item.pt
+++ b/ordr2/templates/deform/mapping_item.pt
@@ -6,7 +6,7 @@
category category|field.widget.category;
structural hidden or category == 'structural';
required required|field.required;"
- class="control-group ${field.error and 'has-error' or ''} ${field.widget.item_css_class or ''} ${field.default_item_css_class()}"
+ class="control-group ${field.error and 'error' or ''} ${field.widget.item_css_class or ''} ${field.default_item_css_class()}"
title="${description}"
id="item-${oid}"
tal:omit-tag="structural"
diff --git a/ordr2/views/account.py b/ordr2/views/account.py
index 065fa2b..e989e84 100644
--- a/ordr2/views/account.py
+++ b/ordr2/views/account.py
@@ -1,9 +1,11 @@
+import deform
+
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render
from pyramid.security import remember, forget
from pyramid.view import view_config
-from ordr2.models import User
+from ordr2.models import User, Role
from ordr2.schemas.account import RegistrationSchema
# user log in and log out
@@ -76,9 +78,73 @@ def logout(context, request):
context='ordr2:resources.Account',
name='register',
permission='register',
+ request_method='GET',
renderer='ordr2:templates/account/register.jinja2'
)
def registration_form(context, request):
+ ''' display a registration form '''
+
context.nav_highlight = 'register'
form = RegistrationSchema.as_form(request)
return {'form': form}
+
+
+@view_config(
+ context='ordr2:resources.Account',
+ name='register',
+ permission='register',
+ request_method='POST',
+ renderer='ordr2:templates/account/register.jinja2'
+ )
+def registration_form_processing(context, request):
+ ''' process a submitted registration form '''
+
+ if 'Cancel' in request.POST:
+ return HTTPFound(request.resource_path(request.root))
+
+ form = RegistrationSchema.as_form(request)
+ data = request.POST.items()
+ try:
+ appstruct = form.validate(data)
+ except deform.ValidationFailure as e:
+ context.nav_highlight = 'register'
+ return {'form': form}
+
+ # form validation successfull, create user
+ print('USER', appstruct['user_name'])
+ print('POST', list(request.POST.items()))
+ account = User(
+ user_name=appstruct['user_name'],
+ first_name=appstruct['first_name'],
+ last_name=appstruct['last_name'],
+ email=appstruct['email'],
+ role=Role.NEW
+ )
+ account.set_password(appstruct['password'])
+ request.dbsession.add(account)
+
+ request.flash(
+ 'success',
+ 'Your account {} has been created.'.format(account.user_name),
+ dismissable=False
+ )
+ if len(appstruct['password']) < 8:
+ request.flash(
+ 'warning',
+ 'You should really consider using a longer password.',
+ dismissable=False
+ )
+
+
+ return HTTPFound(request.resource_path(context, 'registered'))
+
+
+@view_config(
+ context='ordr2:resources.Account',
+ name='registered',
+ permission='register',
+ renderer='ordr2:templates/account/register_sucessful.jinja2'
+ )
+def registration_sucessful(context, request):
+ ''' registration was sucessfull '''
+ return {}