Overview
The User model extends Laravel’sAuthenticatable class and manages user authentication, authorization, and relationships with assignments, submissions, and classes.
Traits
- Notifiable: Enables email and notification features
Fillable Fields
Unique username for loginUsed throughout the system for identification and file paths
User’s email address
Hashed password for authenticationHidden: Not included in JSON serialization
User’s full name for display purposes
Foreign key to the roles tableDetermines user permissions and access levels
Trial period duration in hours for new student accountsAfter trial expires, students are automatically downgraded to guest role
Hidden Fields
Casts
Additional Columns
While not in$fillable, these columns exist in the users table:
email_verified_at(datetime) - When email was verifiedfirst_login_time(datetime) - First time user logged inlast_login_time(datetime) - Most recent login timeremember_token(string) - For “remember me” functionalityselected_assignment_id(integer) - Currently selected assignment in UIcreated_at(timestamp) - Account creation timeupdated_at(timestamp) - Last update time
Relationships
role()
The user’s role determining permissionsCommon roles:
admin- Full system accesshead_instructor- Can manage assignments and classesinstructor- Can create problems and view student workstudent- Can submit to assigned problemsguest- Read-only access, cannot submit
submissions()
All submissions made by this user
problems()
Problems created/owned by this userOnly applicable for instructors and admins
lops()
Classes (“lops”) this user belongs to
- Students: Classes they’re enrolled in
- Instructors: Classes they teach
selected_assignment()
The assignment currently selected in the user’s UIUsed to persist user’s current context across page loads
Role Hierarchy
Roles are hierarchical with different permission levels:Admin (role_id: 1)
- Full access to all features
- Can edit any assignment, problem, or user
- Can submit to any problem (including practice)
- Bypasses all permission checks
Head Instructor (role_id: 2)
- Can create and manage assignments
- Can manage their own classes (lops)
- Can edit assignments they created or that belong to their classes
- Can view all student submissions in their classes
- Can use sharable problems from other instructors
Instructor (role_id: 3)
- Can create problems
- Can view student work
- Can use sharable problems
- Limited assignment management
Student (role_id: 4)
- Can submit to assigned problems
- Can practice on problems with
allow_practice = true - Can view their own submissions
- Subject to assignment time limits and permissions
Guest (role_id: 5)
- Read-only access
- Cannot make submissions
- Students are auto-downgraded to guest after trial period expires
Trial Account System
From Assignment.php:712, the trial system works as follows:- When creating a student account, set
trial_time(in hours) - On submission attempt, system checks if trial expired
- If
created_at + trial_time <= now, auto-downgrade to guest - Guest users cannot submit
Permission Helpers
While not defined in the model, these permission patterns are used throughout the codebase:Check if user can edit assignment
Check if user can submit
Check if user can practice problem
Check if user can edit problem
Example Usage
Authentication
The User model extendsAuthenticatable and works with Laravel’s authentication system:
Security Notes
- Password Hashing: Always use
Hash::make()when setting passwords - Hidden Fields:
passwordandremember_tokenare automatically hidden from JSON - Role Validation: Always check
$user->role->namebefore allowing privileged actions - Trial Expiration: System auto-enforces trial expiration on submission attempts

