From b70494f1ab9fbccea96c69c87ba8a3e4fdc426b7 Mon Sep 17 00:00:00 2001 From: "Alfonso Saavedra \"Son Link" Date: Sun, 3 Apr 2022 15:51:46 +0200 Subject: [PATCH] Users: Fixed a bug when receiving multiple data not covered when saving users --- app/Models/UsersModel.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/Models/UsersModel.php b/app/Models/UsersModel.php index 7b8559a..faf44d5 100644 --- a/app/Models/UsersModel.php +++ b/app/Models/UsersModel.php @@ -350,24 +350,29 @@ class UsersModel extends Model 'msg' => '' ]; - unset($data['passwordcheck']); - unset($data['phrase']); + $user = [ + 'username' => $data['username'], + 'email' => $data['email'], + 'nation' => $data['nation'], + 'username' => $data['username'], + ]; // First verify if the user or email $sql = $this->db->table('users'); - $sql->where('username', $data['username']); - $sql->orWhere('email', $data['email']); + $sql->where('username', $user['username']); + $sql->orWhere('email', $user['email']); $query = $sql->get(1); + if ($query && $query->getNumRows() == 1){ $response['msg'] = 'Username and/or email are registered'; } else { // 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 - $sql->insert($data); + $sql->insert($user); $error = $this->db->error(); if ($error['code'] != 0) { @@ -378,7 +383,7 @@ class UsersModel extends Model $id = $this->db->insertID(); $sql->resetQuery(); // Move the file to it's new home - $filename = $data['username'] . '.' . $image->getExtension(); + $filename = $user['username'] . '.' . $image->getExtension(); $image->move(FCPATH . '/img/users/', $filename); $sql->where('id', $id)->update(['img' => $filename]); $response['ok'] = true;