Basic

Users

Introduction

User Management is a system for authenticating users and storing user data. As of now, VaahCms has two Login option: Login via Password and Login via OTP. In VaahCms, you can manage all aspects of your user accounts such as changing user properties, reset passwords, enable or disable users, and more.

Visit following url you will see the Users section:

<project-url>/backend#/vaah/users/
user1
User Listing

Get a list of all your users, and their data in one place. The Users table contains all of your user data and the VaahCms puts all user management functions right at your fingertips. You have the ability to add, edit, and delete users. You can also search, sort, and filter your user data and modify user information and roles, all in the same place.

user2
Create New Users

You can create new user accounts within your app in Users section. VaahCms give you total control over how users get created. You decide the level of access they receive within your app.

user3
Password Reset

Your users need the ability to change their password without contacting you, the Administrator. Don’t waste time manually assisting users that lose or forget their password. If you need to handle a password change yourself, you can do it from Backend.

user4
Manage Roles

You can assign roles to a user in Users section. By clicking on Role column, a page will open that contain list of Roles along with Yes/No Button.

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

create

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\Entities\User::create($request); returns a duplicate user error if the email already exists in the User table.


postStore

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,
                    'id'                    => null,    // required
                    '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
                ]
            ]
        );

Update an existing user in the database. \WebReinvent\VaahCms\Entities\User::postStore($request); returns a duplicate user error if the updated email id already exists in the User table.


validation

Parameters: $inputs

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

This is a method for validate user's following columns: email, first_name, is_active, status which use Laravel Validator.


getList

Parameters: $request

$request =  new Request(
            [
                'new_item' => [
                    'page'          => null,        // 1,2,3,4.....
                    'q'             => null,        // search_input
                    'trashed'       => null,        // true,false
                    'status'        => null,        // 01,10
                    'from'          => null,        // date
                    'to'            => null,        // date
                    'roles'         => [
                        "administrator"
                    ]
                ]
            ]
        );

This getList method that returns a list of Users, total number of roles in vh_roles table and status of method. The list of User are Paginated. There is one parameter $request which has following values:

  • page: This contain numbers which is used to get data of that page number in pagination.
  • q: This contain string which is used to search in vh_users table by id, email, first_name, middle_name, last_name
  • trashed: This contain boolean values. If trashed value is true, it will return list of all Users including trashed User.
  • status: This contain string. If status value is 01, it will return list of all Active Users.
  • from,to: Both contain date. If there value is set, it will return list of Users who is created in between these dates.
  • roles: This contain array of role slug. If there is some role in this array, it will return list of Users who has that role.

getItem

Parameters: $id

This getItem method find user only by the id and relation with createdByUser. updatedByUser. deletedByUser method. If someone is logged in and that user has can-see-users-contact-details permission then you will get some extra columns: email, alternate_email, phone


getItemRoles

Parameters: $request, $id

$request =  new Request(
            [
                'page'          => null,        // 1,2,3,4.....
                'q'             => null,        // search_input
            ]
        );

This getItemRoles method find user by the id and get the list of their associated roles. There is a parameter $request which has following values:

  • page: This contain numbers which is used to get data of that page number in pagination.
  • q: This contain string which is used to search in vh_roles table by name, slug.

bulkStatusChange

Parameters: $request

 $request =  new Request(
            [
                "inputs" =>  [
                    0 => 1
                ],
                "data" =>  [
                    "status" => "1"
                ],
                "action" => "bulk-change-status"
            ]
        );

This method is used to change the status of Users. There is one parameter $request which has following values:

  • inputs: This contain array of User's id which is used to find user by the id and update status.
  • data: This is also a array which has one value status. It has new updated status of User
  • action: This is a action name which is used to check restricted action.

bulkTrash

Parameters: $request

 $request =  new Request(
            [
                "inputs" =>  [
                    0 => 1
                ],
                "data" =>  [
                    
                ],
                "action" => "bulk-trash"
            ]
        );

This method is used to soft delete the Users. There is one parameter $request which has following values:

  • inputs: This contain array of User's id which is used to find user by the id and update status.
  • data: This is also a array which has one value status. It has new updated status of User
  • action: This is a action name which is used to check restricted action.

bulkRestore

Parameters: $request

 $request =  new Request(
            [
                "inputs" =>  [
                    0 => 1
                ],
                "data" =>  [
                    
                ],
                "action" => "bulk-trash"
            ]
        );

This method is used to restore the Users. There is one parameter $request which has following values:

  • inputs: This contain array of User's id which is used to find user by the id and update status.
  • data: This is also a array which has one value status. It has new updated status of User
  • action: This is a action name which is used to check restricted action.

bulkDelete

Parameters: $request

 $request =  new Request(
            [
                "inputs" =>  [
                    0 => 1
                ],
                "data" =>  [
                    
                ],
                "action" => "bulk-trash"
            ]
        );

This method is used to permanently delete the Users. There is one parameter $request which has following values:

  • inputs: This contain array of User's id which is used to find user by the id and update status.
  • data: This is also a array which has one value status. It has new updated status of User
  • action: This is a action name which is used to check restricted action.



Copyright © 2024