Файл: modules/user/security.php
Строк: 80
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013-2014, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
$locate = 'in_cabinet';
if(isset($user)) {
if(isset($_POST['save_email']) && $_GET['act']== 'change_mail') {
$email = input($_POST['nemail']);
if (!empty($email) && (mb_strlen($email, 'UTF-8') < 3 || mb_strlen($email, 'UTF-8') > 72)) $err .= _t('b_mail').'<br />';
if (!empty($email) && !preg_match('|^([a-z0-9_.-]{1,20})@([a-z0-9.-]{1,20}).([a-z]{2,4})$|ius', $email)) $err .= _t('e_email').'<br />';
if(crypto($_POST['pass']) == $user['password'] && $_POST['cemail'] == $user['email']) {
if($db->query("SELECT * FROM `users` WHERE `email` = '$email'")->rowCount() == 0) {
$db->query("UPDATE `users` SET `email` = '". $email."' WHERE `id` = '". $user['id']."' ");
// print_r($db->errorInfo());
go('/user/security/?act=edited');
}
} else { $err .= _t('ex_mail').'<br/>'; }
}
if(isset($_POST['save_pass']) && $_GET['act']== 'change_pass') {
$pass1 = input($_POST['npass']);
$pass = input($_POST['pass']);
if (!empty($pass1) && (mb_strlen($pass1, 'UTF-8') < 5 || mb_strlen($pass1, 'UTF-8') > 64)) $err .= _t('e_pass').'<br />';
if (!empty($pass1) && !empty($pass) && $pass1 != $pass) $err .= _t('e_pass2').'<br />';
if(crypto(input($_POST['cpass'])) == $user['password']) {
$db->query("UPDATE `users` SET `password` = '". crypto($pass)."' WHERE `id` = '". $user['id']."' ");
unset($_COOKIE);
$_SESSION['password'] = crypto($pass);
setcookie('password', crypto($pass), time()+60*60*24*1024, '/');
// print_r($db->errorInfo());
redirect('/');
} else { $err .= _t('ex_mail').'<br/>'; }
}
$title = _t('security');
include_header($title);
if($_GET['act']=='edited') {$tpl->div('block', _t('succ_save'));}
$tpl->div('title', _t('security'));
if(isset($err)) $tpl->div('error', $err);
$tpl->div('menu', _t('security_t'));
$tpl->div('title', _t('change_mail'));
echo '<form action="?act=change_mail" method="post">
<div class="post">
<b>'. _t('current') .' E-Mail</b>:<br/>
<input type="text" name="cemail" value="'. $user['email'] .'" /><br/>
<b>'. _t('new_e') .' E-Mail:</b><br/>
<input type="text" name="nemail"/><br/>
<b>'. _t('current') .' '. _t('password') .'</b>:<br/>
<input type="password" name="pass"/><br/>
<input type="submit" name="save_email" value="'. _t('save') .'" /><br/>
</div>
</form>';
$tpl->div('title', _t('change_pass'));
echo '<form action="?act=change_pass" method="post">
<div class="post">
<b>'. _t('current') .' '. _t('password') .'</b>:<br/>
<input type="text" name="cpass" /><br/>
<b>'. _t('new_e') .' '. _t('password') .'</b><br/>
<input type="text" name="npass"/><br/>
<b>'. _t('confirm') .' '. _t('password') .'</b>:<br/>
<input type="text" name="pass"/><br/>
<input type="submit" name="save_pass" value="'. _t('save') .'" /><br/>
</div>
</form>';
$tpl->div('block', NAV.'<a href="/user/panel/">'._t('user_panel').'</a><br/>'. HICO .'<a href="/">'. _t('home') .'</a>');
include_footer();
} else { go('/'); }
?>