Browse Source

finished first version of registration form

php2python
Holger Frey 7 years ago
parent
commit
ee9df92675
  1. 7
      ordr2/schemas/account.py
  2. 32
      ordr2/templates/account/register_sucessful.jinja2
  3. 2
      ordr2/templates/deform/mapping_item.pt
  4. 68
      ordr2/views/account.py

7
ordr2/schemas/account.py

@ -12,8 +12,9 @@ class RegistrationSchema(CSRFSchema):
user_name = colander.SchemaNode( user_name = colander.SchemaNode(
colander.String(), colander.String(),
widget=deform.widget.TextInputWidget(disabled=True), widget=deform.widget.TextInputWidget(),
description='automagically generated for you' description='automagically generated for you',
missing=''
) )
first_name = colander.SchemaNode( first_name = colander.SchemaNode(
colander.String() colander.String()
@ -34,7 +35,7 @@ class RegistrationSchema(CSRFSchema):
def as_form(cls, request, **override): def as_form(cls, request, **override):
settings = { settings = {
'buttons': ('Create Account', 'Cancel'), 'buttons': ('Create Account', 'Cancel'),
'css_class': 'form-horizontal' 'css_class': 'form-horizontal registration'
} }
settings.update(override) settings.update(override)
return super().as_form(request, **settings) return super().as_form(request, **settings)

32
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 %}
<div class="content">
<div class="container">
<div class="row">
<div class="span12">
<hgroup id="register-successful">
<h1>Registration successful!!</h1>
</hgroup>
</div>
<div class="span10 offset1">
{{ macros.flash_messages() }}
<div class="alert block-alert success-alert">
<h4 class="alert-heading">Not so fast!</h4>
<p>
Before you can log in your account has first to be activated by an admin.
So lean back and read through the <a href="{{ request.resource_url(request.root, 'faq') }}">FAQ Page</a>.
Maybe the information will help you use this software better.
</p>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}

2
ordr2/templates/deform/mapping_item.pt

@ -6,7 +6,7 @@
category category|field.widget.category; category category|field.widget.category;
structural hidden or category == 'structural'; structural hidden or category == 'structural';
required required|field.required;" 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}" title="${description}"
id="item-${oid}" id="item-${oid}"
tal:omit-tag="structural" tal:omit-tag="structural"

68
ordr2/views/account.py

@ -1,9 +1,11 @@
import deform
from pyramid.httpexceptions import HTTPFound from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render 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.models import User from ordr2.models import User, Role
from ordr2.schemas.account import RegistrationSchema from ordr2.schemas.account import RegistrationSchema
# user log in and log out # user log in and log out
@ -76,9 +78,73 @@ def logout(context, request):
context='ordr2:resources.Account', context='ordr2:resources.Account',
name='register', name='register',
permission='register', permission='register',
request_method='GET',
renderer='ordr2:templates/account/register.jinja2' renderer='ordr2:templates/account/register.jinja2'
) )
def registration_form(context, request): def registration_form(context, request):
''' display a registration form '''
context.nav_highlight = 'register' context.nav_highlight = 'register'
form = RegistrationSchema.as_form(request) form = RegistrationSchema.as_form(request)
return {'form': form} 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 <em>{}</em> 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 {}