if (!preg_match('/\\@/', $v['email']) || strlen($v['email']) > 90) { $errorFields[] = 'email'; die(json_encode(array('successful' => 0, 'errorfields' => $errorFields, 'errormsg' => 'You must enter a valid E-mail address.'))); } if ($v['terms'] != '1') { $errorfields[] = 'terms'; die(json_encode(array('successful' => 0, 'errorfields' => $errorFields, 'errormsg' => 'You must agree with the Terms and Conditions to register.'))); } // Make sure the captcha is right... $resp = recaptcha_check_answer(Config::getVal('recaptcha', 'private_key'), $_SERVER["REMOTE_ADDR"], $v["recaptcha_challenge_field"], $v["recaptcha_response_field"]); if (!$resp->is_valid) { $errorFields[] = 'recaptcha_response_field'; die(json_encode(array('successful' => 0, 'errorfields' => $errorFields, 'errormsg' => 'Incorrect CAPTCHA. Please solve again.'))); } // Are we banned? $psm = PermissionSetModel::getInstance(); if ($psm->getByIPAddressCached($_SERVER['REMOTE_ADDR'])) { die(json_encode(array('successful' => 0, 'errorfields' => $errorFields, 'errormsg' => 'You have been flagged as an ' . Config::getVal('general', 'site_name') . ' attacker and cannot register.'))); } // It's all good! Enter it in! $result = UserSession::register($v['name'], $v['pass'], $v['email'], true, $code); switch ($result) { case UserProfileModel::CREATE_OK: break; case UserProfileModel::CREATE_USERNAME_EXISTS: die(json_encode(array('successful' => 0, 'errorfields' => array('name'), 'errormsg' => 'Username already exists. Please choose another.'))); case UserProfileModel::CREATE_EMAIL_EXISTS: die(json_encode(array('successful' => 0, 'errorfields' => array('email'), 'errormsg' => 'Email address is already registered. One account per person, please.'))); default: die(json_encode(array('successful' => 0, 'errorfields' => array(), 'errormsg' => 'Unknown error. Please try again later.'))); }
public static function open_session($useCache = true) { if (static::$opened) { return false; } session_start(); $psm = PermissionSetModel::getInstance(); if (isset($_SESSION['LOGGED_IN']) && $_SESSION['LOGGED_IN'] && isset($_SESSION['USER_ID']) && $_SESSION['USER_ID'] > 0) { $upm = UserProfileModel::getInstance(); static::$userID = $_SESSION['USER_ID']; if ($useCache) { static::$userBean = $upm->getByUserIDCached(static::$userID); } else { static::$userBean = $upm->getByUserID(static::$userID); } if (!static::$userBean) { static::$userID = 0; } } else { if (isset($_COOKIE['publickey'])) { static::autoLogin($_COOKIE['publickey'], $useCache); } } if (!static::$userBean) { if ($useCache) { static::$pubps = $psm->getByGroupNameCached('Public'); } else { static::$pubps = $psm->getByGroupName('Public'); } } else { if (!static::$userBean->getPermission('ip_ban_immune') && strlen($_SERVER['REMOTE_ADDR']) >= 7) { if ($useCache) { static::$ipps = $psm->getByIPAddressCached($_SERVER['REMOTE_ADDR']); } else { static::$ipps = $psm->getByIPAddress($_SERVER['REMOTE_ADDR']); } } } if (Config::getVal('mint', 'enabled', false) && static::$userBean && (!isset($_COOKIE['appdb_username']) || $_COOKIE['appdb_username'] != static::$userBean->username)) { static::bakeCookie('appdb_username', static::$userBean->username); } static::$opened = true; return true; }