/** * Edit user * @param string $edit_user (Optional) Whether to edit a user * @param string $user_id User ID * @param string $user_first_name First name * @param string $user_last_name Last name * @param string $user_email Email address * @param string $user_active Active status * @param string $user_admin Admin status * @param string $user_password (Optional) New password * @param string $user_password_confirm (Optional) Password confirmation */ public function edit() { $id = $this->getArg('id'); if (!\Sonic\Model\User::_IDexists($id)) { new \Sonic\Resource\Redirect('index', array('error' => 'Invalid User')); } $user = \Sonic\Model\User::_read($id); $this->view->assignByRef('newuser', $user); if ($this->getArg('edit_user')) { // User data $user->fromPost(TRUE, array('first_name', 'last_name', 'email', 'active', 'admin')); if (\Sonic\Message::count('error')) { return FALSE; } // New password $exclude = array(); if ($user->get('password')) { if ($user->get('password') !== $this->getArg('user_password_confirm')) { new \Sonic\Message('error', 'The new passwords did not match, please try again'); return; } } else { $exclude[] = 'password'; } // Update if (!$user->update($exclude)) { new \Sonic\Message('error', 'User update failed, please try again'); return; } // Success $user->read(); new \Sonic\Message('success', 'User Updated'); } }
/** * Delete user * @return integer $id User ID */ public function delete() { $id = $this->getArg('id'); if (!ctype_digit($id) || !\Sonic\Model\User::_IDexists($id)) { return $this->error('Invalid User'); } if (!\Sonic\Model\User::_delete($id)) { return $this->error('Unable to delete user'); } else { return $this->success(); } }