2.7 KiB
2.7 KiB
Auto-Create User Account Feature Plan
Context
The user requested a feature to automatically create portal login accounts when creating a Customer or Vendor, avoiding a manual two-step process. Following clarification:
- No welcome emails will be sent immediately.
- The initial password will be
123456, but the system will force the user to change their password upon their very first login.
Proposed Changes
Phase 1: Database & Middleware (Force Password Change)
- Migration: Create a migration to add a boolean column
requires_password_changeto theuserstable, defaulting tofalse. - Middleware: Create
ForcePasswordChangeMiddleware.php.- If
Auth::check()and$request->user()->requires_password_change == true, intercept the request. - Redirect to a dedicated "Change Password" screen (unless they are already on the change password or logout routes).
- If
- Routing & UI:
- Register the middleware in
bootstrap/app.phporKernel.phpto run globally for web routes. - Create a React page
Auth/ForcePasswordChange.tsxwith a form asking for "New Password" and "Confirm New Password". - Create a controller route to handle the password update and set
requires_password_changetofalse.
- Register the middleware in
Phase 2: Form Requests Validation
StoreCustomerRequest.php&StoreVendorRequest.php:- Add
create_user_account(boolean) to the validation rules. - Validate that
contact_person_emailis required and unique in theuserstable ifcreate_user_accountis true.
- Add
Phase 3: Controller Logic Updates
CustomerController@store&VendorController@store:- If
$request->create_user_accountis true: - Create a new
Userrecord using the provided email and name. - Set the password to
Hash::make('123456'). - Set
requires_password_change = true. - Assign the appropriate role (
clientorvendor). - Assign the new
user_idto the Customer/Vendor record before saving.
- If
Phase 4: Frontend UI Updates
Account/Customers/Create.tsx&Account/Vendors/Create.tsx:- Add a "Create Portal Account Automatically" Checkbox below the "User" dropdown.
- When checked, disable the "User" dropdown since the system handles it.
Verification Checklist
- Migration applied and
userstable has new column. - Middleware correctly intercepts users with
requires_password_change. - "Force Password Change" UI successfully updates the password and removes the flag.
- Creating a customer with the checkbox successfully spawns a
clientuser. - Creating a vendor with the checkbox successfully spawns a
vendoruser. - Form validation prevents creating duplicate accounts with the same email.