Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hava
  5. * Date: 01.02.16
  6. * Time: 16:10
  7. */
  8.  
  9. namespace HavaModules;
  10. use MysqlSettings;
  11.  
  12. class User
  13. {
  14. public $login, $email, $password, $password1,$IamIdiot;
  15. public $peremoga;
  16. public $create_info;
  17.  
  18.  
  19.  
  20. function __construct($log, $mail, $pass, $pass1, $checkbox)
  21. {
  22. $this->login = $log;
  23. $this->email = $mail;
  24. $this->password = $pass;
  25. $this->password1 = $pass1;
  26. $this->IamIdiot = $checkbox;
  27. }
  28.  
  29. protected function loginvalid($log){
  30. $login_peremoga='';
  31. if(!preg_match("/^[a-zA-Z0-9а-яА-Я]+$/",$log)){
  32. $login_peremoga='Недопустимые символы в логине.<br>';
  33. }
  34. if (strlen($log)<3 or strlen($log)>30){
  35. $login_peremoga=$login_peremoga.'Логин должен быть от 3 до 30 символов.<br>';
  36. }
  37. //проверка на допустимые символы и длинну логина закончена
  38. If ($log<>null){
  39. $myconnect = MysqlSettings::getConnection();
  40. if (MysqlSettings::getConnection()->connect_error) {
  41. $this->showbalet('Ошибка подключения к базе данных');
  42. }
  43. $check_login = 'SELECT * FROM users WHERE login=\'' . $log . '\';';
  44. $check_login_result = $myconnect->query($check_login);
  45. if ($check_login_result->num_rows > 0) {
  46. $login_peremoga = $login_peremoga . 'Такой логин уже занят.';
  47. }
  48. }
  49. //проверка на занятость логина
  50. return $login_peremoga;
  51. }
  52.  
  53. protected function mailvalid($mail){
  54. $mail_peremoga='';
  55. if ($mail<>null)
  56. {
  57. if (strlen($mail) < 5) $mail_peremoga = 'Неправильно указано мыло.';
  58. if (strpos($mail, '@') == 0) $mail_peremoga = 'Неправильно указано мыло.';
  59. if (strpos($mail, '.') == 0) $mail_peremoga = 'Неправильно указано мыло.';
  60.  
  61. //проверка на допустимое мыло
  62. $myconnect=MysqlSettings::getConnection();
  63. if (MysqlSettings::getConnection()->connect_error)
  64. {
  65. $this->showbalet('Ошибка подключения к базе данных');
  66. }
  67. $check_mail='SELECT * FROM users WHERE mail=\'' . $mail .'\';';
  68. $check_login_result=$myconnect->query($check_mail);
  69. if ($check_login_result->num_rows>0) {
  70. $mail_peremoga=$mail_peremoga . 'Такое мыло уже занято.';
  71. }
  72. }
  73. else $mail_peremoga = 'Неуказано мыло.';
  74. return $mail_peremoga;
  75. }
  76.  
  77. protected function passvalid($p1,$p2)
  78. {
  79. $pass_peremoga='';
  80. If ($p1==null) $pass_peremoga='Не указан пароль. <br>';
  81. else {
  82. If (strlen($p1) < 8)
  83. $pass_peremoga = 'Пароль полное говно, короткий. <br>';
  84. if ($p1 <> $p2) $pass_peremoga = $pass_peremoga . 'Пароли нихуйца не совпадают. <br> ';
  85. }
  86. return $pass_peremoga;
  87. }
  88.  
  89. public function validUser(){
  90.  
  91. $create_info='';
  92. if (($this->login==null) and ($this->password==null) and ($this->password1==null) and ($this->email==null))
  93. { $create_info='Заполни анкету.';}
  94. else {
  95. $a=$this->loginvalid($this->login);
  96. $create_info = $create_info . $a;
  97. $a=$this->passvalid($this->password,$this->password1);
  98. $create_info=$create_info.$a;
  99. $a=$this->mailvalid($this->email);
  100. $create_info=$create_info.$a;
  101. //if ($this->IamIdiot == true) $create_info = $create_info . 'ТЫ НЕ ЕБАНУТ!111. <br> ';
  102.  
  103. }
  104. $this->create_info=$create_info;
  105. }
  106.  
  107.  
  108. <?php
  109. /**
  110. * Created by PhpStorm.
  111. * User: hava
  112. * Date: 25.01.16
  113. * Time: 15:04
  114. */
  115.  
  116.  
  117. namespace Controllers;
  118.  
  119.  
  120. use HavaModules\Api_key;
  121. use HavaModules\hash_password;
  122. use HavaModules\Kote;
  123. use HavaModules\User;
  124. use MysqlSettings;
  125.  
  126. class registration extends BaseContoller
  127. {
  128.  
  129. public function index()
  130. {
  131. $myconnect=MysqlSettings::getConnection();
  132. if (MysqlSettings::getConnection()->connect_error)
  133. {
  134. $this->showbalet('Ошибка подключения к базе данных');
  135.  
  136. }
  137.  
  138.  
  139. $new_user= new User($_REQUEST ["login"],$_REQUEST ["email"],$_REQUEST ["password"],$_REQUEST ["password1"],$_REQUEST ["checkbox"]);
  140. $new_user->validUser();
  141. $info=$new_user->create_info;
  142. if ($new_user->create_info==NULL) {
  143. $hash_pass=sha1('onotole' . sha1($new_user->password) . 'up4k');
  144. //$hash_pass=hash_password::hash_this_str($new_user->password);
  145. //var_dump($aa);die;
  146. $new_api_key=$this->Generate_api_key();
  147. $qs = 'INSERT INTO users(`login`,`pass`,`user_api_key`,`pepycka`,`mail`,`group`)
  148. VALUES(\'' .
  149. $new_user->login . '\',\'' .
  150. $hash_pass . '\',\'' .
  151. $new_api_key . '\',\'' .
  152. 0 . '\',\'' .
  153. $new_user->email . '\',\'' .
  154. 1 .'\')';
  155. //var_dump($qs);die;
  156. $result_response_bd=$myconnect->query($qs);
  157. }
  158.  
  159. $new_kote= new Kote();
  160. $this->templateEngine->assign('lepro_kote',$new_kote->link_kote);
  161. $this->templateEngine->assign('content','registration.tpl');
  162. $this->templateEngine->assign('header_text','РЕГИСТРАЦИЯ РИАЛЬНЕ');
  163. $this->templateEngine->assign('psto',$info);
  164. $this->templateEngine->display('glagne.tpl');
  165.  
  166.  
  167. }
  168.  
  169. public function Generate_api_key(){
  170. $length=15;
  171. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
  172. $code = "";
  173. $clen = strlen($chars) - 1;
  174. while (strlen($code) < $length) {
  175.  
  176. $code .= $chars[mt_rand(0,$clen)];
  177. }
  178. $code=sha1($code);
  179. return $code;
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement