| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 146 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 177 | function validate_post_make_user() { |
||
| 178 | $config = get_config(); |
||
| 179 | if (parse_bool($config, "disable_account_creation") |
||
| 180 | || parse_bool($config, "no_web_account_creation") |
||
| 181 | ) { |
||
| 182 | error_page("Account creation is disabled"); |
||
| 183 | } |
||
| 184 | |||
| 185 | if (recaptcha_private_key()) { |
||
| 186 | if (!boinc_recaptcha_isValidated(recaptcha_private_key())) { |
||
| 187 | show_error( |
||
| 188 | tra("Your reCAPTCHA response was not correct. Please try again.") |
||
| 189 | ); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | // Check if consent to terms of use has been given. |
||
| 194 | // |
||
| 195 | $myconsent = FALSE; |
||
| 196 | list($checkct, $ctid) = check_consent_type(CONSENT_TYPE_ENROLL); |
||
| 197 | if ($checkct and check_termsofuse()) { |
||
| 198 | $agree = post_str("agree_to_terms_of_use", true); |
||
| 199 | if (!$agree) { |
||
| 200 | error_page(tra("You have not agreed to our terms of use. Please agree to the terms of use by navigating back to the previous page, in order to create your account")); |
||
| 201 | } |
||
| 202 | $myconsent = TRUE; |
||
| 203 | } |
||
| 204 | |||
| 205 | // see whether the new account should be pre-enrolled in a team, |
||
| 206 | // and initialized with its founder's project prefs |
||
| 207 | // |
||
| 208 | $teamid = post_int("teamid", true); |
||
| 209 | if ($teamid) { |
||
| 210 | $team = BoincTeam::lookup_id($teamid); |
||
| 211 | $clone_user = BoincUser::lookup_id($team->userid); |
||
| 212 | if (!$clone_user) { |
||
| 213 | error_page("User $team->userid not found"); |
||
| 214 | } |
||
| 215 | $project_prefs = $clone_user->project_prefs; |
||
| 216 | } else { |
||
| 217 | $teamid = 0; |
||
| 218 | $project_prefs = ""; |
||
| 219 | } |
||
| 220 | |||
| 221 | if (defined('INVITE_CODES')) { |
||
| 222 | $invite_code = post_str("invite_code"); |
||
| 223 | if (strlen($invite_code) == 0) { |
||
| 224 | show_error(tra("You must supply an invitation code to create an account.")); |
||
| 225 | } |
||
| 226 | if (!preg_match(INVITE_CODES, $invite_code)) { |
||
| 227 | show_error(tra("The invitation code you gave is not valid.")); |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | $new_name = post_str("new_name"); |
||
| 232 | if (!is_valid_user_name($new_name, $reason)) { |
||
| 233 | show_error($reason); |
||
| 234 | } |
||
| 235 | if (UNIQUE_USER_NAME) { |
||
| 236 | $u = BoincUser::lookup_name($new_name); |
||
| 237 | if ($u) { |
||
| 238 | page_head("That name is in use"); |
||
| 239 | echo "<p>The following user names are taken; |
||
| 240 | please go back and use a different one.<p> |
||
| 241 | "; |
||
| 242 | $users = BoincUser::enum( |
||
| 243 | sprintf("name like '%s%%'", $new_name) |
||
| 244 | ); |
||
| 245 | foreach ($users as $u){ |
||
| 246 | echo "<p>$u->name\n"; |
||
| 247 | } |
||
| 248 | page_tail(); |
||
| 249 | exit; |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | $new_email_addr = strtolower(post_str("new_email_addr")); |
||
| 254 | if (!is_valid_email_syntax($new_email_addr)) { |
||
| 255 | show_error(tra("Invalid email address: please enter a valid address of the form [email protected]")); |
||
| 256 | } |
||
| 257 | if (!is_valid_email_sfs($new_email_addr)) { |
||
| 258 | show_error("$new_email_addr was flagged by stopforumspam.com"); |
||
| 259 | } |
||
| 260 | |||
| 261 | $user = BoincUser::lookup_email_addr($new_email_addr); |
||
| 262 | if ($user) { |
||
| 263 | show_error(tra("There's already an account with that email address.")); |
||
| 264 | } |
||
| 265 | |||
| 266 | $tmpuser = BoincUser::lookup_prev_email_addr($new_email_addr); |
||
| 267 | if ($tmpuser) { |
||
| 268 | show_error(tra("There's already an account with that email address.")); |
||
| 269 | } |
||
| 270 | |||
| 271 | $passwd = post_str("passwd"); |
||
| 272 | |||
| 273 | $min_passwd_length = parse_config($config, "<min_passwd_length>"); |
||
| 274 | if (!$min_passwd_length) $min_passwd_length = 6; |
||
| 275 | |||
| 276 | if (!is_ascii($passwd)) { |
||
| 277 | show_error(tra("Passwords may only include ASCII characters.")); |
||
| 278 | } |
||
| 279 | |||
| 280 | if (strlen($passwd)<$min_passwd_length) { |
||
| 281 | show_error( |
||
| 282 | tra("New password is too short: minimum password length is %1 characters.", $min_passwd_length) |
||
| 283 | ); |
||
| 284 | } |
||
| 285 | |||
| 286 | $passwd_hash = md5($passwd.$new_email_addr); |
||
| 287 | |||
| 288 | $country = ""; |
||
| 289 | if (USER_COUNTRY) { |
||
| 290 | $country = post_str("country", true); |
||
| 291 | if ($country && !is_valid_country($country)) { |
||
| 292 | error_page("bad country"); |
||
| 293 | } |
||
| 294 | } |
||
| 295 | |||
| 296 | if (POSTAL_CODE) { |
||
| 297 | $postal_code = sanitize_tags(post_str("postal_code", true)); |
||
| 298 | } else { |
||
| 299 | $postal_code = ''; |
||
| 300 | } |
||
| 301 | |||
| 302 | $user = make_user( |
||
| 303 | $new_email_addr, $new_name, $passwd_hash, |
||
| 304 | $country, $postal_code, $project_prefs, $teamid |
||
| 305 | ); |
||
| 306 | if (!$user) { |
||
| 307 | show_error( |
||
| 308 | tra("Couldn't create account").": ".BoincDb::error() |
||
| 309 | ); |
||
| 310 | } |
||
| 311 | |||
| 312 | if ($myconsent) { |
||
| 313 | $rc = consent_to_a_policy($user, $ctid, 1, 0, 'Webreg'); |
||
| 314 | if (!$rc) { |
||
| 315 | show_error(tra("database error, please contact site administrators")); |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | if (defined('INVITE_CODES')) { |
||
| 320 | error_log("Account '$new_email_addr' created using invitation code '$invite_code'"); |
||
| 321 | } |
||
| 322 | return $user; |
||
| 323 | } |
||
| 349 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.