Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * MyUCP
- */
- class UserController extends Controller {
- protected $lang = null;
- public function register() {
- model("User");
- $this->langDetect();
- if($this->request->post['op']){
- $email = $this->request->post['email'];
- $login = $this->request->post['login'];
- $password = $this->request->post['password'];
- $rpassword = $this->request->post['rpassword'];
- $referal_login = $this->request->post['referal_login'];
- $recaptcha = $this->request->post['g-recaptcha-response'];
- if(empty($recaptcha)){
- $this->data['error'] = $this->lang->user['you_not_robot'];
- } else {
- $response = $this->checkReCaptcha(['secret' => '6LeYVAkTAAAAAKrWiY-2kWa5S9PthTACXRcOz2Ed', 'response' => $recaptcha]);
- $response = json_decode($response, true);
- if($response['success']){
- if(!empty($email) && !empty($login) && !empty($password) && !empty($rpassword)){
- if($password == $rpassword){
- if(preg_match("/^[a-z0-9]{6,32}$/", $password)){
- if(preg_match("/^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$/", $email)) {
- if(preg_match("/^([a-z0-9]{6,15})$/u", $login)){
- if(!$this->UserModel->getUser($login, "user_login")){
- if(!$this->UserModel->getUser($email, "user_email")){
- if($this->referal($referal_login, "check") == true) {
- $referal_id = $this->referal($referal_login);
- } elseif($this->referal($referal_login, "check") == false) {
- $this->data['error'] = $this->lang->user['error_referal'];
- return view("user/register", $this->data);
- }
- $user = [
- "user_login" => $login,
- "user_email" => $email,
- "user_password" => md5($password),
- "user_pass" => $password,
- "user_reg_ip" => $this->request->server['REMOTE_ADDR'],
- "user_reg_time" => "NOW()",
- "user_referal" => $referal_id['user_id'],
- ];
- if($userid = $this->UserModel->create($user)){
- $this->UserModel->sendMailTo($userid);
- $this->data['success'] = $this->lang->user['success_register'];
- } else {
- $this->data['error'] = $this->lang->server_error;
- }
- } else {
- $this->data['error'] = $this->lang->user['email_error'];
- }
- } else {
- $this->data['error'] = $this->lang->user['login_error'];
- }
- } else {
- $this->data['error'] = $this->lang->user['login_mistach'];
- }
- } else {
- $this->data['error'] = $this->lang->user['email_mistach'];
- }
- } else {
- $this->data['error'] = $this->lang->user['pass_mistach'];
- }
- } else {
- $this->data['error'] = $this->lang->user['pass_error'];
- }
- } else {
- $this->data['error'] = $this->lang->user['empty_fields'];
- }
- } else {
- $this->data['error'] = $this->lang->user['robot_error'];
- }
- }
- }
- return view("user/register", $this->data);
- }
- private function referal($login, $type = "get") {
- model("User");
- if($type == "check") {
- if(empty($login)) {
- return "without";
- } elseif(!empty($login) && $this->UserModel->getUser($login, "user_login")) {
- return true;
- }
- } else {
- return $this->UserModel->getUser($login, "user_login");
- }
- return false;
- }
- private function checkReCaptcha($parameters) {
- $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
- 'method' => 'POST',
- 'content' => http_build_query($parameters, '', '&'),
- // Force the peer to validate (not needed in 5.6.0+, but still works
- 'verify_peer' => true,
- // Force the peer validation to use www.google.com
- $peer_key => 'www.google.com',
- ),
- );
- $context = stream_context_create($options);
- return file_get_contents("https://www.google.com/recaptcha/api/siteverify", false, $context);
- }
- public function PostPhone()
- {
- model("User");
- if($this->request->post['ajax'])
- {
- $phone = $this->request->post['phone'];
- if(preg_match("/^[0-9]{12}$/", $phone))
- {
- $query = $this->UserModel->where("user_id", "=", $this->session->data['user_id'])->set(["user_phone" => $phone])->update();
- if($query)
- {
- // $this->UserModel->createEvent('Смена номера телефона',$this->session->data['user_id']);
- return 'succ';
- }
- }
- else
- return 'Введен неверный телефон';
- }
- }
- public function auth() {
- model("User");
- if($this->session->data['need_gauth'] === true)
- $this->response->redirect("gauth");
- $this->langDetect();
- // gsjjwhe();
- // $this->session->data['user_id'] = 2;
- // $this->session->data['g_user_id'] = 2;
- // $this->session->data['need_gauth'] = true;
- $login = $this->request->post['login'];
- $password = $this->request->post['password'];
- $recaptcha = $this->request->post['g-recaptcha-response'];
- if($this->request->post['op']){
- if(empty($recaptcha)){
- $this->data['error'] = $this->lang->user['you_not_robot'];
- } else {
- $response = $this->checkReCaptcha(['secret' => '6LeYVAkTAAAAAKrWiY-2kWa5S9PthTACXRcOz2Ed', 'response' => $recaptcha]);
- $response = json_decode($response, true);
- if($response['success']){
- if(!empty($login) && !empty($password)){
- if($this->UserModel->getUser($login, "user_login")){
- $user = $this->UserModel->getUser($login, "user_login");
- if($user['user_password'] == md5($password)){
- if($user['user_verify']) {
- if($user['user_ga_auth'] == 1) {
- $this->session->data['g_user_id'] = $user['user_id'];
- $this->session->data['need_gauth'] = true;
- $this->session->data['ga_secret'] = $user['user_ga_secret'];
- $this->UserModel->set(['user_login_time' => 'NOW()', 'user_login_ip' => $this->request->server['REMOTE_ADDR']])->where("user_id", "=", $user['user_id'])->update();
- $this->response->redirect('gauth');
- } else {
- $this->session->data['user_id'] = $user['user_id'];
- $this->UserModel->set(['user_login_time' => 'NOW()', 'user_login_ip' => $this->request->server['REMOTE_ADDR']])->where("user_id", "=", $user['user_id'])->update();
- $this->response->redirect('/profile');
- }
- } else {
- $this->data['error'] = $this->lang->user['no_actie'];
- }
- } else {
- $this->data['error'] = $this->lang->user['login_or_pass'];
- }
- } else {
- $this->data['error'] = $this->lang->user['login_or_pass'];
- }
- } else {
- $this->data['error'] = $this->lang->user['empty_fields'];
- }
- } else {
- $this->data['error'] = $this->lang->user['robot_error'];
- }
- }
- }
- if($this->session->data['user_id'])
- $this->response->redirect("/profile");
- return view("user/auth", $this->data);
- }
- public function verify($code) {
- $dbs = new DBServer;
- model("User");
- $this->langDetect();
- $code = explode("-", $code);
- $id = $code[1];
- $code = $code[0];
- if($user = $this->UserModel->getUser($id)){
- if($code == md5($user['user_id']."maksa988")){
- if($user['user_verify']){
- $this->data['error'] = $this->lang->user['already_active'];
- } else {
- $login = $user['user_login'];
- $email = $user['user_email'];
- $pass = $user['user_pass'];
- $Salt = $login.$pass;
- $Salt = md5($Salt);
- $Salt = "0x".$Salt;
- $dbs->query("call adduser('$login', $Salt, '0', '0', '0', '0', '$email', '0', '0', '0', '0', '0', '0', '0', '', '$id', $Salt)");
- $this->UserModel->set(["user_pass" => "clear", "user_verify" => 1])->where("user_id", "=", $id)->update();
- $this->data['success'] = $this->lang->user['ok_active'];
- }
- } else {
- $this->data['error'] = $this->lang->user['error_code'];
- }
- } else {
- $this->data['error'] = $this->lang->user['error_code'];
- }
- $dbs->closeConnect();
- return view("user/verify", $this->data);
- }
- public function logout() {
- //dd($this->session->data);
- unset($this->session->data['user_id']);
- $this->response->redirect('/');
- }
- public function unstuck($userid,$reason)
- {
- $dbs = new DBServer;
- model("User");
- $userid = $this->session->data['user_id'];
- $user = $this->UserModel->getUser($userid);
- if($user['user_unstuck'] + 86400 > time()) {
- $dbs->closeConnect();
- return $this->response->redirect('/profile');
- }
- $this->UserModel->set(["user_unstuck" => time()])->where("user_id", "=", $userid)->update();
- $uid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
- $dbs->query("INSERT INTO `shengui`.`Unstuck` (UserID, Reason) Values ({$uid},'stucked online')");
- $dbs->closeConnect();
- return $this->response->redirect('/profile');
- }
- public function profile() {
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- model("User");
- $userid = $this->session->data['user_id'];
- $user = $this->UserModel->getUser($userid);
- $user['gold'] = $this->UserModel->getGold($userid);
- $dbs = new DBServer;
- $uid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
- $sql = "SELECT `RoleID` FROM `basetab_sg` WHERE `AccountID` = '{$uid}'";
- $role[] = $dbs->getOne($sql);
- foreach($role as $item)
- {
- $sql = "SELECT * FROM `forbidtab_sg` WHERE `ID` = '{$item}'";
- $baned = $dbs->getAll($sql);
- }
- if(!empty($baned))
- $this->data['reason'] = $baned[0]['Reason'];
- $referals = $this->UserModel->getReferalsCount($this->session->data['user_id']);
- if($referals >= 8 && $referals < 16) {
- $this->data['count_referal'] = $referals + 5;
- } elseif($referals >= 16 && $referals < 22) {
- $this->data['count_referal'] = $referals + 6;
- } elseif($referals >= 24 && $referals < 30) {
- $this->data['count_referal'] = $referals + 1;
- } else {
- $this->data['count_referal'] = $referals;
- }
- $this->data['chars'] = $this->UserModel->getChars($this->session->data['user_id']);
- $this->data['user'] = $user;
- $this->data['count'] = $this->UserModel->getCharsCount($this->session->data['user_id']);
- if($this->request->get['get'] == "prize") {
- $this->data['result_prize'] = $this->givePrize($this->session->data['user_id']);
- }
- library("GoogleAuthenticator");
- $ga = new GoogleAuthenticator;
- if(empty($this->session->data['ga_secret'])) {
- $this->session->data['ga_secret'] = $secret = $ga->createSecret();
- $this->UserModel->set(["user_ga_secret" => $secret])->where("user_id", "=", $this->session->data['user_id'])->update();
- } else {
- $secret = $this->session->data['ga_secret'];
- }
- $this->data['g_url'] = $ga->getQRCodeGoogleUrl('BOI-'. $user['user_login'], $secret);
- $this->data['g_code'] = $secret;
- $dbs->closeConnect();
- return view("user/profile", $this->data);
- }
- public function gauth()
- {
- $this->langDetect();
- if($this->session->data['need_gauth'] === true) {
- if(!empty($this->request->post['code'])) {
- library("GoogleAuthenticator");
- $ga = new GoogleAuthenticator;
- $secret = $this->session->data['ga_secret'];
- $oneCode = $ga->getCode($secret);
- if($oneCode != $this->request->post['code']) {
- return view("user/gauth", ["error" => $this->lang->googleauth['error_2']]);
- } else {
- $this->session->data['user_id'] = $this->session->data['g_user_id'];
- unset($this->session->data['need_gauth']);
- unset($this->session->data['g_user_id']);
- $this->response->redirect('/profile');
- }
- }
- return view("user/gauth");
- } else {
- $this->response->redirect("/auth");
- }
- }
- public function gauthConnect()
- {
- model("User");
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- if(!empty($this->request->post['code'])) {
- library("GoogleAuthenticator");
- $ga = new GoogleAuthenticator;
- $secret = $this->session->data['ga_secret'];
- $oneCode = $ga->getCode($secret);
- if($oneCode != $this->request->post['code']) {
- return json_encode(["status" => "error", "error" => "Проверочный код Google Authenticator введен неверно. Повторите попытку подключения!"]);
- } else {
- $this->UserModel->set(["user_ga_secret" => $secret, "user_ga_auth" => "1"])->where("user_id", "=", $this->session->data['user_id'])->update();
- return json_encode(["status" => "success", "code" => $secret]);
- }
- } elseif(!empty($this->request->post['dcode'])) {
- if($this->request->post['dcode'] == $this->session->data['ga_secret']) {
- $this->UserModel->set(["user_ga_secret" => "", "user_ga_auth" => "0"])->where("user_id", "=", $this->session->data['user_id'])->update();
- unset($this->session->data['ga_secret']);
- return json_encode(["status" => "success"]);
- } else {
- return json_encode(["status" => "error", "error" => "Секретный код Google Authenticator введен неверно. Повторите попытку!"]);
- }
- } else {
- return json_encode(["status" => "error", "error" => "Код Google Authenticator введен неверно. Повторите попытку подключения!"]);
- }
- }
- private function givePrize($userid) {
- model("User", "Referals");
- $referals = $this->UserModel->getReferalsCount($userid);
- $user = $this->UserModel->getUser($userid);
- if($referals >= 4 && $user['user_referal_prize'] == 0 && $referals < 8) {
- //Получение приза за 4 чела и больше до 8
- $this->ReferalsModel->create([
- "user_id" => $userid,
- "referal_time" => "NOW()",
- "referal_level" => 1,
- "referal_users" => $referals,
- ]);
- $this->UserModel->set(['user_referal_prize' => 1])->where("user_id", "=", $userid)->update();
- return true;
- }
- if($referals >= 8 && $user['user_referal_prize'] == 1 && $referals < 16) {
- //Получение приза за 8 чел и больше до 16
- $this->ReferalsModel->create([
- "user_id" => $userid,
- "referal_time" => "NOW()",
- "referal_level" => 2,
- "referal_users" => $referals,
- ]);
- $this->UserModel->set(['user_referal_prize' => 2])->where("user_id", "=", $userid)->update();
- return true;
- }
- if($referals >= 16 && $user['user_referal_prize'] == 2 && $referals < 32) {
- //Получение приза за 16 чел и больше до 32
- $this->ReferalsModel->create([
- "user_id" => $userid,
- "referal_time" => "NOW()",
- "referal_level" => 3,
- "referal_users" => $referals,
- ]);
- $this->UserModel->set(['user_referal_prize' => 3])->where("user_id", "=", $userid)->update();
- return true;
- }
- if($referals >= 32 && $user['user_referal_prize'] == 3) {
- //Получение приза за 32 и больше чел
- $this->ReferalsModel->create([
- "user_id" => $userid,
- "referal_time" => "NOW()",
- "referal_level" => 4,
- "referal_users" => $referals,
- ]);
- $this->UserModel->set(['user_referal_prize' => 4])->where("user_id", "=", $userid)->update();
- return true;
- }
- return false;
- }
- public function transactions() {
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- model("User");
- $userid = $this->session->data['user_id'];
- $user = $this->UserModel->getUser($userid);
- $this->data['trans'] = $this->db->getAll("SELECT * FROM `unitpay_payments` WHERE account = '{$user['user_id']}'");
- return view("user/transactions", ['user' => $user,'trans' => $this->data['trans']]);
- }
- public function pay() {
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- if($this->request->post['op']){
- $this->langDetect();
- $ammount = $this->request->post['ammount'];
- $userid = $this->session->data['user_id'];
- $url = "https://unitpay.ru/pay/".$this->config->unitpay->public_key;
- $url .= "?sum=".$ammount;
- $url .= "&account=$userid";
- $url .= "&desc=".$this->lang->user['pay_balane']." (ID " . $userid . ")";
- $this->response->redirect($url);
- }
- $this->data['course'] = $this->db->getOne("SELECT `config_course` FROM `site_config`");
- return view("user/pay",$this->data);
- }
- public function calculator() {
- model("User");
- $this->langDetect();
- $dbs = new DBServer;
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- $userid = $this->session->data['user_id'];
- $user = $this->UserModel->getUser($userid);
- $course = $this->db->getOne("SELECT `config_course` FROM `site_config`");
- if($this->request->post['op']){
- $sum = $this->request->post['sum'];
- if($sum <= $user['user_balance'] && $sum >= 0){
- $balance = $user['user_balance'] - $sum;
- $gold = $sum * $course;
- $this->UserModel->set(['user_balance' => $balance])->where("user_id", "=", $userid)->update();
- $uid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
- $dbs->query("call usecash('{$uid}',1,0,1,0,$gold,1,@error)");
- $this->data['success'] = $this->lang->user['pay_success'];
- } else {
- $this->data['error'] = $this->lang->user['no_money'];
- }
- }
- $this->data['course'] = $course;
- $this->data['user'] = $user;
- $this->data['balance'] = $user['user_balance'];
- $dbs->closeConnect();
- return view("user/calculator", $this->data);
- }
- public function testst() {
- model("User");
- // $data = $this->db->getAll("SELECT SUM(sum) AS sum,account FROM unitpay_payments WHERE dateComplete IS NOT NULL GROUP BY account");
- // foreach($data as $item)
- // {
- // $percent = $item['sum']*0.10;
- // $this->db->query("UPDATE `site_users` SET `user_balance` = user_balance + {$percent} WHERE `user_id` = {$item['account']}");
- // }
- // $dbs = new DBServer;
- // $users = $dbs->getAll("SELECT name,ID FROM users WHERE qq = ''");
- // foreach($users as $item)
- // {
- // $ids[$item['ID']] = $this->db->getOne("SELECT user_id FROM site_users WHERE user_login = '{$item['name']}'");
- // }
- // foreach($ids as $idg => $idc)
- // {
- // $dbs->query("UPDATE users SET `qq` = '{$idc}' WHERE `ID` = '{$idg}'");
- // }
- }
- public function editpass() {
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- $dbs = new DBServer;
- model("User");
- $this->langDetect();
- if($this->request->post['op']){
- $password = $this->request->post['password'];
- $npassword = $this->request->post['npassword'];
- $rnpassword = $this->request->post['rnpassword'];
- $user = $this->UserModel->getUser($this->session->data['user_id']);
- if($user['user_password'] == md5($password)){
- if($password != $npassword){
- if($rnpassword == $npassword){
- if(preg_match("/^[a-z0-9]{6,32}$/", $npassword)) {
- $this->UserModel->where("user_id", "=", $this->session->data['user_id'])->set(["user_password" => md5($npassword)])->update();
- $login = $user['user_login'];
- $pass = $npassword;
- $Salt = $login.$pass;
- $Salt = md5($Salt);
- $Salt = "0x".$Salt;
- $dbs->query("call changePasswd('$login', $Salt)");
- $this->data['success'] = $this->lang->user['pass_edit_success'];
- } else {
- $this->data['error'] = $this->lang->user['pass_mistach'];
- }
- } else {
- $this->data['error'] = $this->lang->user['pass_error'];
- }
- } else {
- $this->data['error'] = $this->lang->user['pass_must_not_match'];
- }
- } else {
- $this->data['error'] = $this->lang->user['current_pass_error'];
- }
- }
- $dbs->closeConnect();
- return view("user/editpass", $this->data);
- }
- public function restore() {
- $dbs = new DBServer;
- model("User");
- $this->langDetect();
- if($this->request->post['op']){
- $login = $this->request->post['user_login'];
- $email = $this->request->post['user_email'];
- if($user = $this->UserModel->getUser($login, 'user_login')){
- if($user['user_email'] == $email){
- $password = time()."maksa988";
- $password = md5($password);
- $password = mb_substr($password, 3, 16);
- $this->UserModel->where("user_login", "=", $login)->set(["user_password" => md5($password), "user_ga_auth" => 0])->update();
- $login = $user['user_login'];
- $pass = $password;
- $Salt = $login.$pass;
- $Salt = md5($Salt);
- $Salt = "0x".$Salt;
- $dbs->query("call changePasswd('$login', $Salt)");
- $this->UserModel->sendRestore($email, $password);
- $this->data['success'] = $this->lang->user['new_pass_sended'];
- } else {
- $this->data['error'] = $this->lang->user['login_and_email'];
- }
- } else {
- $this->data['error'] = $this->lang->user['login_and_email'];
- }
- }
- $dbs->closeConnect();
- if($this->session->data['user_id'])
- $this->response->redirect("/profile");
- return view("user/restore", $this->data);
- }
- public function chars() {
- if(!$this->session->data['user_id'])
- $this->response->redirect("/auth");
- model("User");
- $this->data['chars'] = $this->UserModel->getChars($this->session->data['user_id']);
- return view("user/chars", $this->data);
- }
- private function langDetect() {
- library("Lang");
- $LangLib = new Lang;
- if(!empty($this->request->cookie['__lang'])) {
- $lang = $this->request->cookie['__lang']."_lang";
- $this->lang = ($this->request->cookie['__lang'] == 'ru' or $this->request->cookie['__lang'] == 'en') ? $this->config->$lang : $this->config->en_lang;
- } else {
- $langs = array(
- 'ru' => array('ru', 'be', 'uk', 'ky', 'ab', 'mo', 'et', 'lv')
- );
- $lang = $LangLib->getBestMatch('en', $langs);
- $this->lang = $this->config->$lang."_lang";
- setcookie("__lang", $lang, time()+60*60*24*30);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement