Advertisement
Maksa988

Untitled

Mar 10th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.33 KB | None | 0 0
  1. <?php
  2. /*
  3. * MyUCP
  4. */
  5.  
  6. class UserController extends Controller {
  7.    
  8.     protected $lang = null;
  9.  
  10.     public function register() {
  11.        
  12.         model("User");
  13.         $this->langDetect();
  14.  
  15.         if($this->request->post['op']){
  16.             $email = $this->request->post['email'];
  17.             $login = $this->request->post['login'];
  18.             $password = $this->request->post['password'];
  19.             $rpassword = $this->request->post['rpassword'];
  20.             $referal_login = $this->request->post['referal_login'];
  21.             $recaptcha = $this->request->post['g-recaptcha-response'];
  22.  
  23.             if(empty($recaptcha)){
  24.                 $this->data['error'] = $this->lang->user['you_not_robot'];
  25.             } else {
  26.                 $response = $this->checkReCaptcha(['secret' => '6LeYVAkTAAAAAKrWiY-2kWa5S9PthTACXRcOz2Ed', 'response' => $recaptcha]); 
  27.                 $response = json_decode($response, true);
  28.  
  29.                 if($response['success']){          
  30.                     if(!empty($email) && !empty($login) && !empty($password) && !empty($rpassword)){
  31.                         if($password == $rpassword){
  32.                             if(preg_match("/^[a-z0-9]{6,32}$/", $password)){
  33.                                 if(preg_match("/^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$/", $email)) {
  34.                                     if(preg_match("/^([a-z0-9]{6,15})$/u", $login)){
  35.                                         if(!$this->UserModel->getUser($login, "user_login")){
  36.                                             if(!$this->UserModel->getUser($email, "user_email")){
  37.                                                 if($this->referal($referal_login, "check") == true) {
  38.                                                     $referal_id = $this->referal($referal_login);
  39.                                                 } elseif($this->referal($referal_login, "check") == false) {
  40.                                                     $this->data['error'] = $this->lang->user['error_referal'];
  41.                                                     return view("user/register", $this->data);
  42.                                                 }
  43.  
  44.                                                 $user = [
  45.                                                     "user_login"    =>  $login,
  46.                                                     "user_email"    =>  $email,
  47.                                                     "user_password" =>  md5($password),
  48.                                                     "user_pass"     =>  $password,
  49.                                                     "user_reg_ip"   =>  $this->request->server['REMOTE_ADDR'],
  50.                                                     "user_reg_time" =>  "NOW()",
  51.                                                     "user_referal" =>   $referal_id['user_id'],
  52.                                                 ];
  53.  
  54.                                                 if($userid = $this->UserModel->create($user)){
  55.                                                     $this->UserModel->sendMailTo($userid);
  56.                                                     $this->data['success'] = $this->lang->user['success_register'];
  57.                                                 } else {
  58.                                                     $this->data['error'] = $this->lang->server_error;
  59.                                                 }
  60.                                             } else {
  61.                                                 $this->data['error'] = $this->lang->user['email_error'];
  62.                                             }
  63.                                         } else {
  64.                                             $this->data['error'] = $this->lang->user['login_error'];
  65.                                         }
  66.                                     } else {
  67.                                         $this->data['error'] = $this->lang->user['login_mistach'];
  68.                                     }
  69.                                 } else {
  70.                                     $this->data['error'] = $this->lang->user['email_mistach'];
  71.                                 }
  72.                             } else {
  73.                                 $this->data['error'] = $this->lang->user['pass_mistach'];
  74.                             }
  75.                         } else {
  76.                             $this->data['error'] = $this->lang->user['pass_error'];
  77.                         }
  78.                     } else {
  79.                         $this->data['error'] = $this->lang->user['empty_fields'];
  80.                     }
  81.                 } else {
  82.                     $this->data['error'] = $this->lang->user['robot_error'];
  83.                 }
  84.             }
  85.         }
  86.        
  87.         return view("user/register", $this->data);
  88.     }
  89.  
  90.     private function referal($login, $type = "get") {
  91.         model("User");
  92.  
  93.         if($type == "check") {
  94.             if(empty($login)) {
  95.                 return "without";
  96.             } elseif(!empty($login) && $this->UserModel->getUser($login, "user_login")) {
  97.                 return true;
  98.             }
  99.         } else {
  100.             return $this->UserModel->getUser($login, "user_login");
  101.         }
  102.  
  103.         return false;
  104.     }
  105.  
  106.     private function checkReCaptcha($parameters) {
  107.         $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
  108.         $options = array(
  109.             'http' => array(
  110.                 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
  111.                 'method' => 'POST',
  112.                 'content' => http_build_query($parameters, '', '&'),
  113.                 // Force the peer to validate (not needed in 5.6.0+, but still works
  114.                 'verify_peer' => true,
  115.                 // Force the peer validation to use www.google.com
  116.                 $peer_key => 'www.google.com',
  117.             ),
  118.         );
  119.         $context = stream_context_create($options);
  120.         return file_get_contents("https://www.google.com/recaptcha/api/siteverify", false, $context);
  121.     }
  122.  
  123.     public function PostPhone()
  124.     {
  125.         model("User");
  126.  
  127.         if($this->request->post['ajax'])
  128.         {
  129.            
  130.             $phone = $this->request->post['phone'];
  131.             if(preg_match("/^[0-9]{12}$/", $phone))
  132.             {
  133.                 $query = $this->UserModel->where("user_id", "=", $this->session->data['user_id'])->set(["user_phone" => $phone])->update();
  134.                
  135.                 if($query)
  136.                 {
  137.                 //  $this->UserModel->createEvent('Смена номера телефона',$this->session->data['user_id']);
  138.                     return 'succ';
  139.                 }
  140.                    
  141.             }
  142.             else
  143.                 return 'Введен неверный телефон';
  144.            
  145.            
  146.                            
  147.         }
  148.     }
  149.  
  150.     public function auth() {
  151.         model("User");
  152.        
  153.         if($this->session->data['need_gauth'] === true)
  154.             $this->response->redirect("gauth");
  155.  
  156.         $this->langDetect();
  157.  
  158.         // gsjjwhe();
  159.         // $this->session->data['user_id'] = 2;
  160.         // $this->session->data['g_user_id'] = 2;
  161.         // $this->session->data['need_gauth'] = true;
  162.  
  163.         $login = $this->request->post['login'];
  164.         $password = $this->request->post['password'];
  165.         $recaptcha = $this->request->post['g-recaptcha-response'];
  166.  
  167.         if($this->request->post['op']){
  168.             if(empty($recaptcha)){
  169.                 $this->data['error'] = $this->lang->user['you_not_robot'];
  170.             } else {
  171.                 $response = $this->checkReCaptcha(['secret' => '6LeYVAkTAAAAAKrWiY-2kWa5S9PthTACXRcOz2Ed', 'response' => $recaptcha]); 
  172.                 $response = json_decode($response, true);
  173.  
  174.                 if($response['success']){          
  175.                     if(!empty($login) && !empty($password)){
  176.                         if($this->UserModel->getUser($login, "user_login")){
  177.                             $user = $this->UserModel->getUser($login, "user_login");
  178.                             if($user['user_password'] == md5($password)){
  179.                                 if($user['user_verify']) {
  180.                                     if($user['user_ga_auth'] == 1) {
  181.                                         $this->session->data['g_user_id'] = $user['user_id'];
  182.                                         $this->session->data['need_gauth'] = true;
  183.                                         $this->session->data['ga_secret'] = $user['user_ga_secret'];
  184.                                         $this->UserModel->set(['user_login_time' => 'NOW()', 'user_login_ip' => $this->request->server['REMOTE_ADDR']])->where("user_id", "=", $user['user_id'])->update();
  185.                                         $this->response->redirect('gauth');
  186.                                     } else {
  187.                                         $this->session->data['user_id'] = $user['user_id'];
  188.                                         $this->UserModel->set(['user_login_time' => 'NOW()', 'user_login_ip' => $this->request->server['REMOTE_ADDR']])->where("user_id", "=", $user['user_id'])->update();
  189.                                         $this->response->redirect('/profile');
  190.                                     }
  191.                                 } else {
  192.                                     $this->data['error'] = $this->lang->user['no_actie'];
  193.                                 }
  194.                             } else {
  195.                                 $this->data['error'] = $this->lang->user['login_or_pass'];
  196.                             }
  197.                         } else {
  198.                             $this->data['error'] = $this->lang->user['login_or_pass'];
  199.                         }
  200.                     } else {
  201.                         $this->data['error'] = $this->lang->user['empty_fields'];
  202.                     }
  203.                 } else {
  204.                     $this->data['error'] = $this->lang->user['robot_error'];
  205.                 }
  206.             }
  207.         }
  208.  
  209.         if($this->session->data['user_id'])
  210.             $this->response->redirect("/profile");
  211.  
  212.         return view("user/auth", $this->data);
  213.     }
  214.  
  215.     public function verify($code) {
  216.         $dbs = new DBServer;
  217.         model("User");
  218.         $this->langDetect();
  219.         $code = explode("-", $code);
  220.         $id = $code[1];
  221.         $code = $code[0];
  222.         if($user = $this->UserModel->getUser($id)){
  223.             if($code == md5($user['user_id']."maksa988")){
  224.                 if($user['user_verify']){
  225.                     $this->data['error'] = $this->lang->user['already_active'];
  226.                 } else {
  227.                     $login = $user['user_login'];
  228.                     $email = $user['user_email'];
  229.                     $pass = $user['user_pass'];
  230.                     $Salt = $login.$pass;
  231.                     $Salt = md5($Salt);
  232.                     $Salt = "0x".$Salt;
  233.                     $dbs->query("call adduser('$login', $Salt, '0', '0', '0', '0', '$email', '0', '0', '0', '0', '0', '0', '0', '', '$id', $Salt)");
  234.                     $this->UserModel->set(["user_pass" => "clear", "user_verify" => 1])->where("user_id", "=", $id)->update();
  235.                     $this->data['success'] = $this->lang->user['ok_active'];
  236.                 }
  237.             } else {
  238.                 $this->data['error'] = $this->lang->user['error_code'];
  239.             }
  240.         } else {
  241.             $this->data['error'] = $this->lang->user['error_code'];
  242.         }
  243.  
  244.         $dbs->closeConnect();
  245.         return view("user/verify", $this->data);
  246.     }
  247.  
  248.     public function logout() {
  249.         //dd($this->session->data);
  250.         unset($this->session->data['user_id']);
  251.         $this->response->redirect('/');
  252.     }
  253.     public function unstuck($userid,$reason)
  254.     {
  255.         $dbs = new DBServer;
  256.         model("User");
  257.         $userid = $this->session->data['user_id'];     
  258.         $user = $this->UserModel->getUser($userid);
  259.        
  260.        
  261.         if($user['user_unstuck'] + 86400 > time()) {
  262.             $dbs->closeConnect();
  263.             return $this->response->redirect('/profile');
  264.         }
  265.  
  266.         $this->UserModel->set(["user_unstuck" => time()])->where("user_id", "=", $userid)->update();
  267.         $uid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
  268.         $dbs->query("INSERT INTO `shengui`.`Unstuck` (UserID, Reason) Values ({$uid},'stucked online')");
  269.        
  270.         $dbs->closeConnect();
  271.         return $this->response->redirect('/profile');
  272.  
  273.     }
  274.  
  275.     public function profile() {
  276.  
  277.         if(!$this->session->data['user_id'])
  278.             $this->response->redirect("/auth");
  279.  
  280.         model("User");
  281.         $userid = $this->session->data['user_id'];
  282.         $user = $this->UserModel->getUser($userid);
  283.         $user['gold'] = $this->UserModel->getGold($userid);
  284.  
  285.         $dbs = new DBServer;
  286.         $uid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
  287.         $sql = "SELECT `RoleID` FROM `basetab_sg` WHERE `AccountID` = '{$uid}'";      
  288.         $role[] = $dbs->getOne($sql);      
  289.         foreach($role as $item)
  290.         {
  291.             $sql = "SELECT * FROM `forbidtab_sg` WHERE `ID` = '{$item}'";
  292.             $baned = $dbs->getAll($sql);
  293.         }
  294.         if(!empty($baned))
  295.             $this->data['reason'] = $baned[0]['Reason'];
  296.  
  297.         $referals = $this->UserModel->getReferalsCount($this->session->data['user_id']);
  298.  
  299.         if($referals >= 8 && $referals < 16) {
  300.             $this->data['count_referal'] = $referals + 5;
  301.         } elseif($referals >= 16 && $referals < 22) {
  302.             $this->data['count_referal'] = $referals + 6;
  303.         } elseif($referals >= 24 && $referals < 30) {
  304.             $this->data['count_referal'] = $referals + 1;
  305.         } else {
  306.             $this->data['count_referal'] = $referals;
  307.         }
  308.  
  309.         $this->data['chars'] = $this->UserModel->getChars($this->session->data['user_id']);
  310.         $this->data['user'] = $user;
  311.         $this->data['count'] = $this->UserModel->getCharsCount($this->session->data['user_id']);
  312.  
  313.         if($this->request->get['get'] == "prize") {
  314.             $this->data['result_prize'] = $this->givePrize($this->session->data['user_id']);
  315.         }
  316.  
  317.         library("GoogleAuthenticator");
  318.  
  319.         $ga = new GoogleAuthenticator;
  320.         if(empty($this->session->data['ga_secret'])) {
  321.             $this->session->data['ga_secret'] = $secret = $ga->createSecret();
  322.             $this->UserModel->set(["user_ga_secret" => $secret])->where("user_id", "=", $this->session->data['user_id'])->update();
  323.         } else {
  324.             $secret = $this->session->data['ga_secret'];
  325.         }
  326.  
  327.         $this->data['g_url'] = $ga->getQRCodeGoogleUrl('BOI-'. $user['user_login'], $secret);
  328.         $this->data['g_code'] = $secret;
  329.  
  330.         $dbs->closeConnect();
  331.         return view("user/profile", $this->data);
  332.     }
  333.  
  334.     public function gauth()
  335.     {
  336.  
  337.         $this->langDetect();
  338.  
  339.         if($this->session->data['need_gauth'] === true) {
  340.             if(!empty($this->request->post['code'])) {
  341.                 library("GoogleAuthenticator");
  342.  
  343.                 $ga = new GoogleAuthenticator;
  344.                 $secret = $this->session->data['ga_secret'];
  345.  
  346.                 $oneCode = $ga->getCode($secret);
  347.  
  348.                 if($oneCode != $this->request->post['code']) {
  349.                     return view("user/gauth", ["error" => $this->lang->googleauth['error_2']]);
  350.                 } else {
  351.                     $this->session->data['user_id'] = $this->session->data['g_user_id'];
  352.                     unset($this->session->data['need_gauth']);
  353.                     unset($this->session->data['g_user_id']);
  354.  
  355.                     $this->response->redirect('/profile');
  356.                 }
  357.             }
  358.  
  359.             return view("user/gauth");
  360.         } else {
  361.             $this->response->redirect("/auth");
  362.         }
  363.     }
  364.  
  365.     public function gauthConnect()
  366.     {
  367.         model("User");
  368.  
  369.         if(!$this->session->data['user_id'])
  370.             $this->response->redirect("/auth");
  371.  
  372.         if(!empty($this->request->post['code'])) {
  373.             library("GoogleAuthenticator");
  374.  
  375.             $ga = new GoogleAuthenticator;
  376.             $secret = $this->session->data['ga_secret'];
  377.  
  378.             $oneCode = $ga->getCode($secret);
  379.  
  380.             if($oneCode != $this->request->post['code']) {
  381.                 return json_encode(["status" => "error", "error" => "Проверочный код Google Authenticator введен неверно. Повторите попытку подключения!"]);
  382.             } else {
  383.                 $this->UserModel->set(["user_ga_secret" => $secret, "user_ga_auth" => "1"])->where("user_id", "=", $this->session->data['user_id'])->update();
  384.                 return json_encode(["status" => "success", "code" => $secret]);
  385.             }
  386.         } elseif(!empty($this->request->post['dcode'])) {
  387.             if($this->request->post['dcode'] == $this->session->data['ga_secret']) {
  388.                 $this->UserModel->set(["user_ga_secret" => "", "user_ga_auth" => "0"])->where("user_id", "=", $this->session->data['user_id'])->update();
  389.                 unset($this->session->data['ga_secret']);
  390.                 return json_encode(["status" => "success"]);
  391.             } else {
  392.                 return json_encode(["status" => "error", "error" => "Секретный код Google Authenticator введен неверно. Повторите попытку!"]);
  393.             }
  394.         } else {
  395.             return json_encode(["status" => "error", "error" => "Код Google Authenticator введен неверно. Повторите попытку подключения!"]);
  396.         }
  397.     }
  398.  
  399.     private function givePrize($userid) {
  400.         model("User", "Referals");
  401.  
  402.         $referals = $this->UserModel->getReferalsCount($userid);
  403.         $user = $this->UserModel->getUser($userid);
  404.        
  405.         if($referals >= 4 && $user['user_referal_prize'] == 0 && $referals < 8) {
  406.             //Получение приза за 4 чела и больше до 8
  407.             $this->ReferalsModel->create([
  408.                 "user_id" => $userid,
  409.                 "referal_time" => "NOW()",
  410.                 "referal_level" => 1,
  411.                 "referal_users" => $referals,
  412.             ]);
  413.             $this->UserModel->set(['user_referal_prize' => 1])->where("user_id", "=", $userid)->update();
  414.             return true;
  415.         }
  416.  
  417.         if($referals >= 8 && $user['user_referal_prize'] == 1 && $referals < 16) {
  418.             //Получение приза за 8 чел и больше до 16
  419.             $this->ReferalsModel->create([
  420.                 "user_id" => $userid,
  421.                 "referal_time" => "NOW()",
  422.                 "referal_level" => 2,
  423.                 "referal_users" => $referals,
  424.             ]);
  425.             $this->UserModel->set(['user_referal_prize' => 2])->where("user_id", "=", $userid)->update();
  426.             return true;
  427.         }
  428.  
  429.         if($referals >= 16 && $user['user_referal_prize'] == 2 && $referals < 32) {
  430.             //Получение приза за 16 чел и больше до 32
  431.             $this->ReferalsModel->create([
  432.                 "user_id" => $userid,
  433.                 "referal_time" => "NOW()",
  434.                 "referal_level" => 3,
  435.                 "referal_users" => $referals,
  436.             ]);
  437.             $this->UserModel->set(['user_referal_prize' => 3])->where("user_id", "=", $userid)->update();
  438.             return true;
  439.         }
  440.  
  441.         if($referals >= 32 && $user['user_referal_prize'] == 3) {
  442.             //Получение приза за 32 и больше чел
  443.             $this->ReferalsModel->create([
  444.                 "user_id" => $userid,
  445.                 "referal_time" => "NOW()",
  446.                 "referal_level" => 4,
  447.                 "referal_users" => $referals,
  448.             ]);
  449.             $this->UserModel->set(['user_referal_prize' => 4])->where("user_id", "=", $userid)->update();
  450.             return true;
  451.         }
  452.  
  453.         return false;
  454.  
  455.     }
  456.  
  457.     public function transactions() {
  458.         if(!$this->session->data['user_id'])
  459.             $this->response->redirect("/auth");
  460.  
  461.         model("User");
  462.         $userid = $this->session->data['user_id'];
  463.         $user = $this->UserModel->getUser($userid);    
  464.         $this->data['trans'] = $this->db->getAll("SELECT * FROM `unitpay_payments` WHERE account = '{$user['user_id']}'");
  465.  
  466.         return view("user/transactions", ['user' => $user,'trans' => $this->data['trans']]);
  467.     }
  468.  
  469.     public function pay() {
  470.         if(!$this->session->data['user_id'])
  471.             $this->response->redirect("/auth");
  472.  
  473.         if($this->request->post['op']){
  474.             $this->langDetect();
  475.             $ammount = $this->request->post['ammount'];
  476.             $userid = $this->session->data['user_id'];
  477.            
  478.             $url = "https://unitpay.ru/pay/".$this->config->unitpay->public_key;
  479.             $url .= "?sum=".$ammount;
  480.             $url .= "&account=$userid";
  481.             $url .= "&desc=".$this->lang->user['pay_balane']." (ID " . $userid . ")";
  482.            
  483.             $this->response->redirect($url);
  484.         }
  485.        
  486.         $this->data['course'] = $this->db->getOne("SELECT `config_course` FROM `site_config`");
  487.  
  488.         return view("user/pay",$this->data);
  489.     }
  490.  
  491.     public function calculator() {
  492.         model("User");
  493.         $this->langDetect();
  494.         $dbs = new DBServer;
  495.         if(!$this->session->data['user_id'])
  496.             $this->response->redirect("/auth");
  497.  
  498.         $userid = $this->session->data['user_id'];
  499.         $user = $this->UserModel->getUser($userid);
  500.         $course = $this->db->getOne("SELECT `config_course` FROM `site_config`");
  501.         if($this->request->post['op']){
  502.             $sum = $this->request->post['sum'];
  503.             if($sum <= $user['user_balance'] && $sum >= 0){
  504.                 $balance = $user['user_balance'] - $sum;
  505.                 $gold = $sum * $course;
  506.                 $this->UserModel->set(['user_balance' => $balance])->where("user_id", "=", $userid)->update();
  507.                 $uid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
  508.                 $dbs->query("call usecash('{$uid}',1,0,1,0,$gold,1,@error)");
  509.                 $this->data['success'] = $this->lang->user['pay_success'];
  510.             } else {
  511.                 $this->data['error'] = $this->lang->user['no_money'];
  512.             }
  513.         }
  514.         $this->data['course'] = $course;
  515.         $this->data['user'] = $user;
  516.         $this->data['balance']  =   $user['user_balance'];
  517.         $dbs->closeConnect();
  518.         return view("user/calculator", $this->data);
  519.     }
  520.     public function testst() {
  521.         model("User");
  522.  
  523.         // $data = $this->db->getAll("SELECT SUM(sum) AS sum,account FROM unitpay_payments WHERE dateComplete IS NOT NULL GROUP BY account");
  524.         // foreach($data as $item)
  525.         // {
  526.         //  $percent = $item['sum']*0.10;
  527.         //  $this->db->query("UPDATE `site_users` SET `user_balance` = user_balance + {$percent} WHERE `user_id` = {$item['account']}");
  528.         // }
  529.     //  $dbs = new DBServer;
  530.        
  531.     //  $users = $dbs->getAll("SELECT name,ID FROM users WHERE qq = ''");
  532.  
  533.     //  foreach($users as $item)
  534.     //  {
  535.     //      $ids[$item['ID']] = $this->db->getOne("SELECT user_id FROM site_users WHERE user_login = '{$item['name']}'");
  536.     //  }
  537.     //  foreach($ids as $idg => $idc)
  538.     //  {
  539.     //      $dbs->query("UPDATE users SET `qq` = '{$idc}' WHERE `ID` = '{$idg}'");
  540.     //  }
  541.  
  542.     }
  543.     public function editpass() {
  544.         if(!$this->session->data['user_id'])
  545.             $this->response->redirect("/auth");
  546.  
  547.         $dbs = new DBServer;
  548.         model("User");
  549.         $this->langDetect();
  550.  
  551.         if($this->request->post['op']){
  552.             $password = $this->request->post['password'];
  553.             $npassword = $this->request->post['npassword'];
  554.             $rnpassword = $this->request->post['rnpassword'];
  555.             $user = $this->UserModel->getUser($this->session->data['user_id']);
  556.             if($user['user_password'] == md5($password)){
  557.                 if($password != $npassword){
  558.                     if($rnpassword == $npassword){
  559.                         if(preg_match("/^[a-z0-9]{6,32}$/", $npassword)) {
  560.                             $this->UserModel->where("user_id", "=", $this->session->data['user_id'])->set(["user_password" => md5($npassword)])->update();
  561.                             $login = $user['user_login'];
  562.                             $pass = $npassword;
  563.                             $Salt = $login.$pass;
  564.                             $Salt = md5($Salt);
  565.                             $Salt = "0x".$Salt;
  566.                             $dbs->query("call changePasswd('$login', $Salt)");
  567.                             $this->data['success'] = $this->lang->user['pass_edit_success'];
  568.                         } else {
  569.                             $this->data['error'] = $this->lang->user['pass_mistach'];
  570.                         }
  571.                     } else {
  572.                         $this->data['error'] = $this->lang->user['pass_error'];
  573.                     }
  574.                 } else {
  575.                     $this->data['error'] = $this->lang->user['pass_must_not_match'];
  576.                 }
  577.             } else {
  578.                 $this->data['error'] = $this->lang->user['current_pass_error'];
  579.             }
  580.            
  581.         }
  582.         $dbs->closeConnect();
  583.         return view("user/editpass", $this->data);
  584.     }
  585.  
  586.     public function restore() {
  587.         $dbs = new DBServer;
  588.         model("User");
  589.         $this->langDetect();
  590.  
  591.         if($this->request->post['op']){
  592.             $login = $this->request->post['user_login'];
  593.             $email = $this->request->post['user_email'];
  594.  
  595.             if($user = $this->UserModel->getUser($login, 'user_login')){
  596.                 if($user['user_email'] == $email){
  597.                     $password = time()."maksa988";
  598.                     $password = md5($password);
  599.                     $password = mb_substr($password, 3, 16);
  600.  
  601.                     $this->UserModel->where("user_login", "=", $login)->set(["user_password" => md5($password), "user_ga_auth" => 0])->update();
  602.                     $login = $user['user_login'];
  603.                     $pass = $password;
  604.                     $Salt = $login.$pass;
  605.                     $Salt = md5($Salt);
  606.                     $Salt = "0x".$Salt;
  607.                     $dbs->query("call changePasswd('$login', $Salt)");
  608.                     $this->UserModel->sendRestore($email, $password);
  609.                     $this->data['success'] = $this->lang->user['new_pass_sended'];
  610.                 } else {
  611.                     $this->data['error'] = $this->lang->user['login_and_email'];
  612.                 }
  613.             } else {
  614.                 $this->data['error'] = $this->lang->user['login_and_email'];
  615.             }
  616.         }
  617.         $dbs->closeConnect();
  618.        
  619.         if($this->session->data['user_id'])
  620.             $this->response->redirect("/profile");
  621.  
  622.         return view("user/restore", $this->data);
  623.     }
  624.  
  625.     public function chars() {
  626.         if(!$this->session->data['user_id'])
  627.             $this->response->redirect("/auth");
  628.  
  629.  
  630.         model("User");
  631.  
  632.         $this->data['chars'] = $this->UserModel->getChars($this->session->data['user_id']);
  633.         return view("user/chars", $this->data);
  634.     }
  635.  
  636.     private function langDetect() {
  637.         library("Lang");
  638.         $LangLib = new Lang;
  639.  
  640.         if(!empty($this->request->cookie['__lang'])) {
  641.             $lang = $this->request->cookie['__lang']."_lang";
  642.  
  643.             $this->lang = ($this->request->cookie['__lang'] == 'ru' or $this->request->cookie['__lang'] == 'en') ? $this->config->$lang : $this->config->en_lang;
  644.         } else {
  645.             $langs = array(
  646.               'ru' => array('ru', 'be', 'uk', 'ky', 'ab', 'mo', 'et', 'lv')
  647.             );
  648.             $lang = $LangLib->getBestMatch('en', $langs);
  649.  
  650.             $this->lang = $this->config->$lang."_lang";
  651.             setcookie("__lang", $lang, time()+60*60*24*30);
  652.         }
  653.     }
  654. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement