CodeIgniter Forums
SHIELD: disable autonomous user registration - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: SHIELD: disable autonomous user registration (/showthread.php?tid=89189)



SHIELD: disable autonomous user registration - Corsari - 01-20-2024

Hello
I'm experimenting with SHIELD because my need is to make a totally private app on a public hosting

Because of that, I'd like to make the registration process fully private too, more precisely I'd like that me as administrator, will be the unique one that is enabled to register users from "the admin side"

Later the whole app (from root to bottom) will be protected by SHIELD authentication while publicly it will be seen only the login page but trimmed to just user name and password fields

They come to my mind few manners for achieving that

though I thank you so much if some SHIELD expert can point out the correct approach and methods to do achieve that , at least the part to correctly disable the users self registration

Thank you





Hello
found one setting in
\app\Config\Auth.php


PHP Code:
    /**
    * --------------------------------------------------------------------
    * Allow Registration
    * --------------------------------------------------------------------
    * Determines whether users can register for the site.
    */
    public bool $allowRegistration false


which is the case

Now it does remain the case of an administrator users registration section:
should be written from scratch? Or it can be done something making use of the SHIELD controllers and views?

Thank you



About an Admin Users creation/registration controller and view

Looks like the it should be used this part of the guide
https://shield.codeigniter.com/user_management/managing_users/#creating-users

(well looks like that writing on the forum, allows me to find the right addresses on the guide)
Blush


RE: SHIELD: disable autonomous user registration - InsiteFX - 01-21-2024

This is what I use to create the SuperAdmin Account, it depends on what the default user group is set to in
app/Config/AuthGroups.php

PHP Code:
/**
 * createUser ()
 * -------------------------------------------------------------------
 *
 * @param string $userName
 * @param string $emailAddress
 * @param string $password
 */
public function createUser(string $userName ''string $emailAddress ''string $password ''): void
{
    // Get the User Provider (UserModel by default)
    $users auth()->getProvider();

    // Users record
    $user = new User([
        'username' => $userName,
        'email'    => $emailAddress,
        'password' => $password,
    ]);

    // Save the new user information
    $users->save($user);

    // To get the complete user object with ID, we need to get from the database
    $user $users->findById($users->getInsertID());

    // Add to default group
    $users->addToDefaultGroup($user);




RE: SHIELD: disable autonomous user registration - Corsari - 01-23-2024

(01-21-2024, 10:35 AM)InsiteFX Wrote: This is what I use to create the SuperAdmin Account, it depends on what the default user group is set to in
app/Config/AuthGroups.php

PHP Code:
/**
 * createUser ()
 * -------------------------------------------------------------------
....
    $users->addToDefaultGroup($user);


thank you