source: trunk/register.php @ 25121

Last change on this file since 25121 was 25121, checked in by flop25, 11 years ago

bug:2948 The registration can be done without typing a password

The password is only mandatory on the public register page
Better error messages from admin/user_list.php

  • Property svn:eol-style set to LF
File size: 5.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24//----------------------------------------------------------- include
25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_FREE);
32
33//----------------------------------------------------------- user registration
34
35if (!$conf['allow_user_registration'])
36{
37  page_forbidden('User registration closed');
38}
39
40trigger_action('loc_begin_register');
41
42if (isset($_POST['submit']))
43{
44  if (!verify_ephemeral_key(@$_POST['key']))
45  {
46                set_status_header(403);
47    $page['errors'][] = l10n('Invalid/expired form key');
48  }
49
50  if(empty($_POST['password']))
51  {
52    $page['errors'][] = l10n('Password is missing. Please enter the password.');
53  }
54  else if(empty($_POST['password_conf']))
55  {
56    $page['errors'][] = l10n('Password confirmation is missing. Please confirm the chosen password.');
57  }
58  else if ($_POST['password'] != $_POST['password_conf'])
59  {
60    $page['errors'][] = l10n('The passwords do not match');
61  }
62
63  register_user($_POST['login'],
64                $_POST['password'],
65                $_POST['mail_address'],
66                true,
67                $page['errors']);
68
69  if (count($page['errors']) == 0)
70  {
71    // email notification
72    if (isset($_POST['send_password_by_mail']) and isset($_POST['mail_address']))
73    {
74      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
75           
76      $keyargs_content = array(
77        get_l10n_args('Hello %s,', $_POST['login']),
78        get_l10n_args('Thank you for registering at %s!', $conf['gallery_title']),
79        get_l10n_args('', ''),
80        get_l10n_args('Here are your connection settings', ''),
81        get_l10n_args('Username: %s', $_POST['login']),
82        get_l10n_args('Password: %s', $_POST['password']),
83        get_l10n_args('Email: %s', $_POST['mail_address']),
84        get_l10n_args('', ''),
85        get_l10n_args('If you think you\'ve received this email in error, please contact us at %s', get_webmaster_mail_address()),
86        );
87       
88      pwg_mail(
89        $_POST['mail_address'],
90        array(
91          'subject' => '['.$conf['gallery_title'].'] '.l10n('Registration'),
92          'content' => l10n_args($keyargs_content),
93          'content_format' => 'text/plain',
94          )
95        );
96       
97      $_SESSION['page_infos'][] = l10n('Successfully registered, you will soon receive an email with your connection settings. Welcome!');
98    }
99   
100    // log user and redirect
101    $user_id = get_userid($_POST['login']);
102    log_user($user_id, false);
103    redirect(make_index_url());
104  }
105        $registration_post_key = get_ephemeral_key(2);
106}
107else
108{
109        $registration_post_key = get_ephemeral_key(6);
110}
111
112$login = !empty($_POST['login'])?htmlspecialchars(stripslashes($_POST['login'])):'';
113$email = !empty($_POST['mail_address'])?htmlspecialchars(stripslashes($_POST['mail_address'])):'';
114
115//----------------------------------------------------- template initialization
116//
117// Start output of page
118//
119$title= l10n('Registration');
120$page['body_id'] = 'theRegisterPage';
121
122$template->set_filenames( array('register'=>'register.tpl') );
123$template->assign(array(
124  'U_HOME' => make_index_url(),
125        'F_KEY' => $registration_post_key,
126  'F_ACTION' => 'register.php',
127  'F_LOGIN' => $login,
128  'F_EMAIL' => $email,
129  'obligatory_user_mail_address' => $conf['obligatory_user_mail_address'],
130  ));
131
132// include menubar
133$themeconf = $template->get_template_vars('themeconf');
134if (!isset($themeconf['hide_menu_on']) OR !in_array('theRegisterPage', $themeconf['hide_menu_on']))
135{
136  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
137}
138
139include(PHPWG_ROOT_PATH.'include/page_header.php');
140trigger_action('loc_end_register');
141flush_page_messages();
142$template->parse('register');
143include(PHPWG_ROOT_PATH.'include/page_tail.php');
144?>
Note: See TracBrowser for help on using the repository browser.