From 26434d8e226e77bd6f5284f012b59910e6274f9d Mon Sep 17 00:00:00 2001 From: Christian Lopez Date: Sun, 13 May 2018 18:24:21 -0400 Subject: [PATCH 1/4] Added conflict with flagrow/terms See #20 --- composer.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 4dca0e3..4da40c2 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ }, { - "name": "Charlie K", - "email": "issyrocks12@reflar.email", - "homepage": "https://reflar.io" + "name": "Charlie K", + "email": "issyrocks12@reflar.email", + "homepage": "https://reflar.io" } ], "support": { @@ -31,7 +31,10 @@ "require": { "flarum/core": "^0.1.0-beta.6" }, - "autoload": { + "conflict": { + "flagrow/terms": ">=0.1.0" + }, + "autoload": { "psr-4": { "Reflar\\UserManagement\\": "src/" } @@ -46,4 +49,4 @@ } } } -} \ No newline at end of file +} From c69f714b94725303a02ec73a15346fd25829e119 Mon Sep 17 00:00:00 2001 From: Christian Lopez Date: Sun, 13 May 2018 18:26:45 -0400 Subject: [PATCH 2/4] Tidy up README.md - Fixed spelling. - Added compatibility list (see #20 to why this was added). - Changed GitLab links to GitHub. - Fixed shields. --- README.md | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 278be07..7ca4b6a 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,43 @@ -# Flarum User Management by ReFlar +# User Management by ReFlar -[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitlab.com/ReFlar/user-management/blob/master/LICENSE) [![Latest Stable Version](https://img.shields.io/packagist/v/reflar/user-management.svg)](https://gitlab.com/ReFlar/user-management) +[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/reflar/user-management/blob/master/LICENSE.md) [![Latest Stable Version](https://img.shields.io/packagist/v/reflar/user-management.svg)](https://packagist.org/packages/reflar/user-management) [![Total Downloads](https://img.shields.io/packagist/dt/reflar/user-management.svg)](https://packagist.org/packages/reflar/user-management) -A [Flarum](http://flarum.org) extension that allows your to manage every aspect of your users, with style! +A [Flarum](http://flarum.org) extension that allows you to manage every aspect of your users, with style! -This extension allows you to give users strikes for posts if they violate rules. Those strikes are kept and can be viewed at anytime by anyone with permission. This extension also allows your to disable the email registration option, as well as adds age and gender at registration. The user's age and gender is shown on their profile page. You can also manually activate users from the admin interface, or from the users page. +This extension allows you to give users strikes for posts if they violate rules. Those strikes are kept and can be viewed at any time by anyone with permission. This extension also allows you to disable the email registration option, as well as giving you the ability to add an age and gender field to the user registration modal. The user's age and gender is shown on their profile page. You can also manually activate users from the admin interface, or from the users page. ![gif](http://i.imgur.com/pkMM6aA.gif) ![gif](http://i.imgur.com/dfHaFwL.gif) -### Goals +## Compatibility -- To make registration more customizable -- To log user incidents +This extension might not be compatible with other extensions that make change to the sign up modal as well. If an extension is not listed below, please try it on a test forum first and let us know if it works. -### Usage +**Works With:** -- Moderators can asign strikes to posts -- Strikes can be tracked from admin page or directly from user page -- Remove email registration -- Added age and gender +- All ReFlar extensions -### Installation +**Does Not Work With:** + +- [Flagrow Terms](https://github.com/flagrow/terms) (should be compatible again in future version 0.2) see [ReFlar/user-management#20](https://github.com/ReFlar/user-management/issues/20) for more details + +## Goals + +- To provide an easy and intuitive User Management solution. +- To make registration more customizable. +- To log user incidents. + +## Usage + +- User Management from the Admin CP. +- Moderators can assign strikes to posts. +- Strikes can be tracked from admin page or directly from the user page. +- Remove email registration. +- Added age and gender. + +## Installation Install it with composer: @@ -33,7 +47,7 @@ composer require reflar/user-management Then login and enable the extension. -### Developer Guide +## Developer Guide You have 2 events to listen for "UserWillBeGivenStrike" as well as "UserWasGivenStike" which both contain the offending post, the user being struck, the strike issuer, and the reason. @@ -41,17 +55,17 @@ You also have the api/strike post route to give a user a strike, /API strike/{us You can also post to /api/reflar/usermanagement/attributes to set a user's gender and age. -### To Do +## To Do - Requests? -### Issues +## Issues -- None known +- Incompatibility with Flagrow's Terms extension. -### Links +## Links -- [on github](https://gitlab.com/ReFlar/user-management) +- [on github](https://github.com/ReFlar/user-management) - [on packagist](https://packagist.org/packages/ReFlar/user-management) -- [issues](https://gitlab.com/ReFlar/user-management/issues) +- [issues](https://github.com/ReFlar/user-management/issues) From 452314cb53dca8de4089d0f44b0250b5ac71c91a Mon Sep 17 00:00:00 2001 From: Christian Lopez Date: Sun, 13 May 2018 18:28:45 -0400 Subject: [PATCH 3/4] Updated current "Issues" under "To Do" --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ca4b6a..ed12894 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This extension might not be compatible with other extensions that make change to **Does Not Work With:** -- [Flagrow Terms](https://github.com/flagrow/terms) (should be compatible again in future version 0.2) see [ReFlar/user-management#20](https://github.com/ReFlar/user-management/issues/20) for more details +- [Flagrow Terms](https://github.com/flagrow/terms) (should be compatible again in future version 0.2) see [ReFlar/user-management#20](https://github.com/ReFlar/user-management/issues/20) for more details. ## Goals @@ -61,7 +61,7 @@ You can also post to /api/reflar/usermanagement/attributes to set a user's gende ## Issues -- Incompatibility with Flagrow's Terms extension. +- Incompatibility with [Flagrow's Terms](https://github.com/flagrow/terms) extension (should be compatible again in future version 0.2) see [ReFlar/user-management#20](https://github.com/ReFlar/user-management/issues/20) for more details. ## Links From 9ac199a8d22dee3d7d502488a0af66e81ed68c9e Mon Sep 17 00:00:00 2001 From: Christian Lopez Date: Tue, 15 May 2018 18:38:42 +0000 Subject: [PATCH 4/4] Apply fixes from StyleCI --- src/Api/Controllers/CreateUserController.php | 2 +- src/Api/Serializers/StrikeSerializer.php | 2 +- src/Commands/RegisterUser.php | 8 ++-- src/Commands/RegisterUserHandler.php | 12 +++--- src/Commands/ServeStrikeHandler.php | 2 +- src/Listeners/AddApiAttributes.php | 42 ++++++++++---------- src/Listeners/AddClientAssets.php | 2 +- 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/Api/Controllers/CreateUserController.php b/src/Api/Controllers/CreateUserController.php index 1e78338..3cd0dad 100644 --- a/src/Api/Controllers/CreateUserController.php +++ b/src/Api/Controllers/CreateUserController.php @@ -42,7 +42,7 @@ protected function data(ServerRequestInterface $request, Document $document) { $serverParams = $request->getServerParams(); - if(isset($serverParams['HTTP_CF_CONNECTING_IP'])) { + if (isset($serverParams['HTTP_CF_CONNECTING_IP'])) { $ipAddress = $serverParams['HTTP_CF_CONNECTING_IP']; } else { $ipAddress = $serverParams['REMOTE_ADDR']; diff --git a/src/Api/Serializers/StrikeSerializer.php b/src/Api/Serializers/StrikeSerializer.php index 254b420..61c895f 100644 --- a/src/Api/Serializers/StrikeSerializer.php +++ b/src/Api/Serializers/StrikeSerializer.php @@ -23,7 +23,7 @@ protected function getDefaultAttributes($strike) return [ 'id' => (int) $strike->id, 'userId' => (int) $strike->user_id, - 'post' => $strike->discussion_id . '/'. $strike->post_id, + 'post' => $strike->discussion_id.'/'.$strike->post_id, 'reason' => $strike->reason, 'actor' => $strike->actor_id, 'content' => $strike->post_content, diff --git a/src/Commands/RegisterUser.php b/src/Commands/RegisterUser.php index 0fab259..4138eb9 100644 --- a/src/Commands/RegisterUser.php +++ b/src/Commands/RegisterUser.php @@ -32,16 +32,16 @@ class RegisterUser public $data; /** - * The IP address of the request + * The IP address of the request. * * @var string */ public $ip; /** - * @param User $actor The user performing the action. - * @param array $data The attributes of the new user. - * @param string $ip The IP address of the request + * @param User $actor The user performing the action. + * @param array $data The attributes of the new user. + * @param string $ip The IP address of the request */ public function __construct(User $actor, array $data, $ip) { diff --git a/src/Commands/RegisterUserHandler.php b/src/Commands/RegisterUserHandler.php index 4d02a84..370ec7a 100644 --- a/src/Commands/RegisterUserHandler.php +++ b/src/Commands/RegisterUserHandler.php @@ -116,13 +116,13 @@ public function handle(RegisterUser $command) $password = $password ?: str_random(20); } - if($this->settings->get('Reflar-sfs') == true) { + if ($this->settings->get('Reflar-sfs') == true) { if (isset($command->ip) && $this->isValidIpAddress($command->ip)) { $ipAddress = $command->ip; } $client = new Guzzle([ - 'query' => ['ip' => $ipAddress, 'email' => $email] + 'query' => ['ip' => $ipAddress, 'email' => $email], ]); $response = $client->request('GET', 'http://api.stopforumspam.org/api'); $body = $response->getBody()->getContents(); @@ -208,10 +208,11 @@ private function saveAvatarFromUrl(User $user, $url) } /** - * Check that a given string is a valid IP address + * Check that a given string is a valid IP address. * - * @param string $ip - * @return boolean + * @param string $ip + * + * @return bool */ protected function isValidIpAddress($ip) { @@ -219,6 +220,7 @@ protected function isValidIpAddress($ip) if (filter_var($ip, FILTER_VALIDATE_IP, $flags) === false) { return false; } + return true; } } diff --git a/src/Commands/ServeStrikeHandler.php b/src/Commands/ServeStrikeHandler.php index 349b3dd..d3cba6b 100644 --- a/src/Commands/ServeStrikeHandler.php +++ b/src/Commands/ServeStrikeHandler.php @@ -96,7 +96,7 @@ public function handle(ServeStrike $command) $discussion = $this->discussions->findOrFail($post->discussion_id, $command->actor); $discussion->hide_time = date('Y-m-d H:i:s'); $discussion->save(); - } + } } $this->events->fire( new UserWasGivenStrike($post, $user, $command->actor, $command->reason) diff --git a/src/Listeners/AddApiAttributes.php b/src/Listeners/AddApiAttributes.php index dbc340d..7b5ea4b 100644 --- a/src/Listeners/AddApiAttributes.php +++ b/src/Listeners/AddApiAttributes.php @@ -62,25 +62,25 @@ public function configureApiRoutes(ConfigureApiRoutes $event) $event->delete('/strike/{id}', 'strike', DeleteStrikeController::class); } - /** - * @param PrepareApiAttributes $event - */ - public function addAttributes(PrepareApiAttributes $event) - { - if ($event->isSerializer(DiscussionSerializer::class)) { - $event->attributes['canStrike'] = $event->actor->can('strike', $event->model); - } - if ($event->isSerializer(ForumSerializer::class)) { - $event->attributes['ReFlar-emailRegEnabled'] = $this->settings->get('Reflar-emailRegEnabled'); - $event->attributes['ReFlar-genderRegEnabled'] = $this->settings->get('Reflar-genderRegEnabled'); - $event->attributes['ReFlar-ageRegEnabled'] = $this->settings->get('Reflar-ageRegEnabled'); - $event->attributes['ReFlar-amountPerPage'] = $this->settings->get('Reflar-genderRegEnabled'); - } - if ($event->isSerializer(UserSerializer::class)) { - $event->attributes['canActivate'] = $event->actor->can('activate', $event->model); - $event->attributes['canViewStrike'] = $event->actor->can('strike', $event->model); - $event->attributes['gender'] = $event->model->gender; - $event->attributes['age'] = $event->model->age; - } - } + /** + * @param PrepareApiAttributes $event + */ + public function addAttributes(PrepareApiAttributes $event) + { + if ($event->isSerializer(DiscussionSerializer::class)) { + $event->attributes['canStrike'] = $event->actor->can('strike', $event->model); + } + if ($event->isSerializer(ForumSerializer::class)) { + $event->attributes['ReFlar-emailRegEnabled'] = $this->settings->get('Reflar-emailRegEnabled'); + $event->attributes['ReFlar-genderRegEnabled'] = $this->settings->get('Reflar-genderRegEnabled'); + $event->attributes['ReFlar-ageRegEnabled'] = $this->settings->get('Reflar-ageRegEnabled'); + $event->attributes['ReFlar-amountPerPage'] = $this->settings->get('Reflar-genderRegEnabled'); + } + if ($event->isSerializer(UserSerializer::class)) { + $event->attributes['canActivate'] = $event->actor->can('activate', $event->model); + $event->attributes['canViewStrike'] = $event->actor->can('strike', $event->model); + $event->attributes['gender'] = $event->model->gender; + $event->attributes['age'] = $event->model->age; + } + } } diff --git a/src/Listeners/AddClientAssets.php b/src/Listeners/AddClientAssets.php index b6146e2..a3f6afd 100644 --- a/src/Listeners/AddClientAssets.php +++ b/src/Listeners/AddClientAssets.php @@ -14,8 +14,8 @@ namespace Reflar\UserManagement\Listeners; use DirectoryIterator; -use Flarum\Event\ConfigureWebApp; use Flarum\Event\ConfigureLocales; +use Flarum\Event\ConfigureWebApp; use Illuminate\Contracts\Events\Dispatcher; class AddClientAssets