Skip to content

Commit

Permalink
Rebrand User plugin for Winter CMS (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Jauvin <[email protected]>
  • Loading branch information
bennothommo and mjauvin authored Mar 16, 2021
1 parent c9447a9 commit 5b06e30
Show file tree
Hide file tree
Showing 69 changed files with 623 additions and 547 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
strategy:
max-parallel: 6
matrix:
phpVersions: ['7.2', '7.3', '7.4']
phpVersions: ['7.2', '7.3', '7.4', '8.0']
fail-fast: false
env:
phpExtensions: mbstring, intl, gd, xml, sqlite
cacheKey: ext-cache-v1
octoberCmsRelease: develop
winterCmsRelease: develop
steps:
- name: Checkout changes
uses: actions/checkout@v2
Expand All @@ -45,19 +45,21 @@ jobs:
with:
php-version: ${{ matrix.phpVersions }}
extensions: ${{ env.phpExtensions }}
tools: composer:v1
tools: composer:v2
coverage: none

- name: Install October CMS
- name: Install Winter CMS
run: |
wget https://github.com/octobercms/october/archive/${{ env.octoberCmsRelease }}.zip
unzip ${{ env.octoberCmsRelease }}.zip
wget https://github.com/wintercms/winter/archive/${{ env.winterCmsRelease }}.zip
unzip ${{ env.winterCmsRelease }}.zip
rm ${{ env.winterCmsRelease }}.zip
shopt -s dotglob
mv october-${{ env.octoberCmsRelease }}/* ./
mv winter-${{ env.winterCmsRelease }}/* ./
rmdir winter-${{ env.winterCmsRelease }}
shopt -u dotglob
cp config/cms.php config/testing/cms.php
mkdir -p plugins/rainlab
mv user-plugin plugins/rainlab/user
mkdir -p plugins/winter
mv user-plugin plugins/winter/user
- name: Get Composer cache directory
id: composercache
Expand All @@ -71,12 +73,12 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-interaction --no-progress --no-suggest
run: composer install --no-interaction --no-progress

- name: Run linting
run: ./vendor/bin/parallel-lint plugins/rainlab/user
run: ./vendor/bin/parallel-lint plugins/winter/user

- name: Run unit tests
run: |
cd plugins/rainlab/user
cd plugins/winter/user
../../../vendor/bin/phpunit
107 changes: 56 additions & 51 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace RainLab\User;
<?php namespace Winter\User;

use App;
use Auth;
Expand All @@ -7,9 +7,9 @@
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use Illuminate\Foundation\AliasLoader;
use RainLab\User\Classes\UserRedirector;
use RainLab\User\Models\MailBlocker;
use RainLab\Notify\Classes\Notifier;
use Winter\User\Classes\UserRedirector;
use Winter\User\Models\MailBlocker;
use Winter\Notify\Classes\Notifier;

class Plugin extends PluginBase
{
Expand All @@ -21,21 +21,22 @@ class Plugin extends PluginBase
public function pluginDetails()
{
return [
'name' => 'rainlab.user::lang.plugin.name',
'description' => 'rainlab.user::lang.plugin.description',
'name' => 'winter.user::lang.plugin.name',
'description' => 'winter.user::lang.plugin.description',
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-user',
'homepage' => 'https://github.com/rainlab/user-plugin'
'homepage' => 'https://github.com/wintercms/wn-user-plugin',
'replaces' => 'RainLab.User'
];
}

public function register()
{
$alias = AliasLoader::getInstance();
$alias->alias('Auth', 'RainLab\User\Facades\Auth');
$alias->alias('Auth', 'Winter\User\Facades\Auth');

App::singleton('user.auth', function () {
return \RainLab\User\Classes\AuthManager::instance();
return \Winter\User\Classes\AuthManager::instance();
});

App::singleton('redirect', function ($app) {
Expand All @@ -61,38 +62,38 @@ public function register()
});

/*
* Compatability with RainLab.Notify
* Compatability with Winter.Notify
*/
$this->bindNotificationEvents();
}

public function registerComponents()
{
return [
\RainLab\User\Components\Session::class => 'session',
\RainLab\User\Components\Account::class => 'account',
\RainLab\User\Components\ResetPassword::class => 'resetPassword'
\Winter\User\Components\Session::class => 'session',
\Winter\User\Components\Account::class => 'account',
\Winter\User\Components\ResetPassword::class => 'resetPassword'
];
}

public function registerPermissions()
{
return [
'rainlab.users.access_users' => [
'tab' => 'rainlab.user::lang.plugin.tab',
'label' => 'rainlab.user::lang.plugin.access_users'
'winter.users.access_users' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.access_users'
],
'rainlab.users.access_groups' => [
'tab' => 'rainlab.user::lang.plugin.tab',
'label' => 'rainlab.user::lang.plugin.access_groups'
'winter.users.access_groups' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.access_groups'
],
'rainlab.users.access_settings' => [
'tab' => 'rainlab.user::lang.plugin.tab',
'label' => 'rainlab.user::lang.plugin.access_settings'
'winter.users.access_settings' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.access_settings'
],
'rainlab.users.impersonate_user' => [
'tab' => 'rainlab.user::lang.plugin.tab',
'label' => 'rainlab.user::lang.plugin.impersonate_user'
'winter.users.impersonate_user' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.impersonate_user'
],
];
}
Expand All @@ -101,25 +102,25 @@ public function registerNavigation()
{
return [
'user' => [
'label' => 'rainlab.user::lang.users.menu_label',
'url' => Backend::url('rainlab/user/users'),
'label' => 'winter.user::lang.users.menu_label',
'url' => Backend::url('winter/user/users'),
'icon' => 'icon-user',
'iconSvg' => 'plugins/rainlab/user/assets/images/user-icon.svg',
'permissions' => ['rainlab.users.*'],
'iconSvg' => 'plugins/winter/user/assets/images/user-icon.svg',
'permissions' => ['winter.users.*'],
'order' => 500,

'sideMenu' => [
'users' => [
'label' => 'rainlab.user::lang.users.menu_label',
'label' => 'winter.user::lang.users.menu_label',
'icon' => 'icon-user',
'url' => Backend::url('rainlab/user/users'),
'permissions' => ['rainlab.users.access_users']
'url' => Backend::url('winter/user/users'),
'permissions' => ['winter.users.access_users']
],
'usergroups' => [
'label' => 'rainlab.user::lang.groups.menu_label',
'label' => 'winter.user::lang.groups.menu_label',
'icon' => 'icon-users',
'url' => Backend::url('rainlab/user/usergroups'),
'permissions' => ['rainlab.users.access_groups']
'url' => Backend::url('winter/user/usergroups'),
'permissions' => ['winter.users.access_groups']
]
]
]
Expand All @@ -130,31 +131,35 @@ public function registerSettings()
{
return [
'settings' => [
'label' => 'rainlab.user::lang.settings.menu_label',
'description' => 'rainlab.user::lang.settings.menu_description',
'label' => 'winter.user::lang.settings.menu_label',
'description' => 'winter.user::lang.settings.menu_description',
'category' => SettingsManager::CATEGORY_USERS,
'icon' => 'icon-cog',
'class' => 'RainLab\User\Models\Settings',
'class' => 'Winter\User\Models\Settings',
'order' => 500,
'permissions' => ['rainlab.users.access_settings']
'permissions' => ['winter.users.access_settings']
]
];
}

public function registerMailTemplates()
{
return [
'rainlab.user::mail.activate',
'rainlab.user::mail.welcome',
'rainlab.user::mail.restore',
'rainlab.user::mail.new_user',
'rainlab.user::mail.reactivate',
'rainlab.user::mail.invite',
'winter.user::mail.activate',
'winter.user::mail.welcome',
'winter.user::mail.restore',
'winter.user::mail.new_user',
'winter.user::mail.reactivate',
'winter.user::mail.invite',
];
}

public function registerNotificationRules()
{
if (!class_exists(\Winter\Notify\Classes\Notifier::class)) {
return [];
}

return [
'groups' => [
'user' => [
Expand All @@ -163,25 +168,25 @@ public function registerNotificationRules()
],
],
'events' => [
\RainLab\User\NotifyRules\UserActivatedEvent::class,
\RainLab\User\NotifyRules\UserRegisteredEvent::class,
\Winter\User\NotifyRules\UserActivatedEvent::class,
\Winter\User\NotifyRules\UserRegisteredEvent::class,
],
'actions' => [],
'conditions' => [
\RainLab\User\NotifyRules\UserAttributeCondition::class
'Winter\User\NotifyRules\UserAttributeCondition',
],
];
}

protected function bindNotificationEvents()
{
if (!class_exists(Notifier::class)) {
if (!class_exists(\Winter\Notify\Classes\Notifier::class)) {
return;
}

Notifier::bindEvents([
'rainlab.user.activate' => \RainLab\User\NotifyRules\UserActivatedEvent::class,
'rainlab.user.register' => \RainLab\User\NotifyRules\UserRegisteredEvent::class
'winter.user.activate' => \Winter\User\NotifyRules\UserActivatedEvent::class,
'winter.user.register' => \Winter\User\NotifyRules\UserRegisteredEvent::class,
]);

Notifier::instance()->registerCallback(function ($manager) {
Expand Down
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Front-end user plugin

[![Build Status](https://img.shields.io/github/workflow/status/rainlab/user-plugin/Tests)](https://github.com/rainlab/user-plugin/actions)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rainlab/user-plugin/blob/master/LICENCE.md)
[![Build Status](https://img.shields.io/github/workflow/status/wintercms/wn-user-plugin/Tests)](https://github.com/wintercms/wn-user-plugin/actions)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/wintercms/wn-user-plugin/blob/master/LICENCE.md)

Front-end user management for October CMS.
Front-end user management for Winter CMS.

## Requirements

This plugin requires the [Ajax Framework](https://octobercms.com/docs/cms/ajax) to be included in your layout/page in order to handle form requests.
This plugin requires the [Ajax Framework](https://wintercms.com/docs/cms/ajax) to be included in your layout/page in order to handle form requests.

## Managing users

Expand Down Expand Up @@ -47,11 +47,7 @@ As a security precaution, you may restrict users from having sessions across mul

#### Notifications

When a user is first activated -- either by registration, email confirmation or administrator approval -- they are sent a welcome email. To disable the welcome email, select "Do not send a notification" from the **Welcome mail template** dropdown. The default message template used is `rainlab.user::mail.welcome` and you can customize this by selecting **Mail > Mail Templates** from the settings menu.

## Extended features

For extra functionality, consider also installing the [User Plus+ plugin](http://octobercms.com/plugin/rainlab-userplus) (`RainLab.UserPlus`).
When a user is first activated -- either by registration, email confirmation or administrator approval -- they are sent a welcome email. To disable the welcome email, select "Do not send a notification" from the **Welcome mail template** dropdown. The default message template used is `winter.user::mail.welcome` and you can customize this by selecting **Mail > Mail Templates** from the settings menu.

## Session component

Expand Down Expand Up @@ -90,7 +86,7 @@ The `security` property can be user, guest or all. The `redirect` property refer

Access to routes can be restricted by applying the `AuthMiddleware`.

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

Expand Down Expand Up @@ -153,7 +149,7 @@ By default, the User plugin requires a minimum password length of 8 characters f

### Flash messages

This plugin makes use of October's [`Flash API`](http://octobercms.com/docs/markup/tag-flash). In order to display the error messages, you need to place the following snippet in your layout or page.
This plugin makes use of Winter CMS's [`Flash API`](https://wintercms.com/docs/markup/tag-flash). In order to display the error messages, you need to place the following snippet in your layout or page.

{% flash %}
<div class="alert alert-{{ type == 'error' ? 'danger' : type }}">{{ message }}</div>
Expand Down Expand Up @@ -219,7 +215,7 @@ Here the local handler method will take priority over the **account** component'

## Auth facade

There is an `Auth` facade you may use for common tasks, it primarily inherits the `October\Rain\Auth\Manager` class for functionality.
There is an `Auth` facade you may use for common tasks, it primarily inherits the `Winter\Storm\Auth\Manager` class for functionality.

You may use `Auth::register` to register an account:

Expand Down Expand Up @@ -290,7 +286,7 @@ When a user registers with the same email address using the `Auth::register` met

> **Important**: If you are using guest accounts, it is important to disable sensitive functionality for user accounts that are not verified, since it may be possible for anyone to inherit a guest account.
You may also convert a guest to a registered user with the `convertToRegistered` method. This will generate a random password and sends an invitation using the `rainlab.user::mail.invite` template.
You may also convert a guest to a registered user with the `convertToRegistered` method. This will generate a random password and sends an invitation using the `winter.user::mail.invite` template.

$user->convertToRegistered();

Expand All @@ -302,26 +298,26 @@ To disable the notification and password reset, pass the first argument as false

This plugin will fire some global events that can be useful for interacting with other plugins.

- **rainlab.user.beforeRegister**: Before the user's registration is processed. Passed the `$data` variable by reference to enable direct modifications to the `$data` provided to the `Auth::register()` method.
- **rainlab.user.register**: The user has successfully registered. Passed the `$user` object and the submitted `$data` variable.
- **rainlab.user.beforeAuthenticate**: Before the user is attempting to authenticate using the Account component.
- **rainlab.user.login**: The user has successfully signed in.
- **rainlab.user.logout**: The user has successfully signed out.
- **rainlab.user.deactivate**: The user has opted-out of the site by deactivating their account. This should be used to disable any content the user may want removed.
- **rainlab.user.reactivate**: The user has reactivated their own account by signing back in. This should revive the users content on the site.
- **rainlab.user.getNotificationVars**: Fires when sending a user notification to enable passing more variables to the email templates. Passes the `$user` model the template will be for.
- **rainlab.user.view.extendListToolbar**: Fires when the user listing page's toolbar is rendered.
- **rainlab.user.view.extendPreviewToolbar**: Fires when the user preview page's toolbar is rendered.
- **winter.user.beforeRegister**: Before the user's registration is processed. Passed the `$data` variable by reference to enable direct modifications to the `$data` provided to the `Auth::register()` method.
- **winter.user.register**: The user has successfully registered. Passed the `$user` object and the submitted `$data` variable.
- **winter.user.beforeAuthenticate**: Before the user is attempting to authenticate using the Account component.
- **winter.user.login**: The user has successfully signed in.
- **winter.user.logout**: The user has successfully signed out.
- **winter.user.deactivate**: The user has opted-out of the site by deactivating their account. This should be used to disable any content the user may want removed.
- **winter.user.reactivate**: The user has reactivated their own account by signing back in. This should revive the users content on the site.
- **winter.user.getNotificationVars**: Fires when sending a user notification to enable passing more variables to the email templates. Passes the `$user` model the template will be for.
- **winter.user.view.extendListToolbar**: Fires when the user listing page's toolbar is rendered.
- **winter.user.view.extendPreviewToolbar**: Fires when the user preview page's toolbar is rendered.

Here is an example of hooking an event:

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

A common requirement is to adapt another to a legacy authentication system. In the example below, the `WordPressLogin::check` method would check the user password using an alternative hashing method, and if successful, update to the new one used by October.
A common requirement is to adapt another to a legacy authentication system. In the example below, the `WordPressLogin::check` method would check the user password using an alternative hashing method, and if successful, update to the new one used by Winter CMS.

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

Expand All @@ -335,7 +331,7 @@ A common requirement is to adapt another to a legacy authentication system. In t
/*
* The user is logging in with their old WordPress account
* for the first time. Rehash their password using the new
* October system.
* Winter CMS system.
*/
if (WordPressLogin::check($user->password, $password)) {
$user->password = $user->password_confirmation = $password;
Expand Down
Loading

0 comments on commit 5b06e30

Please sign in to comment.