Password modification working.
This commit is contained in:
parent
ffdee544cb
commit
653f50c33d
4
TODO
4
TODO
@ -6,7 +6,3 @@ install.php :
|
||||
=============
|
||||
* Link beside password field to toggle visible / not visible
|
||||
* TRUNCATE before CREATE TABLE in install.php
|
||||
|
||||
index.php :
|
||||
===========
|
||||
* Edit password doesn't work
|
||||
|
@ -123,7 +123,7 @@ class Storage {
|
||||
$query .= $field.'=:'.$field;
|
||||
}
|
||||
|
||||
$query .= 'WHERE id='.$this->id;
|
||||
$query .= ' WHERE id='.$this->id;
|
||||
}
|
||||
else {
|
||||
$query = 'INSERT INTO '.MYSQL_PREFIX.$this->TABLE_NAME.'(';
|
||||
@ -147,6 +147,7 @@ class Storage {
|
||||
$query .= ')';
|
||||
}
|
||||
|
||||
$this->connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
$query = $this->connection->prepare($query);
|
||||
|
||||
foreach($this->fields as $field=>$type) {
|
||||
|
@ -29,7 +29,7 @@ class User extends Storage {
|
||||
}
|
||||
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
$this->id = (int) $id;
|
||||
}
|
||||
|
||||
public function setLogin($login) {
|
||||
@ -41,7 +41,7 @@ class User extends Storage {
|
||||
}
|
||||
|
||||
public function setAdmin($admin) {
|
||||
$this->admin = $admin;
|
||||
$this->admin = (bool) $admin;
|
||||
}
|
||||
|
||||
public function encrypt($text) {
|
||||
@ -55,6 +55,7 @@ class User extends Storage {
|
||||
public function exists() {
|
||||
$user_data = $this->load(array('login'=>$this->login));
|
||||
if(count($user_data) == 1) {
|
||||
$this->setId($user_data[0]['id']);
|
||||
$this->setAdmin($user_data[0]['admin']);
|
||||
$this->setPassword($user_data[0]['password']);
|
||||
|
||||
@ -69,8 +70,11 @@ class User extends Storage {
|
||||
return serialize(array('id'=>$this->id, 'login'=>$this->login, 'password'=>$this->password, 'admin'=>$this->admin));
|
||||
}
|
||||
|
||||
public function sessionRestore($serialized_data) {
|
||||
$user_data = unserialize($serialized_data);
|
||||
public function sessionRestore($data, $serialized) {
|
||||
if($serialized)
|
||||
$user_data = unserialize($serialized_data);
|
||||
else
|
||||
$user_data = $data;
|
||||
|
||||
$this->setId($user_data['id']);
|
||||
$this->setLogin($user_data['login']);
|
||||
|
@ -57,10 +57,8 @@
|
||||
if(!empty($_POST['password']) && !empty($_POST['password_confirm'])) {
|
||||
if($_POST['password'] == $_POST['password_confirm']) {
|
||||
$user = new User();
|
||||
$user->setLogin($current_user['login']);
|
||||
$user->sessionRestore($current_user, false);
|
||||
$user->setPassword($user->encrypt($_POST['password']));
|
||||
$user->setAdmin($current_user['admin']);
|
||||
$user->setId($current_user['id']);
|
||||
$user->save();
|
||||
|
||||
header('location: index.php');
|
||||
|
Loading…
Reference in New Issue
Block a user