User And Access

Users

Purpose

A system for authenticating users and storing users information is called as user management. Using this method you will be able to create a user and can manage every aspect of your user accounts in VaahCMS, including altering user properties, resetting passwords, enabling or disabling users, and more.

Features & Demos

Create a User

In VaahCMS there are two methods of creating a user

  1. From Registrations
  2. From Users

Follow below image for reference: You will get to know about both these methods one by one.

Method 1 : From Registrations

The purpose of this method is to identify the actual user before saving their details into users table. Once the user is verified then their details will be saved in the users table in the database.
To know more about this method, click here.

Method 2 : From Users

To create a user from this method you just need to click on Create button present in the top right corner of the Users section.

Follow below image for reference:

When you click on Create button, you will be able to see a form where you need to fill the required fields and click on Create & New button.That user will be added in the Users list.
Follow below image for reference:


User Listing

To get the Users list you just need to visit the Users and Access menu and click on the Users icon in the sidebar. You will get the Users list and you will have the ability to add, edit, and remove users. Additionally, you may alter user details and roles at the same location where you can search, sort, and filters the users' data.
Follow below image for reference:

When you click on the Users icon in the sidebar you will be able to see the list of users.
Follow below image for reference:

Manage User Roles

You can assign roles to a user in Users section. You will see Roles column in the Users section.
Follow below images for reference: By clicking on Roles column for a particular user, a page will open that contain list of Roles along with Yes/No Button.
Follow below image for reference:

Watch the following video to have a better understanding of the Users section.

Impersonate user

Impersonating a user refers to the ability for an administrator or privileged user to temporarily assume the identity and privileges of another user in a system or application.

During the impersonation process, the administrator's privileges are temporarily replaced with the privileges of the user being impersonated. This means that the administrator can perform actions and access resources as if they were the user, without needing to know or change the user's password.

Click on the user icon button for the user you want to impersonate.

After completing this step, you will be able to access the impersonated user's account and perform actions on their behalf. To exit the impersonation mode, simply click on the Leave button, as shown in the image below.

Required User Permissions To Access This Section

PermissionsDescription
Has Access Of Users SectionThis will allow user to see the link of user section.
Can Create UsersThis will allow user to add anything in the user section.
Can Read UsersThis will allow user to view anything in the user section.
Can Update UsersThis will allow user to edit anything in the user section.
Can Delete UsersThis will allow user to delete anything in the user section.
Can Manage UsersThis will allow user to manage anything in the user section.
Can See Users Contact DetailsThis will allow user to view contact (email, mobile) detail in the user section.
Can Impersonate UsersThis will allow user to impersonate users.

Files

  • Laravel Route: vaahcms/Routes/backend/route-users.php
  • Laravel Controller: vaahcms/Http/Controllers/Backend/UsersController.php
  • Laravel Model: vaahcms/Models/User.php
  • Vue Route: vaahcms/Vue/routes/vue-routes-users.js
  • Vue Store: vaahcms/Vue/stores/store-users.js
  • Vue Page Directory: vaahcms/Vue/pages/users

Methods

Accessors

To know about Accessors, see Laravel Documentation

Method NameDescription
getAvatarAttributeGet value of avatar_url column from database or Gravatar url. To know about Gravatar, click here
getMetaAttributeGet value of meta column in JSON
getNameAttributeGet value of display_name column or joined string of first_name, middle_name and last_name column from database.

Mutators

To know about Mutators, see Laravel Documentation

Method NameParameterDescription
setMetaAttribute$valueSet json encoded value in meta column
setFirstNameAttribute$valueSet first character of First Name capitalized
setMiddleNameAttribute$valueSet first character of Middle Name capitalized
setLastNameAttribute$valueSet first character of Last Name capitalized
setPasswordAttribute$valueHashing of Password. prevent_password_attr_set This variable is defined to ignore this mutator.
setLoginOtpAttribute$valueHashing of Login OTP code

Scopes

To know about Scopes, see Laravel Documentation

Method NameParameterDescription
scopeIsActive$queryReturn Active User (is-active == 1)
scopeBetweenDates$query $from $toReturn User which is created between $from date & $to date
scopeExclude$query $columnsThe array in $columns parameter is exclude from select query.

Relationships

To know about Relationships, see Laravel Documentation

Method NameDescription
createdByUserReturn data of User model that has an id which matches the created_by column of User.
updatedByUserReturn data of User model that has an id which matches the updated_by column of User.
deletedByUserReturn data of User model that has an id which matches the deleted_by column of User.
rolesReturn data of Role model with Pivot that is assigned to Users.

Non Static
Method NameParameterDescription
getTableColumnsGet array of all columns name in User table.
getFormFillableColumnsGet array of some column name in User table.
activeRolesReturn active Roles of User.
hasRole$role_slugReturn true if role in $role_slug is active.
isAdminReturn true if Administrator role is active.
hasPermission$permission_slug $detailsReturn true if permission in $permission_slug is active and their associated role is active.

Static
Method NameParameterDescription
User::findByUsername$username $columns = array('*')The findByUsername method find users only by the username and return given columns.
User::findByEmail$email $columns = array('*')The findByEmail method find users only by the email and return given columns.
User::countAdministratorsThe countAdministrators method return number of users which has Administrator role.
User::getByRoles$array_role_slugsThe getByRoles method return a list of the users which has a role exists in $array_role_slugs.
User::getByRolesOnlyIds$array_role_slugsThe getByRolesOnlyIds method return only id of the users which has a role exists in $array_role_slugs.
User::getByRolesOnlyEmails$array_role_slugsThe getByRolesOnlyEmails method return only email of the users which has a role exists in $array_role_slugs.
User::rulesAdminCreateThe rulesAdminCreate method return the array of validation rules for User.
User::isLastAdminThe isLastAdmin method return true if Application has only one User of Administrator role.
User::getAvatarById$idThe getAvatarById method find users only by the id and return avatar url.
User::getUsersForAssetsThe getUsersForAssets method return list of active users with following columns: id, first_name, middle_name, last_name

Generate new API Token

To use api of VaahCMS you need to pass the Token in Authorization. To generate this toke you need to click Genenrate new API Token option which is presents in the Detail view of the item.

Just like below image:

API

VaahCMS has APIs for every method, allowing you to interact with NuxJS or other frameworks.

You can access APIs method from vaachms/Http/Controllers/Api/UsersController.php and routes from vaahcms/Routes/api/api-routes-users.php

We mention some methods bellow which help you to understand the structure.

create
Method: POST
URL: <public-url>/api/users/users/
Sample Request

Parameters: $request

$request =  new Request([
    'new_item' => [
        'alternate_email'       => null,
        'avatar_url'            => null,
        'bio'                   => null,
        'birth'                 => null,
        'country'               => null,
        'country_calling_code'  => null,
        'country_code'          => null,
        'designation'           => null,
        'display_name'          => null,
        'email'                 => null,    // required
        'first_name'            => null,    // required
        'gender'                => null,
        'is_active'             => null,    // required       //true:false:0:1
        'last_name'             => null,
        'middle_name'           => null,
        'password'              => null,
        'phone'                 => null,
        'status'                => null,    // required       //active:inactive
        'timezone'              => null,
        'title'                 => null,
        'username'              => null,
        'website'               => null
    ]
]);

Creates a new user for the database on which the method is run. \WebReinvent\VaahCms\Models\User::create($request); returns a duplicate user error if the email already exists in the User table.

Sample Response
{
  "data":  {
    "item": {
      ...
    }
  },
  "messages": "Saved successfully.",
  "success": true
}

Get List
Method: GET
URL: <public-url>/api/users/users/
Sample Request
parameter = [
    'filter' => [
        'q'            // for search queary (optionl)
        'trashed'      // for include or exclude trashed data (optionl)
        'is_active'    // for fetching only active or inactive data (optionl)
        'sort'         // for sorting the data (optionl)
    ];  
];
Sample Response
{
  "data": {
      ...
  },
  "success": true
}

validation

Parameters: $inputs

$inputs = [
    'first_name' => null,    // required
    'email'      => null,    // required
    'is_active'  => null,    // required       //true:false:0:1
    'status'     => null,    // required       //active:inactive
];

This function uses the Laravel Validator to validate the user's following columns: first_name, email, is_active, and status.


Copyright © 2024