Sindbad~EG File Manager
# Member Account System Documentation
## Overview
The Member Account System provides a comprehensive solution for member portal access, allowing church members to login, view their profiles, and manage their account details separately from the admin system.
## Features Implemented
### 1. Database Structure
- **`member_accounts` table**: Stores member login credentials and account information
- **Foreign key relationships**: Links to members, areas, districts, and assemblies
- **Security features**: Password hashing, account status management
### 2. Member Portal (`/members/index.php`)
- **Profile Management**: View and edit member details
- **Profile Photo Upload**: Members can update their profile pictures
- **Account Settings**: Change email and password
- **Tabbed Interface**: Separate tabs for profile and account management
- **Responsive Design**: Mobile-friendly interface
### 3. Admin Member Accounts Management (`/modules/member-accounts/index.php`)
- **Create Accounts**: Generate accounts for members without login access
- **Manage Existing Accounts**: Update member account details
- **Account Status Control**: Enable/disable member accounts
- **Statistics Dashboard**: Overview of account metrics
- **Search and Filter**: Find members easily
### 4. Dual Login System (`/login.php`)
- **Admin Tab**: Traditional admin login (existing functionality)
- **Member Tab**: Member login using username/email and password
- **Automatic Redirection**: Admins to dashboard, members to portal
- **Session Management**: Separate session handling for each user type
### 5. Automatic Account Creation
- **During Member Registration**: Accounts created automatically when email provided
- **Username Generation**: First initial + last name (e.g., "jsmith")
- **Random Password**: Secure password generation
- **Credential Display**: Shows generated username/password to admin
## File Structure
```
/members/
├── index.php # Member portal (profile & account management)
/modules/member-accounts/
├── index.php # Admin interface for managing member accounts
/classes/
├── MemberAuth.php # Member authentication and account management
/sql/
├── member_accounts.sql # Database schema
└── add_member_accounts_module.sql # Module registration
```
## Database Schema
### member_accounts Table
```sql
CREATE TABLE member_accounts (
id INT AUTO_INCREMENT PRIMARY KEY,
member_id INT NOT NULL, -- Links to members table
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
full_name VARCHAR(255) NOT NULL,
phone VARCHAR(20) DEFAULT NULL,
profile_photo VARCHAR(255) DEFAULT NULL,
is_superuser TINYINT(1) DEFAULT 0, -- Reserved for future use
access_level ENUM('member') DEFAULT 'member',
area_id INT DEFAULT NULL,
district_id INT DEFAULT NULL,
assembly_id INT DEFAULT NULL,
is_active TINYINT(1) DEFAULT 1,
last_login TIMESTAMP NULL DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
```
## Setup Instructions
### 1. Database Setup
```sql
-- Create member accounts table
SOURCE sql/member_accounts.sql;
-- Add member accounts module to navigation
SOURCE sql/add_member_accounts_module.sql;
```
### 2. File Permissions
Ensure the uploads directory has proper permissions:
```bash
chmod 755 uploads/member_photos/
```
### 3. Configuration
No additional configuration required - the system uses existing database connections and settings.
## Usage Guide
### For Administrators
#### Creating Member Accounts
1. Navigate to **Member Accounts** in admin panel
2. Go to **Create Account** tab
3. Select a member from the dropdown (only members with email addresses)
4. Click **Create Account**
5. Note the generated username and password
6. Share credentials with the member
#### Managing Existing Accounts
1. Go to **Manage Accounts** tab
2. View all member accounts with status and last login
3. Click edit icon to update account details
4. Use status toggle to enable/disable accounts
### For Members
#### Logging In
1. Visit the login page
2. Click **Member** tab
3. Enter username/email and password
4. Access the member portal
#### Managing Profile
1. **Profile Details** tab:
- Update contact information
- Upload profile photo
- View read-only member information
2. **Account Settings** tab:
- Change email address
- Update password
- Manage login credentials
## Security Features
### Authentication
- **Password Hashing**: Uses PHP's `password_hash()` with default algorithm
- **Session Management**: Separate sessions for admin and member users
- **Account Status**: Ability to disable accounts without deletion
- **Login Tracking**: Records last login timestamp
### Access Control
- **Member Portal**: Only accessible to logged-in members
- **Admin Interface**: Restricted to area-level users and superusers
- **Profile Updates**: Members can only update their own profiles
- **Data Validation**: Input sanitization and validation
### File Upload Security
- **Allowed Extensions**: jpg, jpeg, png, gif only
- **File Size Limits**: Configurable upload limits
- **Secure Storage**: Files stored outside web root when possible
- **Filename Sanitization**: Prevents directory traversal attacks
## API Reference
### MemberAuth Class Methods
#### `createMemberAccount($memberData)`
Creates a new member account with auto-generated credentials.
#### `authenticateMember($identifier, $password)`
Authenticates member login using username or email.
#### `updateMemberAccount($accountId, $data)`
Updates member account information.
#### `getMemberAccountByMemberId($memberId)`
Retrieves account information by member ID.
#### `getMembersWithoutAccounts()`
Returns list of members who don't have login accounts.
#### Static Methods
- `isMemberLoggedIn()`: Check if member is logged in
- `getCurrentMember()`: Get current member data
- `memberLogout()`: Log out member
## Integration Points
### Email System Integration
- Welcome emails sent to new member accounts
- Account creation notifications
- Password reset functionality (future enhancement)
### Existing Member System
- Seamless integration with existing member records
- Preserves all existing member data
- Links to area/district/assembly structure
### Admin System
- Separate from admin authentication
- Admin can manage member accounts
- Audit logging for account changes
## Future Enhancements
### Planned Features
1. **Password Reset**: Self-service password reset via email
2. **Two-Factor Authentication**: Enhanced security options
3. **Member Directory**: Browse other members (with privacy controls)
4. **Event Registration**: Integration with church events
5. **Donation Portal**: Online giving integration
6. **Mobile App**: Native mobile application
7. **Advanced Permissions**: Role-based access within member system
### Technical Improvements
1. **API Endpoints**: RESTful API for mobile integration
2. **Single Sign-On**: Integration with external authentication
3. **Advanced Analytics**: Member engagement tracking
4. **Bulk Operations**: Mass account creation and management
5. **Data Export**: Member data export capabilities
## Troubleshooting
### Common Issues
#### Members Can't Login
1. Check account is active in admin panel
2. Verify username/email is correct
3. Ensure password hasn't been changed
4. Check member_accounts table exists
#### Profile Photos Not Uploading
1. Check file permissions on uploads directory
2. Verify file size and type restrictions
3. Ensure PHP upload limits are adequate
4. Check disk space availability
#### Account Creation Fails
1. Verify member has email address
2. Check for duplicate usernames/emails
3. Ensure database foreign key constraints are met
4. Review error logs for specific issues
### Error Logging
All errors are logged to PHP error log. Check:
- Account creation errors
- Authentication failures
- File upload issues
- Database connection problems
## Support and Maintenance
### Regular Tasks
1. **Monitor Account Activity**: Review login patterns
2. **Clean Up Inactive Accounts**: Disable unused accounts
3. **Update Profile Photos**: Remove old/unused images
4. **Database Maintenance**: Regular backups and optimization
### Security Audits
1. **Password Policy**: Encourage strong passwords
2. **Session Security**: Monitor for suspicious activity
3. **File Upload Monitoring**: Check for malicious uploads
4. **Access Log Review**: Regular security assessments
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists