C4 Latest version shield manage users |
So i have been playing around with the newest version of shield and really be running in a circle with the manage users, so shield creates a user model default I have made a create user and delete user and update user, create users was a bit tricky using just the code example here the update user has me just stumped, if i edit user then it says username taken, or password required.
My question is how to validate when info has changed so if I edit user name John profile but dont change his username it shouldn't say username taken same for email public function update($id) { $users = auth()->getProvider(); $user = $users->findById($id); $validation = \Config\Services::validation(); $validation->setRules([ 'username' => 'required|is_unique[users.username]', 'email' => 'required|is_unique[auth_identities.secret]' ]); $data = [ 'username' => $this->request->getPost('username'), 'email' => $this->request->getPost('email') ]; if (!$user->hasChanged()) { return redirect()->back() ->with("message", "Nothing to update."); } if ($validation->run($data)) { $user->fill([ 'username' => $data['username'], 'email' => $data['email'] ]); $users->update($user); return redirect()->to("admin/dashboard/manage-users") ->with("message", "User updated."); } return redirect()->back() ->with('errors', $validation->getErrors()) ->withInput(); }
Try add validation error message as follows:
PHP Code: $validation->setRules([
@xxxx[{::::::::::::::::::::::::::::::::>
That changes nothing, if i edit a user lets say email if i change email it tells me username is taken
Read https://codeigniter.com/user_guide/libra...aceholders
let say $id = 4 So it will ignore the row in the database that has id=4 when it verifies the email or username is unique.
@xxxx[{::::::::::::::::::::::::::::::::>
This code is dangerous. Because an attacker can send any values to your server.
Be sure that $id does not have invalid value as the id value (number only?) before running this code. PHP Code: $validation->setRules([
do thid
PHP Code: <?php Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
|
Welcome Guest, Not a member yet? Register Sign In |