SeVOo POS

Register

Already have an account? Login

``` ### Update Authentication Class I'll now add the `register()` method to your `Auth` class to handle the logic of creating a new user. ```diff --- a/c:/xampp/htdocs/sha-restaurant/includes/Auth.php +++ b/c:/xampp/htdocs/sha-restaurant/includes/Auth.php @@ -100,6 +100,48 @@ ]; } /** * Register a new user */ public function register($username, $password, $full_name, $email, $phone, $role_id) { // Check if username exists $this->db->query("SELECT id FROM users WHERE username = :username"); $this->db->bind(':username', $username); if ($this->db->single()) { return [ 'success' => false, 'message' => 'Username already exists.' ]; } // Hash password $hashedPassword = password_hash($password, PASSWORD_DEFAULT); // Insert user $this->db->query("INSERT INTO users (username, password, full_name, email, phone, role_id, is_active) VALUES (:username, :password, :full_name, :email, :phone, :role_id, 1)"); $this->db->bind(':username', $username); $this->db->bind(':password', $hashedPassword); $this->db->bind(':full_name', $full_name); $this->db->bind(':email', $email ?? ''); $this->db->bind(':phone', $phone ?? ''); $this->db->bind(':role_id', $role_id); if ($this->db->execute()) { $userId = $this->db->lastInsertId(); $this->logActivity($userId, 'register', 'New user registered'); return [ 'success' => true, 'message' => 'Registration successful.' ]; } return [ 'success' => false, 'message' => 'Registration failed. Please try again.' ]; } /** * Create user session */ ``` These changes introduce a complete registration flow. Users can now navigate to `register.php`, fill out the form, and create a new account. For security, new users cannot register as an 'Admin'. I would also recommend adding a link to `register.php` on your `login.php` page for easy access, similar to the "Already have an account?" link on the new registration page. Let me know if you have any other questions!