Indefero

Indefero Commit Details


Date:2008-07-29 15:33:13 (16 years 4 months ago)
Author:Loic d'Anterroches
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, newdiff, release-1.1, release-1.2, release-1.3, svn
Commit:416d13e249da7d8717ebb15966b9dbbd5c0188ba
Parents: c50e218704dcc81eb346cc757e4c1bdbd0808d8b
Message:Added the registration form.

Still need a lot :)
Changes:

File differences

src/IDF/Form/Register.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 CĂ©ondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Create a new user account.
*
*/
class IDF_Form_Register extends Pluf_Form
{
public function initFields($extra=array())
{
$login = '';
if (isset($extra['initial']['login'])) {
$login = $extra['initial']['login'];
}
$this->fields['login'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Your login'),
'max_length' => 8,
'min_length' => 3,
'initial' => $login,
'help_text' => __('The login must be between 3 and 8 characters long and contains only letters and digits.'),
'widget_attrs' => array(
'maxlength' => 8,
'size' => 10,
),
));
$this->fields['email'] = new Pluf_Form_Field_Email(
array('required' => true,
'label' => __('Your email'),
'initial' => '',
'help_text' => __('We will never send you any unsolicited emails. We hate spams too!'),
));
$this->fields['terms'] = new Pluf_Form_Field_Boolean(
array('required' => true,
'label' => __('I agree to the terms and conditions.'),
'initial' => '',
));
}
/**
* Validate the interconnection in the form.
*/
public function clean_login()
{
$this->cleaned_data['login'] = mb_strtolower(trim($this->cleaned_data['login']));
$guser = new Pluf_User();
$sql = new Pluf_SQL('login=%s', $this->cleaned_data['login']);
if ($guser->getCount(array('filter' => $sql->gen())) > 0) {
throw new Pluf_Form_Invalid(sprintf(__('The login "%s" is already used, please find another one.'), $this->cleaned_data['login']));
}
return $this->cleaned_data['login'];
}
/**
* Check the terms.
*/
public function clean_terms()
{
if (!$this->cleaned_data['terms']) {
throw new Pluf_Form_Invalid(__('We know, this is boring, but you need to agree with the terms and conditions.'));
}
return $this->cleaned_data['terms'];
}
function clean_email()
{
$this->cleaned_data['email'] = mb_strtolower(trim($this->cleaned_data['email']));
$guser = new Pluf_User();
$sql = new Pluf_SQL('email=%s', $this->cleaned_data['email']);
if ($guser->getCount(array('filter' => $sql->gen())) > 0) {
throw new Pluf_Form_Invalid(sprintf(__('The email "%s" is already used. If you need, click on the help link to recover your password.'), $this->cleaned_data['email']));
}
return $this->cleaned_data['email'];
}
/**
* Save the model in the database.
*
* @param bool Commit in the database or not. If not, the object
* is returned but not saved in the database.
* @return Object Model with data set from the form.
*/
function save($commit=true)
{
if (!$this->isValid()) {
throw new Exception(__('Cannot save the model from an invalid form.'));
}
}
}
src/IDF/Views.php
4848
4949
5050
51
52
53
54
55
56
57
5158
5259
5360
......
6168
6269
6370
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
6498
*/
public function login($request, $match)
{
if (isset($request->POST['action'])
and $request->POST['action'] == 'new-user') {
$login = (isset($request->POST['login'])) ? $request->POST['login'] : '';
$url = Pluf_HTTP_URL_urlForView('IDF_Views::register', array(),
array('login' => $login));
return new Pluf_HTTP_Response_Redirect($url);
}
$v = new Pluf_Views();
return $v->login($request, $match, Pluf::f('login_success_url'));
}
return $views->logout($request, $match, Pluf::f('after_logout_page'));
}
/**
* Registration.
*
* We just ask for login, email and to agree with the terms. Then,
* we go ahead and send a confirmation email. The confirmation
* email will allow to set the password, first name and last name
* of the user.
*/
function register($request, $match)
{
$title = __('Create Your Account');
if ($request->method == 'POST') {
$form = new IDF_Form_Register($request->POST);
if ($form->isValid()) {
$user = $form->save();
$url = Pluf_HTTP_URL_urlForView('IDF_Views::registerConfirmation');
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$init = (isset($request->GET['login'])) ? array('initial' => array('login' => $request->GET['login'])) : array();
$form = new IDF_Form_Register(null, $init);
}
return Pluf_Shortcuts_RenderToResponse('register.html',
array('page_title' => $title,
'form' => $form),
$request);
}
}
src/IDF/conf/views.php
3636
3737
3838
39
40
41
42
43
44
3945
4046
4147
'model' => 'IDF_Views',
'method' => 'login');
$ctl[] = array('regex' => '#^/register/$#',
'base' => $base,
'priority' => 4,
'model' => 'IDF_Views',
'method' => 'register');
$ctl[] = array('regex' => '#^/logout/$#',
'base' => $base,
'priority' => 4,
src/IDF/templates/issues/create.html
6464
6565
6666
67
68
6769
6870
6971
70
71
72
7273
<li><strong>Do not provide any password or confidential information!</strong></li>
</ul>{/blocktrans}
</div>
{/block}
{block javascript}
<script type="text/javascript">
document.getElementById('id_summary').focus()
</script>
{/block}
{block javascript}{include 'issues/js-autocomplete.html'}{/block}
{include 'issues/js-autocomplete.html'}{/block}
src/IDF/templates/register.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{extends "base-simple.html"}
{block body}
{if $form.errors}
<div class="px-message-error">
<p>{trans 'Oups, please check the provided login and email address to register.'}</p>
{if $form.get_top_errors}
{$form.render_top_errors|unsafe}
{/if}
</div>
{/if}
<form method="post" action=".">
<table class="form" summary="">
<tr>
<th><strong>{$form.f.login.labelTag}:</strong></th>
<td>{if $form.f.login.errors}{$form.f.login.fieldErrors}{/if}
{$form.f.login|unsafe}<br />
<span class="helptext">{$form.f.login.help_text}</span>
</td>
</tr>
<tr>
<th><strong>{$form.f.email.labelTag}:</strong></th>
<td>{if $form.f.email.errors}{$form.f.email.fieldErrors}{/if}
{$form.f.email|unsafe}<br />
<span class="helptext">{$form.f.email.help_text}</span>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
{if $form.f.terms.errors}{$form.f.terms.fieldErrors}{/if}
{$form.f.terms|unsafe} <strong>{$form.f.terms.labelTag}</strong><br />
<span class="helptext">{blocktrans}Read the <a href="#">terms and conditions</a> (basically <em>"Please be nice, we respect you.")</em>{/blocktrans}</span>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="{trans 'Create Your Account'}" name="submit" /> | <a href="{url 'IDF_Views::index'}">{trans 'Cancel'}</a>
</td>
</tr>
</table>
</form>
{/block}
{block context}
<div class="issue-submit-info">
<p>{trans 'Be sure to provide a valid email address, as we are sending a validation link by email.'}</p>
<p><strong>{trans 'Did you know?'}</strong><br />
{aurl 'url', 'IDF_Views::faq'}
{blocktrans}With your account, you will able to participate in the life of all the projects hosted here. Participating in a software project must be fun, so if you have troubles, you can <a href="{$url}">let us know about your issues at anytime</a>!{/blocktrans}
</div>
<script type="text/javascript">
document.getElementById('id_login').focus()
</script>
{/block}
{block javascript}{include 'issues/js-autocomplete.html'}{/block}

Archive Download the corresponding diff file

Page rendered in 0.09279s using 13 queries.