View file enter.php

File size: 3.93Kb
<?php
// coding by Felis
require_once('sys/kernel.php');
require_once('temp/cap.php');

switch($mode)
{
	default:
	if($op == true)
	{
		header('Location: main.php'); exit;
	}
	if(!$_POST)
	{
		echo $fnc->alert('Войти', '<form action="'.CFILE.'" method="post">
		<input type="hidden" name="login" />
		<input type="hidden" name="password" />
		Логен:<br />
		<input type="text" name="_post_field_1_" /><br />
		Пороль:<br />
		<input type="password" name="_post_field_2_" /><br />
		<input type="checkbox" name="_post_field_3_" value="1" /> Запомнить<br />
		<input type="submit" value="Войти" />
		</form>');
		echo $fnc->cont2('<a href="'.CFILE.'?mode=restore">Восстановление пароля</a>');
	}
	else
	{
		$username = $fnc->out($_POST['_post_field_1_'], 1);
		$password = $fnc->out($_POST['_post_field_2_'], 1);
		$cookie = (int)$_POST['_post_field_3_'];
		
		if(empty($username))
		{
			header('Location: '.CFILE);
		}
		else
		{
			$log = $db->query("SELECT `id`,`passwd`,`banned`,`ban_point`,`ban_term`,`access` FROM `users` WHERE `login`='$username' LIMIT 1");
			if($log->num_rows > 0)
			{
				$pl = $log->fetch_assoc();
				if($fnc->encode($password) == $pl['passwd'])
				{
					if($time - $pl['ban_point'] < $pl['ban_term'] and $pl['access'] != 'a')
					{
						echo $fnc->alert('Ошибка!', 'Вы забанены в чате '.date('d '.$fnc->rm(date('m')).', H:i:s', $pl['ban_point']).' сроком на '.round($pl['ban_term'] / 60, 2).' мин!<br />Пожалуйста, ожидайте истечения срока бана..');
						echo $fnc->cont('<a href="main.php">На главную</a>');
					}
					else
					{
						$_SESSION['id'] = $pl['id'];
						$_SESSION['passwd'] = $password;
						
						if($cookie == 1)
						{
							setcookie('id', base64_encode($_SESSION['id']), time() + $sec['month']);
							setcookie('passwd', base64_encode($_SESSION['passwd']), time() + $sec['month']);
						}
						
						$db->query("UPDATE `users` SET `lastdate`=$time WHERE `id`=".$_SESSION['id']);
						header('Location: main.php');
					}
				}
				else { header('Location: '.CFILE); }
			}
			else { header('Location: '.CFILE); }
		}
	}
	break;

	case 'logout':
		session_unset();
		session_destroy();
		
		setcookie('id', NULL);
		setcookie('passwd', NULL);
	header('Location: main.php');
	break;
	
	case 'restore':
		if(!$_POST)
		{
			echo $fnc->alert('Восстановление пароля', '<form action="'.CFILE.'?mode=restore" method="post">
			<!-- E-mail -->
			<input type="hidden" name="mail" />
			Введите E-mail:<br />
			<input type="text" name="_postfield" /><br />
			<input type="submit" value="Выслать" />
			</form>');
		}
		else
		{
			$mail = $fnc->out($_POST['_postfield'], 1);
			$check_user = $db->query("SELECT `id`,`login`,`mail` FROM `users` WHERE `mail`='$mail' LIMIT 1");
			if($check_user->num_rows > 0)
			{
				$restore = $check_user->fetch_assoc();
				$restore_passwd = mt_rand(1111111, 9999999);
				
				if(mail($restore['mail'], '=?utf-8?B?'.base64_encode($conf['sitename'].' - Восстановление пароля').'?=', 'Здравствуйте, '.$restore['login'].'. Ваш новый пароль в чате "'.$conf['sitename'].'" - '.$restore_passwd."\r\n" .'Приятного общения!', 'From: robot@'.ADDRESS."\r\nContent-type: text/html; charset=utf-8;\r\nX-Mailer: ".$conf['sitename']))
				{
					$db->query("UPDATE `users` SET `passwd`='".$fnc->encode($restore_passwd)."' WHERE `id`=".$restore['id']." LIMIT 1");
					header('Location: main.php');
				}
				else
				{
					echo $fnc->alert('Ошибка!', _ERROR);
				}
			}
			else
			{
				echo $fnc->alert('Ошибка!', 'Данного пользователя не существует..');
			}
		}
	break;
}

require_once('temp/foot.php');

// конец файла ./enter.php