id = $id;
$this->pass = $pass;
$this->email = $email;
$this->realname = $realname;
$this->borndate = $borndate;
$this->info = $info;
$this->ip = $ip;
}
public function changePassword($oldPassword, $newPassword)
{
if (password_verify($oldPassword, $this->pass)) {
$this->pass = password_hash($newPassword, PASSWORD_DEFAULT);
} else {
$this->status .= 'Неверный пароль!';
}
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail(string $email): void
{
$this->email = $email;
}
/**
* @return string
*/
public function getRealname(): string
{
return $this->realname;
}
/**
* @param string $realname
*/
public function setRealname(string $realname): void
{
$this->realname = htmlspecialchars($realname);
}
/**
* @return string
*/
public function getBorndate(): string
{
return $this->borndate;
}
/**
* @param string $borndate
*/
public function setBorndate(string $borndate): void
{
$this->borndate = $borndate;
}
/**
* @return string
*/
public function getInfo(): string
{
return $this->info;
}
/**
* @param string $info
*/
public function setInfo(string $info): void
{
if (strlen($info) > self::INFO_CHAR_LIMIT) {
$this->status .= 'Максимальная длинна поля Хобби: ' . self::INFO_CHAR_LIMIT . ' символов!';
} else {
$info = htmlspecialchars($info);
$info = str_replace("\\n", '
', $info);
$info = str_replace("\\r", '', $info);
$info = str_replace('<br />', '
', $info);
$this->info = $info;
}
}
/**
* @return string
*/
public function getIp(): string
{
return $this->ip;
}
/** Сохраняет в базу актуальные имя, пароль, email, дату рождения, текст инфы.
*
*/
public function save(): string
{
if ($this->status) {
return $this->status;
}
$query = 'update users set pass = ?, email = ?, realname = ?, borndate = ?, info = ? where id = ?';
$vals = [
//set
$this->pass,
$this->email,
$this->realname,
$this->borndate,
$this->info,
// where
$this->id
];
Db::getInstance()->execute($query, $vals);
return 'Успешно!';
}
}