rydurham / Sentinel

A Sentry bridge package for Laravel
http://www.ryandurham.com/projects/sentinel/
317 stars 68 forks source link

Activation by admin #236

Closed yilmazerhakan closed 6 years ago

yilmazerhakan commented 6 years ago

Hi,

I want to activate users from admin panel only. When a user registered he will wait for admin.

What trick do you advise.

rydurham commented 6 years ago

My advice would be to disable the default routes and provide your own version of those routes. (See the readme for details.) Then you can disable the activation route and remove the activation link from the welcome email.

To allow admins to activate users, you can do something like this:

try
{
    // Find the user using the user id
    $user = Sentry::findUserById(1);
    $code = $user->getActivationCode();

    // Attempt to activate the user
    if ($user->attemptActivation($code))
    {
        // User activation passed
    }
    else
    {
        // User activation failed
    }
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
    echo 'User was not found.';
}
catch (Cartalyst\Sentry\Users\UserAlreadyActivatedException $e)
{
    echo 'User is already activated.';
}

see here: https://cartalyst.com/manual/sentry/2.1#activating-a-user

yilmazerhakan commented 6 years ago

thank you very much.