Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #21 from ReFlar/0.1.5
Browse files Browse the repository at this point in the history
0.1.5
  • Loading branch information
Ralkage authored May 15, 2018
2 parents 3a95737 + 6b8b132 commit 81a4faa
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 59 deletions.
54 changes: 34 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -33,25 +47,25 @@ 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.

You also have the api/strike post route to give a user a strike, /API strike/{userId} get route to get a user's strikes, and /api/strike/{id} delete route to delete the strike.

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](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
## 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)
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},

{
"name": "Charlie K",
"email": "[email protected]",
"homepage": "https://reflar.io"
"name": "Charlie K",
"email": "[email protected]",
"homepage": "https://reflar.io"
}
],
"support": {
Expand All @@ -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/"
}
Expand All @@ -46,4 +49,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Api/Controllers/CreateUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Serializers/StrikeSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/RegisterUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 7 additions & 5 deletions src/Commands/RegisterUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -208,17 +208,19 @@ 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)
{
$flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;
if (filter_var($ip, FILTER_VALIDATE_IP, $flags) === false) {
return false;
}

return true;
}
}
2 changes: 1 addition & 1 deletion src/Commands/ServeStrikeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions src/Listeners/AddApiAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/Listeners/AddClientAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81a4faa

Please sign in to comment.