Skip to main content

Overview

Wecode provides a comprehensive user management system with role-based access control, bulk user creation, and trial account management.

User Roles

Wecode supports five distinct user roles with different permission levels:

Admin

Full system access, can manage all users, assignments, and problems

Head Instructor

Can create assignments, manage classes, and create instructor/student accounts

Instructor

Can create assignments and student accounts within their classes

Student

Can submit solutions and view personal submissions

Guest

Limited access, cannot make submissions

User Model

The User model includes the following key fields:
User.php:27-29
protected $fillable = [
    'username', 'email', 'password', 'display_name', 'role_id', 'trial_time'
];

Relationships

User.php:55-74
public function role(){
    return $this->belongsTo('App\Models\Role');
}

function submissions()
{
    return $this->hasMany('App\Models\Submission');
}

function problems(){
    return $this->hasMany(Problem::class);
}

function lops(){
    return $this->belongsToMany('App\Models\Lop');
}

function selected_assignment(){
    return $this->belongsTo('App\Models\Assignment', 'selected_assignment_id');
}

Creating Users

Single User Creation

Admins can create individual users through the web interface. Route: POST /users
UserController.php:178-193
public function store(Request $request)
{
    if(Auth::user()->role->name != 'admin'){
        abort(403);
    }
    $user=new User;
    $user->username=$request->username;
    $user->password=Hash::make($request->password);
    $user->display_name=$request->username;
    $user->email=$request->email;
    if ($request->role_id!="")
        $user->role_id=$request->role_id;
    else $user->role_id=4;
    $user->save();
    return redirect('users');
}

Bulk User Creation

Create multiple users at once using CSV format. Route: GET /users/add_multiple
username, email, password, role, display_name
student1, [email protected], random[8], student, John Doe
student2, [email protected], mypassword, student, Jane Smith
instructor1, [email protected], random[12], instructor, Prof. Anderson
Use random[N] in the password field to generate a random password of N characters.

User Permissions

Permission Hierarchy

UserController.php:383-406
// Check permissions
// admin can create any user
// head_instructor can create instructor and student
// instructor can create student
if (Auth::user()->role->name == 'admin'){
    //nothing to be done, admin do whatever he wants
} 
elseif (Auth::user()->role->name == 'head_instructor'){
    if (!in_array($role_name, ['instructor', 'student']))
    {
        array_push($json, 'you can add user with role "instructor" or "student" only');
    }
}
elseif (Auth::user()->role->name == 'instructor'){
    if (!in_array($role_name, [ 'student']))
    {
        array_push($json, 'you can add user with role "student" only');
    }
}
else {
    array_push($json, 'you do not have permission to add user');
}

Trial Accounts

Manage temporary student access with automatic expiration.

Setting Trial Time

Route: POST /users/set_trial
UserController.php:495-497
if ($request->get('set_choice') == 'new_time'){
    $count = $where_clause->update(['trial_time' => $request->get('new_trial_time') , 'role_id' => 4]);
}
Set trial duration in hours from account creation.

Automatic Expiration

Trial accounts automatically convert to guest accounts when expired:
Assignment.php:106-113
if (
    $user->trial_time &&
    in_array($user->role->name, ["student"]) &&
    $user->created_at->addHours($user->trial_time) <= Carbon::now()
) {
    $user->role_id = 5; //5 means guest
    $user->save();
}

User Management Routes

MethodRouteActionPermission
GET/usersList all usersadmin, head_instructor
GET/users/createShow create formadmin
POST/usersCreate useradmin
GET/users/{id}Show user profileadmin, head_instructor, instructor, self
GET/users/{id}/editShow edit formadmin, self
PUT/users/{id}Update useradmin, self
DELETE/users/{id}Delete useradmin
GET/users/add_multipleBulk add formadmin, head_instructor, instructor
POST/users/addsProcess bulk addadmin, head_instructor, instructor
POST/users/set_trialSet trial timeadmin, head_instructor, instructor
GET/users/rankingUser rankingsauthenticated
POST/users/delete_submissions/{user}Delete user submissionsadmin

User Statistics

View detailed user statistics and submission history:
UserController.php:55-121
public function show($id)
{
    if ( ! in_array( Auth::user()->role->name, ['admin', 'head_instructor', 'instructor']))
        if (Auth::user()->id != $id)
            abort(403);
    $user = User::with('lops')->findOrFail($id);
    $subs = $user->submissions()->with('assignment', 'assignment.lops', 'assignment.problems')->get();

    $total = $subs->count();
    $problem_wise_stat = array();
    $total_accept = 0;
    $solved_problems = array();
    $ass = array();
    
    // Calculate statistics per assignment
    foreach ($subs as $sub){
        $t = $ass[$sub->assignment->id] ??= (object)null;
        $t->ass ??= $sub->assignment;
        $t->total ??= 0;
        $t->accept ??= 0;
        $t->score ??= 0;
        $t->ac_score ??= 0;
        $t->solved ??= 0;
        
        // ... statistics calculation
    }
    
    return view('users.show', ['user' => $user, 'ass' => $ass, 'stat' => $statistics]);
}

Best Practices

Security

  • Always hash passwords with Hash::make()
  • Validate email uniqueness
  • Enforce minimum password length (8 characters)
  • Use role-based access control

Trial Accounts

  • Set appropriate trial duration
  • Monitor trial expiration
  • Communicate expiration to users
  • Have upgrade process ready

Bulk Creation

  • Use CSV format for consistency
  • Generate random passwords for security
  • Validate all user data before creation
  • Review error reports after bulk import

User Management

  • Regular cleanup of guest accounts
  • Monitor user submission activity
  • Maintain class enrollment
  • Backup user data regularly

Build docs developers (and LLMs) love