Trongate Way Docs

The Pieces You Need

Before we build anything, let us look at the pieces that make up a login system. Think of this page as showing you the ingredients before we start cooking.

There are four database tables involved. Three of them are created automatically when you install Trongate. One is a table that you create yourself (for your members or users).

The Three Framework Tables

These tables are already in your database. You do not need to create them.

trongate_user_levels - The User Types

This table lists the different kinds of users your website has. Each row is one "user level." For example:

  • Level 1: Administrators (people who manage the website)
  • Level 2: Members (people who signed up for your site)

You can have as many levels as you need. A school website might have: 1 = Teachers, 2 = Students, 3 = Parents. Each level has its own settings.

trongate_users - The Master List

Every person who has an account on your website gets one row in this table. It is a simple list that says, "This person exists, and they belong to this user level." The actual details (name, email, password) live in a separate table.

Think of it like a school register. The register (trongate_users) lists each student's name and student ID number. The detailed records (grades, address, phone number) are kept in a different folder.

trongate_tokens - The Hand Stamps

When a user logs in successfully, the login module creates a "token." A token is just a long, random string of letters and numbers. It is stored in this table and also in the user's browser (as a cookie or session).

Every time the user visits a new page, Trongate checks: "Is there a valid, unexpired token for this user?" If yes, they are allowed through. If no, they are sent to the login page.

Your Custom Table

This is the table you create yourself. It stores the actual details of your users. The table name can be anything you like - members, teachers, customers, accounts - whatever fits your project.

A typical members table looks like this:

members
├── id                 (unique number for each member)
├── username           (the member's display name)
├── email_address      (the member's email)
├── password           (a secret, scrambled version of their password)
├── first_name         (optional profile field)
├── last_name          (optional profile field)
├── trongate_user_id   (links this row back to trongate_users)
├── date_created       (when they joined)
├── num_logins         (how many times they have logged in)
└── code               (a random security string)

Here is the SQL to create this table:

SQL
CREATE TABLE members (
    id int(11) NOT NULL AUTO_INCREMENT,
    username varchar(55) DEFAULT NULL UNIQUE,
    email_address varchar(255) DEFAULT NULL,
    password varchar(255) NOT NULL,
    first_name text DEFAULT NULL,
    last_name text DEFAULT NULL,
    date_created int(11) NOT NULL,
    num_logins int(11) NOT NULL DEFAULT 0,
    last_login int(11) NOT NULL DEFAULT 0,
    trongate_user_id int(11) NOT NULL,
    code varchar(16) NOT NULL,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

You can add more columns for your own needs - for example, a profile picture, a bio, or a phone number. The login module only needs the password column and the identifier columns (like username or email_address). Everything else is extra.

The Configuration File

There is one more piece: a configuration file at config/login.php. This file tells the login module which table to use, which columns hold usernames and passwords, and where to send users after they log in.

We will build this configuration file in the next page. It is the most important part of the setup, and it is simpler than it looks.

What's Next

Now you know the pieces. On the next page, we will create the configuration file step by step.

We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.

Share your thoughts in the Documentation Feedback.

Leave Feedback About This Page