Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: hava
- * Date: 01.02.16
- * Time: 16:10
- */
- namespace HavaModules;
- use MysqlSettings;
- class User
- {
- public $login, $email, $password, $password1,$IamIdiot;
- public $peremoga;
- public $create_info;
- function __construct($log, $mail, $pass, $pass1, $checkbox)
- {
- $this->login = $log;
- $this->email = $mail;
- $this->password = $pass;
- $this->password1 = $pass1;
- $this->IamIdiot = $checkbox;
- }
- protected function loginvalid($log){
- $login_peremoga='';
- if(!preg_match("/^[a-zA-Z0-9а-яА-Я]+$/",$log)){
- $login_peremoga='Недопустимые символы в логине.<br>';
- }
- if (strlen($log)<3 or strlen($log)>30){
- $login_peremoga=$login_peremoga.'Логин должен быть от 3 до 30 символов.<br>';
- }
- //проверка на допустимые символы и длинну логина закончена
- If ($log<>null){
- $myconnect = MysqlSettings::getConnection();
- if (MysqlSettings::getConnection()->connect_error) {
- $this->showbalet('Ошибка подключения к базе данных');
- }
- $check_login = 'SELECT * FROM users WHERE login=\'' . $log . '\';';
- $check_login_result = $myconnect->query($check_login);
- if ($check_login_result->num_rows > 0) {
- $login_peremoga = $login_peremoga . 'Такой логин уже занят.';
- }
- }
- //проверка на занятость логина
- return $login_peremoga;
- }
- protected function mailvalid($mail){
- $mail_peremoga='';
- if ($mail<>null)
- {
- if (strlen($mail) < 5) $mail_peremoga = 'Неправильно указано мыло.';
- if (strpos($mail, '@') == 0) $mail_peremoga = 'Неправильно указано мыло.';
- if (strpos($mail, '.') == 0) $mail_peremoga = 'Неправильно указано мыло.';
- //проверка на допустимое мыло
- $myconnect=MysqlSettings::getConnection();
- if (MysqlSettings::getConnection()->connect_error)
- {
- $this->showbalet('Ошибка подключения к базе данных');
- }
- $check_mail='SELECT * FROM users WHERE mail=\'' . $mail .'\';';
- $check_login_result=$myconnect->query($check_mail);
- if ($check_login_result->num_rows>0) {
- $mail_peremoga=$mail_peremoga . 'Такое мыло уже занято.';
- }
- }
- else $mail_peremoga = 'Неуказано мыло.';
- return $mail_peremoga;
- }
- protected function passvalid($p1,$p2)
- {
- $pass_peremoga='';
- If ($p1==null) $pass_peremoga='Не указан пароль. <br>';
- else {
- If (strlen($p1) < 8)
- $pass_peremoga = 'Пароль полное говно, короткий. <br>';
- if ($p1 <> $p2) $pass_peremoga = $pass_peremoga . 'Пароли нихуйца не совпадают. <br> ';
- }
- return $pass_peremoga;
- }
- public function validUser(){
- $create_info='';
- if (($this->login==null) and ($this->password==null) and ($this->password1==null) and ($this->email==null))
- { $create_info='Заполни анкету.';}
- else {
- $a=$this->loginvalid($this->login);
- $create_info = $create_info . $a;
- $a=$this->passvalid($this->password,$this->password1);
- $create_info=$create_info.$a;
- $a=$this->mailvalid($this->email);
- $create_info=$create_info.$a;
- //if ($this->IamIdiot == true) $create_info = $create_info . 'ТЫ НЕ ЕБАНУТ!111. <br> ';
- }
- $this->create_info=$create_info;
- }
- <?php
- /**
- * Created by PhpStorm.
- * User: hava
- * Date: 25.01.16
- * Time: 15:04
- */
- namespace Controllers;
- use HavaModules\Api_key;
- use HavaModules\hash_password;
- use HavaModules\Kote;
- use HavaModules\User;
- use MysqlSettings;
- class registration extends BaseContoller
- {
- public function index()
- {
- $myconnect=MysqlSettings::getConnection();
- if (MysqlSettings::getConnection()->connect_error)
- {
- $this->showbalet('Ошибка подключения к базе данных');
- }
- $new_user= new User($_REQUEST ["login"],$_REQUEST ["email"],$_REQUEST ["password"],$_REQUEST ["password1"],$_REQUEST ["checkbox"]);
- $new_user->validUser();
- $info=$new_user->create_info;
- if ($new_user->create_info==NULL) {
- $hash_pass=sha1('onotole' . sha1($new_user->password) . 'up4k');
- //$hash_pass=hash_password::hash_this_str($new_user->password);
- //var_dump($aa);die;
- $new_api_key=$this->Generate_api_key();
- $qs = 'INSERT INTO users(`login`,`pass`,`user_api_key`,`pepycka`,`mail`,`group`)
- VALUES(\'' .
- $new_user->login . '\',\'' .
- $hash_pass . '\',\'' .
- $new_api_key . '\',\'' .
- 0 . '\',\'' .
- $new_user->email . '\',\'' .
- 1 .'\')';
- //var_dump($qs);die;
- $result_response_bd=$myconnect->query($qs);
- }
- $new_kote= new Kote();
- $this->templateEngine->assign('lepro_kote',$new_kote->link_kote);
- $this->templateEngine->assign('content','registration.tpl');
- $this->templateEngine->assign('header_text','РЕГИСТРАЦИЯ РИАЛЬНЕ');
- $this->templateEngine->assign('psto',$info);
- $this->templateEngine->display('glagne.tpl');
- }
- public function Generate_api_key(){
- $length=15;
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
- $code = "";
- $clen = strlen($chars) - 1;
- while (strlen($code) < $length) {
- $code .= $chars[mt_rand(0,$clen)];
- }
- $code=sha1($code);
- return $code;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement