public function register($post) { if ($post["password"] != $post["password_repeat"]) { return "Пароли не совпадают"; } $db = PayqrModuleDb::getInstance(); $user = $db->select("select * from " . PayqrModuleDb::getUserTable() . " where username = ?", array($post["username"]), array("s")); if ($user) { return "Пользователь с таким именем уже существует"; } $auth = new PayqrModuleAuth(); $password = $auth->encodePassword($post["password"]); $id = $db->insert(PayqrModuleDb::getUserTable(), array("username" => $post["username"], "password" => $password), array("%s", "%s")); $auth = new PayqrModuleAuth($id); PayqrModule::redirect("auth"); }
private function setOptions() { $db = PayqrModuleDb::getInstance(); $auth = new PayqrModuleAuth(); $user = $auth->getUser(); if ($user) { $query = "select settings from " . PayqrModuleDb::getUserTable() . " where user_id={$user->user_id}"; } else { $query = "select settings from " . PayqrModuleDb::getUserTable() . " limit 1"; } $result = $db->query($query); if ($settings = json_decode($result->settings)) { foreach ($settings as $item) { $this->options[$item->key] = $item->value; } } }
private function recoverUser() { if (isset($_COOKIE[$this->key])) { $db = PayqrModuleDb::getInstance(); $user = $db->select("select user_id, username, merch_id from " . PayqrModuleDb::getUserTable() . " where md5(concat(user_id, username, '" . $this->salt . "')) = ?", array($_COOKIE[$this->key]), array("s")); if ($user) { $_SESSION[$this->key] = $user; } } else { $location = PayqrModule::getBaseUrl() . "/module/auth/"; $auth_location = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; if ($location != $auth_location) { header("Location: {$location}"); } $_SESSION[$this->key] = false; } }
public function save($post) { $db = PayqrModuleDb::getInstance(); $settings = $this->getSettings(); foreach ($settings as $item) { if (isset($post[$item->key])) { $item->value = $post[$item->key]; if ($item->key == "logUrl") { $key = "key="; $url = explode($key, $post[$item->key]); $item->value = $url[0] . $key . $post["logKey"]; } if ($item->key == "merchantID") { $db->update(PayqrModuleDb::getUserTable(), array("merch_id" => $post[$item->key]), array("%s"), array("user_id" => $this->user->user_id), array("%s")); } } } $settings = json_encode($settings); $db->update(PayqrModuleDb::getUserTable(), array("settings" => $settings), array("%s"), array("user_id" => $this->user->user_id), array("%s")); }