Skip to content
Newer
Older
100644 179 lines (127 sloc) 4.71 KB
438f487 @q2a 1.5-beta-1
authored
1 <?php
2
3 /*
4 Question2Answer (c) Gideon Greenspan
5
6 http://www.question2answer.org/
7
8
9 File: qa-include/qa-page-register.php
10 Version: See define()s at top of qa-include/qa-base.php
11 Description: Controller for register page
12
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License
16 as published by the Free Software Foundation; either version 2
17 of the License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 More about this license: http://www.question2answer.org/license.php
25 */
26
27 if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
28 header('Location: ../');
29 exit;
30 }
31
32 require_once QA_INCLUDE_DIR.'qa-app-captcha.php';
33 require_once QA_INCLUDE_DIR.'qa-db-users.php';
34
35
36 // Check we're not using single-sign on integration, that we're not logged in, and we're not blocked
37
38 if (QA_FINAL_EXTERNAL_USERS)
39 qa_fatal_error('User registration is handled by external code');
40
41 if (qa_is_logged_in())
42 qa_redirect('');
43
44 if (qa_opt('suspend_register_users')) {
45 $qa_content=qa_content_prepare();
46 $qa_content['error']=qa_lang_html('users/register_suspended');
47 return $qa_content;
48 }
49
50 if (qa_user_permit_error()) {
51 $qa_content=qa_content_prepare();
52 $qa_content['error']=qa_lang_html('users/no_permission');
53 return $qa_content;
54 }
55
56
57 // Process submitted form
58
59 if (qa_clicked('doregister')) {
60 require_once QA_INCLUDE_DIR.'qa-app-limits.php';
61
62 if (qa_limits_remaining(null, QA_LIMIT_REGISTRATIONS)) {
63 require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
64
65 $inemail=qa_post_text('email');
66 $inpassword=qa_post_text('password');
67 $inhandle=qa_post_text('handle');
68
69 $errors=array_merge(
70 qa_handle_email_filter($inhandle, $inemail),
71 qa_password_validate($inpassword)
72 );
73
74 if (qa_opt('captcha_on_register'))
75 qa_captcha_validate_post($errors);
76
77 if (empty($errors)) { // register and redirect
78 qa_limits_increment(null, QA_LIMIT_REGISTRATIONS);
79
80 $userid=qa_create_new_user($inemail, $inpassword, $inhandle);
81 qa_set_logged_in_user($userid, $inhandle);
82
83 $topath=qa_get('to');
84
85 if (isset($topath))
86 qa_redirect_raw(qa_path_to_root().$topath); // path already provided as URL fragment
87 else
88 qa_redirect('');
89 }
90
91 } else
92 $pageerror=qa_lang('users/register_limit');
93 }
94
95
96 // Prepare content for theme
97
98 $qa_content=qa_content_prepare();
99
100 $qa_content['title']=qa_lang_html('users/register_title');
101
102 $qa_content['error']=@$pageerror;
103
104 $custom=qa_opt('show_custom_register') ? trim(qa_opt('custom_register')) : '';
105
106 $qa_content['form']=array(
107 'tags' => 'METHOD="POST" ACTION="'.qa_self_html().'"',
108
109 'style' => 'tall',
110
111 'fields' => array(
112 'custom' => array(
113 'type' => 'custom',
114 'note' => $custom,
115 ),
116
117 'handle' => array(
118 'label' => qa_lang_html('users/handle_label'),
119 'tags' => 'NAME="handle" ID="handle"',
120 'value' => qa_html(@$inhandle),
121 'error' => qa_html(@$errors['handle']),
122 ),
123
124 'password' => array(
125 'type' => 'password',
126 'label' => qa_lang_html('users/password_label'),
127 'tags' => 'NAME="password" ID="password"',
128 'value' => qa_html(@$inpassword),
129 'error' => qa_html(@$errors['password']),
130 ),
131
132 'email' => array(
133 'label' => qa_lang_html('users/email_label'),
134 'tags' => 'NAME="email" ID="email"',
135 'value' => qa_html(@$inemail),
136 'note' => qa_opt('email_privacy'),
137 'error' => qa_html(@$errors['email']),
138 ),
139 ),
140
141 'buttons' => array(
142 'register' => array(
143 'label' => qa_lang_html('users/register_button'),
144 ),
145 ),
146
147 'hidden' => array(
148 'doregister' => '1',
149 ),
150 );
151
152 if (!strlen($custom))
153 unset($qa_content['form']['fields']['custom']);
154
155 if (qa_opt('captcha_on_register'))
156 qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors);
157
158 $loginmodules=qa_load_modules_with('login', 'login_html');
159
160 foreach ($loginmodules as $module) {
161 ob_start();
162 $module->login_html(qa_opt('site_url').qa_get('to'), 'register');
163 $html=ob_get_clean();
164
165 if (strlen($html))
166 @$qa_content['custom'].='<BR>'.$html.'<BR>';
167 }
168
169 $qa_content['focusid']=isset($errors['handle']) ? 'handle'
170 : (isset($errors['password']) ? 'password'
171 : (isset($errors['email']) ? 'email' : 'handle'));
172
173
174 return $qa_content;
175
176
177 /*
178 Omit PHP closing tag to help avoid accidental output
179 */
Something went wrong with that request. Please try again.