Users: Fixed a bug when receiving multiple data not covered when saving users
This commit is contained in:
parent
c776e0e915
commit
b70494f1ab
|
@ -350,24 +350,29 @@ class UsersModel extends Model
|
||||||
'msg' => ''
|
'msg' => ''
|
||||||
];
|
];
|
||||||
|
|
||||||
unset($data['passwordcheck']);
|
$user = [
|
||||||
unset($data['phrase']);
|
'username' => $data['username'],
|
||||||
|
'email' => $data['email'],
|
||||||
|
'nation' => $data['nation'],
|
||||||
|
'username' => $data['username'],
|
||||||
|
];
|
||||||
|
|
||||||
// First verify if the user or email
|
// First verify if the user or email
|
||||||
$sql = $this->db->table('users');
|
$sql = $this->db->table('users');
|
||||||
$sql->where('username', $data['username']);
|
$sql->where('username', $user['username']);
|
||||||
$sql->orWhere('email', $data['email']);
|
$sql->orWhere('email', $user['email']);
|
||||||
$query = $sql->get(1);
|
$query = $sql->get(1);
|
||||||
|
|
||||||
if ($query && $query->getNumRows() == 1){
|
if ($query && $query->getNumRows() == 1){
|
||||||
$response['msg'] = 'Username and/or email are registered';
|
$response['msg'] = 'Username and/or email are registered';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Encrypt the password
|
// Encrypt the password
|
||||||
$data['password'] = password_hash($data['password'], self::HASH, [self::COST]);
|
$user['password'] = password_hash($data['password'], self::HASH, [self::COST]);
|
||||||
|
unset($data);
|
||||||
// Insert data
|
// Insert data
|
||||||
$sql->insert($data);
|
$sql->insert($user);
|
||||||
$error = $this->db->error();
|
$error = $this->db->error();
|
||||||
if ($error['code'] != 0)
|
if ($error['code'] != 0)
|
||||||
{
|
{
|
||||||
|
@ -378,7 +383,7 @@ class UsersModel extends Model
|
||||||
$id = $this->db->insertID();
|
$id = $this->db->insertID();
|
||||||
$sql->resetQuery();
|
$sql->resetQuery();
|
||||||
// Move the file to it's new home
|
// Move the file to it's new home
|
||||||
$filename = $data['username'] . '.' . $image->getExtension();
|
$filename = $user['username'] . '.' . $image->getExtension();
|
||||||
$image->move(FCPATH . '/img/users/', $filename);
|
$image->move(FCPATH . '/img/users/', $filename);
|
||||||
$sql->where('id', $id)->update(['img' => $filename]);
|
$sql->where('id', $id)->update(['img' => $filename]);
|
||||||
$response['ok'] = true;
|
$response['ok'] = true;
|
||||||
|
|
Loading…
Reference in New Issue