Wednesday, January 8, 2025

Codeigniter Shield Authorization

Codeigniter Shield Authorization

CodeIgniter Shield is the official authentication and authorization framework for CodeIgniter 4. It provides a flexible role-based access control (RBAC) system, allowing you to manage user permissions effectively.

Key Concepts:

Groups: Users can belong to multiple groups, which can represent traditional roles (e.g., admin, moderator) or be used to group users based on features or other criteria.

Permissions: Permissions define what actions a user is allowed to perform within your application. Permissions are typically associated with groups.

Users: Each user has a set of permissions based on the groups they belong to, and can also have permissions directly assigned to them.

Defining Groups:

Groups are defined in the Shield\Config\AuthGroups configuration file. Each group has a key, a title, and an optional description.

php
public array $groups = [
'superadmin' => [
'title' => 'Super Admin',
'description' => 'Optional description of the group.',
],
'editor' => [
'title' => 'Editor',
'description' => 'Can edit content.'
],
'user' => [
'title' => 'User',
'description' => 'Basic user access.'
]
];

Defining Permissions:

php
public array $permissions = [ 'superadmin.access' => 'Can access the sites admin area', 'superadmin.settings' => 'Can access the main site settings', 'editor.create' => 'Can view/edit site content', 'users.create' => 'Can create new non-admin users', 'users.edit' => 'Can edit existing non-admin users', 'users.delete' => 'Can delete existing non-admin users', ];

Checking Permissions:

You can check if a user has a specific permission using the can() method on the User entity. This method checks permissions within the groups the user belongs to, as well as any permissions directly assigned to the user.

php
if (! auth()->user()->can('users.create')) {
return redirect()->back()->with('error', 'You do not have permissions to access that page.');
}

Example:

Let's say you have a 'superadmin' group with the permission users.create. You can check if the current user has this permission like this:

php
if (auth()->user()->can('users.create')) {
// Allow user to create a new user
} else {
// Redirect or show an error message
}

Getting the Current User:

You can get the current user using the auth() helper function:

php
$user = auth()->user();

Adding Group To a User:

php
$user = auth()->user();
$user->addGroup('superadmin', 'editor');

Removing Group From a User:

php
$user = auth()->user(); $user->removeGroup('superadmin', 'editor');

Check if User Belongs to a Group:

php
$user = auth()->user(); if ($user->inGroup('superadmin')) { // do something }

In summary, CodeIgniter Shield's authorization system allows you to:

Define user groups with specific roles and permissions.

Assign users to one or more groups.

Check if a user has the necessary permissions to perform an action.

This provides a flexible and robust way to manage access control in your CodeIgniter application.

Thursday, March 21, 2024

Electron app with React and Electron Forge

Build Desktop applications with React and Electron Forge

Create cross-platform desktop applications using modern web development tools and integration of third-party libraries and frameworks with Electron. Build your electron apps with the commonly used web technologies like HTML, JavaScript, CSS. Supports native interface for all platforms like windows, macOS, Linux. Integrate JavaScript frameworks such as React, Vue for front-end tooling. Publish electron apps with built-in templates. Currently Electron apps have support for these templates for publishing,

  1. Vite
  2. Webpack

Monday, March 11, 2024

Codeigniter Shield - Install and Configure

Install Codeigniter Shield

Codeigniter Shield is the official authentication and authorization framework for codeigniter 4. It provides session authentication, in which the user ID and password is stored in the session for the subsequent requests to authenticate against. Basically, it has all the features that the modern website offers.

Tuesday, March 5, 2024

Codeigniter in Visual Studio Code - Getting started

Getting started with Codeigniter in VSCode

Codeigniter is a PHP Framework for building robust and flexible websites. Basically, codigniter can be downloaded from official sources as a zip package and install in your system to start development. But, there are other ways to download and install codeigniter to build web applications. Here, we will demonstrate two ways to get started with codeigniter app development in visual studio code. The two approaches used here are,

  1. Clone Git repository
  2. Composer (tool to install packages and dependencies)

Monday, March 4, 2024

Setup Laravel in Visual Studio Code - Getting started

Setup Laravel in Visual Studio Code

Laravel is a very popular PHP Framework for developing web applications. There are many ways to get started with Laravel development in different platforms. But, the most commonly used IDE by developers is visual studio code because it is open source and has support for multiple languages. It even has extensions enabling to integrate third-party tools and services, thus allows for faster development. Here, two approaches are used to download and install Laravel in vscode.

  1. Clone Git repository
  2. Composer (tool to get packages and dependencies)


After you download Laravel, first thing that you have to is create a .env file and copy the configurations from the .env.example to .env file. Then, Generate app key and assign to the setting variable.

Thursday, February 29, 2024

Install WordPress on IIS (Internet Information Services)

Install WordPress on IIS

WordPress is an open-source Content Management System (CMS) built using core PHP. It is a production ready web application package which can be setup in minutes to publish content for the end users. Administrators have complete control over the information being displayed on the site. Managing all aspects of the site is made possible through admin panel.


Deploying WordPress on IIS requires you to configure IIS Manager to handle PHP requests. In order to handle PHP requests enable CGI module from windows features. Install PHP package and register in IIS Manager using PHP Manager for IIS, which is a tool to manage different versions of PHP.

Codeigniter Shield Authorization

Codeigniter Shield Authorization CodeIgniter Shield is the official authentication and authorization framework for CodeIgniter 4. It provide...