function register() { $error = array(); if (!valid_email_address($_POST['email'])) { $error['email'] = 'неправильный E-mail'; } if (!trim($_POST['password'])) { $error['password'] = '******'; } if (!isset($_POST['agree'])) { $error['agree'] = 'Примите условия пользовательского соглашения'; } if (count($error)) { Site::passWrite('error_register', $error); return; } else { try { $fields = array(); $data['email'] = strtolower(trim($_POST['email'])); $data['nickname'] = $this->getUniqueNickname(strtolower(trim($_POST['nickname'])), $_POST['email']); $data['password'] = md5(trim($_POST['password'])); $data['registerTime'] = $data['lastAccessTime'] = time(); $data['role'] = User::ROLE_UNVERIFIED; $data['hash'] = md5(time() . '-' . rand(1, 10)); foreach ($data as $f => $v) { $fields[] = '`' . $f . '`=' . Database::escape($v); } Database::query('INSERT INTO `user` SET ' . implode(',', $fields)); $uid = Database::lastInsertId(); try { Site::passWrite('success', true); } catch (Exception $e) { $error['email'] = $e->getMessage(); Site::passWrite('error_register', $error); return; } $this->sendRegisterEmail($data['email'], '', $uid . '-' . $data['hash']); Badges::progressAction($uid, Badges::ACTION_TYPE_REGISTER); } catch (Exception $e) { $error['email'] = 'E-mail уже используется, укажите другой'; Site::passWrite('error_register', $error); return; } CurrentUser::set_cookie($uid); } }
function showConfirmation() { $hash = array_pop(Site::$request_uri_array); list($id, $hash) = explode('-', $hash); $data['success'] = false; if ($hash) { $success = Database::sql2single('SELECT id FROM `user` WHERE `id`=' . $id . ' AND `hash`=' . Database::escape($hash)); if ($success) { CurrentUser::set_cookie($success); Database::query('UPDATE `user` SET hash=\'\', `role`=' . User::ROLE_VERIFIED . ' WHERE id=' . $success); $data['success'] = true; } } return $data; }