~ubuntu-branches/debian/sid/ampache/sid

« back to all changes in this revision

Viewing changes to register.php

  • Committer: Package Import Robot
  • Author(s): Charlie Smotherman
  • Date: 2013-08-27 13:19:48 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20130827131948-1czew0zxn6u70dtv
Tags: 3.6-rzb2752+dfsg-1
* New upsteam snapshot.  Contains important bug fixes to the installer.
* Correct typo in ampache-common.postrm.
* Remove courtousy copy of php-getid3, during repack.  Closes: #701526
* Update package to use dh_linktree to make the needed sym links to the
  needed system libs that were removed during repack.
* Update debian/rules to reflect upstreams removing/moving of modules.
* Update debian/ampache-common.install to reflect upstreams removal of files.
* Updated to use new apache2.4 API. Closes: #669756
* Updated /debian/po/de.po thx David Prévot for the patch.  Closes:  #691963
* M3U import is now ordered, fixed upstream.  Closes: #684984
* Text input area has been resized so IPv6 addresses will now fit, fixed
  upstream.  Closes:  #716230
* Added ampache-common.preinst to make sure that the courtousy copies of code
  dirs are empty so dh_linktree can do it's magic on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
 
2
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
3
3
/**
4
 
 * Register
5
 
 *
6
4
 *
7
5
 * LICENSE: GNU General Public License, version 2 (GPLv2)
8
 
 * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
 
6
 * Copyright 2001 - 2013 Ampache.org
9
7
 *
10
8
 * This program is free software; you can redistribute it and/or
11
9
 * modify it under the terms of the GNU General Public License v2
20
18
 * along with this program; if not, write to the Free Software
21
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
20
 *
23
 
 * @package     Ampache
24
 
 * @copyright   2001 - 2011 Ampache.org
25
 
 * @license     http://opensource.org/licenses/gpl-2.0 GPLv2
26
 
 * @link        http://www.ampache.org/
27
21
 */
28
22
 
29
23
define('NO_SESSION','1');
31
25
 
32
26
/* Check Perms */
33
27
if (!Config::get('allow_public_registration') || Config::get('demo_mode')) {
34
 
        debug_event('DENIED','Error Attempted registration','1');
35
 
        access_denied();
36
 
        exit();
 
28
    debug_event('DENIED','Error Attempted registration','1');
 
29
    UI::access_denied();
 
30
    exit();
37
31
}
38
32
 
39
 
/**
40
 
 * These are only needed for this page so they aren't included in init.php
41
 
 * this is for email validation and the cool little graphic
42
 
*/
43
 
require_once Config::get('prefix') . '/modules/validatemail/validateEmailFormat.php';
44
 
require_once Config::get('prefix') . '/modules/validatemail/validateEmail.php';
45
 
 
46
33
/* Don't even include it if we aren't going to use it */
47
34
if (Config::get('captcha_public_reg')) {
48
 
        define ("CAPTCHA_INVERSE", 1);
49
 
        include Config::get('prefix') . '/modules/captcha/captcha.php';
 
35
    define ("CAPTCHA_INVERSE", 1);
 
36
    require_once Config::get('prefix') . '/modules/captcha/captcha.php';
50
37
}
51
38
 
52
39
 
53
40
/* Start switch based on action passed */
54
41
switch ($_REQUEST['action']) {
55
 
        case 'validate':
56
 
                $username       = scrub_in($_GET['username']);
57
 
                $validation     = scrub_in($_GET['auth']);
58
 
                require_once Config::get('prefix') . '/templates/show_user_activate.inc.php';
59
 
        break;
60
 
        case 'add_user':
61
 
                /**
62
 
                 * User information has been entered
63
 
                 * we need to check the database for possible existing username first
64
 
                 * if username exists, error and say "Please choose a different name."
65
 
                 * if username does not exist, insert user information into database
66
 
                 * then allow the user to 'click here to login'
67
 
                 * possibly by logging them in right then and there with their current info
68
 
                 * and 'click here to login' would just be a link back to index.php
69
 
                 */
70
 
                $fullname               = scrub_in($_POST['fullname']);
71
 
                $username               = scrub_in($_POST['username']);
72
 
                $email                  = scrub_in($_POST['email']);
73
 
                $pass1                  = scrub_in($_POST['password_1']);
74
 
                $pass2                  = scrub_in($_POST['password_2']);
75
 
 
76
 
                /* If we're using the captcha stuff */
77
 
                if (Config::get('captcha_public_reg')) {
78
 
                        $captcha                = captcha::solved();
79
 
                        if(!isset ($captcha)) {
80
 
                                Error::add('captcha', T_('Error Captcha Required'));
81
 
                        }
82
 
                        if (isset ($captcha)) {
83
 
                                if ($captcha) {
84
 
                                        $msg="SUCCESS";
85
 
                                }
86
 
                                else {
87
 
                                        Error::add('captcha', T_('Error Captcha Failed'));
88
 
                                }
89
 
                        } // end if we've got captcha
90
 
                } // end if it's enabled
91
 
 
92
 
                if (Config::get('user_agreement')) {
93
 
                        if (!$_POST['accept_agreement']) {
94
 
                                Error::add('user_agreement', T_("You <U>must</U> accept the user agreement"));
95
 
                        }
96
 
                } // if they have to agree to something
97
 
 
98
 
                if (!$_POST['username']) {
99
 
                        Error::add('username', T_("You did not enter a username"));
100
 
                }
101
 
 
102
 
                if(!$fullname) {
103
 
                        Error::add('fullname', T_("Please fill in your full name (Firstname Lastname)"));
104
 
                }
105
 
 
106
 
                /* Check the mail for correct address formation. */
107
 
                $attempt = 0;
108
 
                $max_attempts = 3;
109
 
                $response_code = "";
110
 
 
111
 
                while ( $response_code == "" || strstr( $response_code, "fsockopen error" )) {
112
 
                        $validate_results = validateEmail( $email );
113
 
                        $response_code = $validate_results[1];
114
 
                        if($attempt == $max_attempts) {
115
 
                                break;
116
 
                        }
117
 
                        $attempt++;
118
 
                }
119
 
 
120
 
                if ($validate_results[0] OR strstr($validate_results[1],"greylist")) {
121
 
                        $mmsg = "MAILOK";
122
 
                }
123
 
                else {
124
 
                        Error::add('email', T_("Error Email address not confirmed")
125
 
                           . "<br />$validate_results[1]");
126
 
                }
127
 
                /* End of mailcheck */
128
 
 
129
 
                if (!$pass1) {
130
 
                        Error::add('password', T_("You must enter a password"));
131
 
                }
132
 
 
133
 
                if ( $pass1 != $pass2 ) {
134
 
                        Error::add('password', T_("Your passwords do not match"));
135
 
                }
136
 
 
137
 
                if (!User::check_username($username)) {
138
 
                        Error::add('duplicate_user', T_("Error Username already exists"));
139
 
                }
140
 
 
141
 
                // If we've hit an error anywhere up there break!
142
 
                if (Error::occurred()) {
143
 
                        require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
144
 
                        break;
145
 
                }
146
 
 
147
 
                /* Attempt to create the new user */
148
 
                $access = '5';
149
 
                switch (Config::get('auto_user')) {
150
 
                        case 'admin':
151
 
                                $access = '100';
152
 
                        break;
153
 
                        case 'user':
154
 
                                $access = '25';
155
 
                        break;
156
 
                        default:
157
 
                        case 'guest':
158
 
                                $access = '5';
159
 
                        break;
160
 
                } // auto-user level
161
 
 
162
 
 
163
 
                $new_user = User::create($username, $fullname, $email, $pass1,
164
 
                        $access, Config::get('admin_enable_required'));
165
 
 
166
 
                if (!$new_user) {
167
 
                        Error::add('duplicate_user', T_("Error: Insert Failed"));
168
 
                        require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
169
 
                        break;
170
 
                }
171
 
 
172
 
                $client = new User($new_user);
173
 
                $validation = md5(uniqid(rand(), true));
174
 
                $client->update_validation($validation);
175
 
 
176
 
                Registration::send_confirmation($username, $fullname, $email, $pass1, $validation);
177
 
                require_once Config::get('prefix') . '/templates/show_registration_confirmation.inc.php';
178
 
        break;
179
 
        case 'show_add_user':
180
 
        default:
181
 
                require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
182
 
        break;
 
42
    case 'validate':
 
43
        $username     = scrub_in($_GET['username']);
 
44
        $validation    = scrub_in($_GET['auth']);
 
45
        require_once Config::get('prefix') . '/templates/show_user_activate.inc.php';
 
46
    break;
 
47
    case 'add_user':
 
48
        /**
 
49
         * User information has been entered
 
50
         * we need to check the database for possible existing username first
 
51
         * if username exists, error and say "Please choose a different name."
 
52
         * if username does not exist, insert user information into database
 
53
         * then allow the user to 'click here to login'
 
54
         * possibly by logging them in right then and there with their current info
 
55
         * and 'click here to login' would just be a link back to index.php
 
56
         */
 
57
        $fullname         = scrub_in($_POST['fullname']);
 
58
        $username        = scrub_in($_POST['username']);
 
59
        $email             = scrub_in($_POST['email']);
 
60
        $pass1             = scrub_in($_POST['password_1']);
 
61
        $pass2             = scrub_in($_POST['password_2']);
 
62
 
 
63
        /* If we're using the captcha stuff */
 
64
        if (Config::get('captcha_public_reg')) {
 
65
                $captcha         = captcha::solved();
 
66
            if(!isset ($captcha)) {
 
67
                Error::add('captcha', T_('Error Captcha Required'));
 
68
            }
 
69
            if (isset ($captcha)) {
 
70
                if ($captcha) {
 
71
                    $msg="SUCCESS";
 
72
                }
 
73
                    else {
 
74
                        Error::add('captcha', T_('Error Captcha Failed'));
 
75
                    }
 
76
            } // end if we've got captcha
 
77
        } // end if it's enabled
 
78
 
 
79
        if (Config::get('user_agreement')) {
 
80
            if (!$_POST['accept_agreement']) {
 
81
                Error::add('user_agreement', T_("You <U>must</U> accept the user agreement"));
 
82
            }
 
83
        } // if they have to agree to something
 
84
 
 
85
        if (!$_POST['username']) {
 
86
            Error::add('username', T_("You did not enter a username"));
 
87
        }
 
88
 
 
89
        if(!$fullname) {
 
90
            Error::add('fullname', T_("Please fill in your full name (Firstname Lastname)"));
 
91
        }
 
92
 
 
93
        // Check the mail for correct address formation.
 
94
        if (!Mailer::validate_address($email)) { 
 
95
            Error::add('email', T_('Invalid email address')
 
96
        }
 
97
 
 
98
        if (!$pass1) {
 
99
            Error::add('password', T_("You must enter a password"));
 
100
        }
 
101
 
 
102
        if ( $pass1 != $pass2 ) {
 
103
            Error::add('password', T_("Your passwords do not match"));
 
104
        }
 
105
 
 
106
        if (!User::check_username($username)) {
 
107
            Error::add('duplicate_user', T_("Error Username already exists"));
 
108
        }
 
109
 
 
110
        // If we've hit an error anywhere up there break!
 
111
        if (Error::occurred()) {
 
112
            require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
 
113
            break;
 
114
        }
 
115
 
 
116
        /* Attempt to create the new user */
 
117
        $access = '5';
 
118
        switch (Config::get('auto_user')) {
 
119
            case 'admin':
 
120
                $access = '100';
 
121
            break;
 
122
            case 'user':
 
123
                $access = '25';
 
124
            break;
 
125
            default:
 
126
            case 'guest':
 
127
                $access = '5';
 
128
            break;
 
129
        } // auto-user level
 
130
 
 
131
 
 
132
        $new_user = User::create($username, $fullname, $email, $pass1,
 
133
            $access, Config::get('admin_enable_required'));
 
134
 
 
135
        if (!$new_user) {
 
136
            Error::add('duplicate_user', T_("Error: Insert Failed"));
 
137
            require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
 
138
            break;
 
139
        }
 
140
 
 
141
        $client = new User($new_user);
 
142
        $validation = md5(uniqid(rand(), true));
 
143
        $client->update_validation($validation);
 
144
 
 
145
        Registration::send_confirmation($username, $fullname, $email, $pass1, $validation);
 
146
        require_once Config::get('prefix') . '/templates/show_registration_confirmation.inc.php';
 
147
    break;
 
148
    case 'show_add_user':
 
149
    default:
 
150
        require_once Config::get('prefix') . '/templates/show_user_registration.inc.php';
 
151
    break;
183
152
} // end switch on action
184
153
?>