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 #22 from ReFlar/analysis-q21PrP
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
Ralkage authored May 15, 2018
2 parents 452314c + 9ac199a commit 6b8b132
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
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 6b8b132

Please sign in to comment.