PHP code example of winter / wn-user-plugin

1. Go to this page and download the library: Download winter/wn-user-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

winter / wn-user-plugin example snippets


Route::group(['middleware' => ['web', 'Winter\User\Classes\AuthMiddleware']], function () {
    // All routes here will 

public function onCheckEmail()
{
    return ['isTaken' => Auth::findUserByLogin(post('email')) ? 1 : 0];
}

function onSignin()
{
    try {
        return $this->account->onSignin();
    }
    catch (Exception $ex) {
        Log::error($ex);
    }
}

$user = Auth::register([
    'name' => 'Some User',
    'email' => '[email protected]',
    'password' => 'changeme',
    'password_confirmation' => 'changeme',
]);

// Auto activate this user
$user = Auth::register([...], true);

// Returns true if signed in.
$loggedIn = Auth::check();

// Returns the signed in user
$user = Auth::getUser();

// Authenticate user by credentials
$user = Auth::authenticate([
    'login' => post('login'),
    'password' => post('password')
]);

$user = Auth::authenticate([...], true);

// Sign in as a specific user
Auth::login($user);

// Sign in and remember the user
Auth::login($user, true);

$user = Auth::findUserByLogin('[email protected]');

$user = Auth::registerGuest(['email' => '[email protected]']);

// This will not throw an "Email already taken" error
$user = Auth::register([
    'email' => '[email protected]',
    'password' => 'changeme',
    'password_confirmation' => 'changeme',
]);

$user->convertToRegistered();

$user->convertToRegistered(false);

Event::listen('winter.user.deactivate', function($user) {
    // Hide all posts by the user
});

Event::listen('winter.user.beforeAuthenticate', function($component, $credentials) {
    $login = array_get($credentials, 'login');
    $password = array_get($credentials, 'password');

    /*
     * No such user exists
     */
    if (!$user = Auth::findUserByLogin($login)) {
        return;
    }

    /*
     * The user is logging in with their old WordPress account
     * for the first time. Rehash their password using the new
     * Winter CMS system.
     */
    if (WordPressLogin::check($user->password, $password)) {
        $user->password = $user->password_confirmation = $password;
        $user->forceSave();
    }
});
bash
php artisan migrate
ini
title = "Restricted page"
url = "/users-only"

[session]
security = "user"
redirect = "home"
ini
title = "Account"
url = "/account/:code?"

[account]
redirect = "home"
paramCode = "code"
==
{% component 'account' %}
ini
title = "Forgotten your password?"
url = "/forgot-password/:code?"

[resetPassword]
paramCode = "code"
==
{% component 'resetPassword' %}