diff --git a/src/IDF/Form/Register.php b/src/IDF/Form/Register.php new file mode 100644 index 0000000..042c1cb --- /dev/null +++ b/src/IDF/Form/Register.php @@ -0,0 +1,111 @@ +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.')); + } + } +} diff --git a/src/IDF/Views.php b/src/IDF/Views.php index fb90764..ab201ac 100644 --- a/src/IDF/Views.php +++ b/src/IDF/Views.php @@ -48,6 +48,13 @@ class IDF_Views */ 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')); } @@ -61,4 +68,31 @@ class IDF_Views 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); + } } \ No newline at end of file diff --git a/src/IDF/conf/views.php b/src/IDF/conf/views.php index eccd4dc..ef8c433 100644 --- a/src/IDF/conf/views.php +++ b/src/IDF/conf/views.php @@ -36,6 +36,12 @@ $ctl[] = array('regex' => '#^/login/$#', '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, diff --git a/src/IDF/templates/issues/create.html b/src/IDF/templates/issues/create.html index 6d315b2..f3f8b63 100644 --- a/src/IDF/templates/issues/create.html +++ b/src/IDF/templates/issues/create.html @@ -64,9 +64,10 @@
{trans 'Be sure to provide a valid email address, as we are sending a validation link by email.'}
+ +{trans 'Did you know?'}
+{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 let us know about your issues at anytime!{/blocktrans}
+