Commit 64260f08 authored by Korko's avatar Korko
Browse files

Fix CI and styles

parent 141abb6c
......@@ -33,7 +33,7 @@ variables:
phpcs:
script:
- vendor/bin/phpcs --standard="./phpcs.xml" -w --colors app/
- composer check-style
allow_failure: true
# Run our tests
......
......@@ -2,9 +2,7 @@
namespace App\Database;
use Config;
use App\Services\SymmetricalEncrypter;
use Illuminate\Contracts\Encryption\DecryptException;
trait AttributesEncrypter
{
......@@ -13,10 +11,10 @@ trait AttributesEncrypter
public function setAttribute($key, $value)
{
parent::setAttribute($key, $value);
parent::setAttribute($key, $value);
// Don't use $value, parent setAttribute may have modified it
$this->attributes[$key] = $this->isEncryptable($key) ? $this->encrypt($this->attributes[$key]) : $this->attributes[$key];
// Don't use $value, parent setAttribute may have modified it
$this->attributes[$key] = $this->isEncryptable($key) ? $this->encrypt($this->attributes[$key]) : $this->attributes[$key];
}
public function getAttributeFromArray($key)
......
......@@ -5,10 +5,14 @@ namespace App\Database;
interface EncryptsAttributes
{
public function setAttribute($key, $value);
public function getAttributeFromArray($key);
public function isEncryptable($key): bool;
public function shareEncryptionKey(EncryptsAttributes $other): EncryptsAttributes;
public function setEncryptionKey(string $key): EncryptsAttributes;
public function getEncryptionKey(): string;
}
......@@ -3,7 +3,6 @@
namespace App;
use App\Database\Model;
use App\Services\SymmetricalEncrypter;
class DearSanta extends Model
{
......
......@@ -3,8 +3,8 @@
namespace App\Http\Controllers;
use Mail;
use Metrics;
use Hashids;
use Metrics;
use App\DearSanta;
use App\Http\Requests\DearSantaRequest;
use App\Mail\DearSanta as DearSantaMail;
......
......@@ -2,7 +2,6 @@
namespace App\Http\Controllers;
use Mail;
use App\Draw;
use App\Participant;
use App\Http\Requests\OrganizerChangeEmailRequest;
......@@ -29,7 +28,7 @@ class OrganizerController extends Controller
$participant->email_address = $request->input('email');
$participant->save();
$emailSent = true;//$this->resendEmail($draw, $participant);
$emailSent = true; //$this->resendEmail($draw, $participant);
$message = $emailSent ? trans('organizer.up_and_sent') : trans('organizer.up_but_not_sent');
return $request->ajax() ?
......@@ -41,6 +40,5 @@ class OrganizerController extends Controller
{
$key = base64_decode($request->input('key'));
$participant->setEncryptionKey($key);
}
}
......@@ -4,8 +4,6 @@ namespace App\Http\Controllers;
use Arr;
use Metrics;
use App\Draw;
use App\Participant;
use Illuminate\Http\Request;
use App\Services\DrawHandler;
use App\Exceptions\SolverException;
......
......@@ -2,9 +2,6 @@
namespace App\Http\Middleware;
use Closure;
use App\Http\Middleware\TransformsRequest;
class DecryptInput extends TransformsRequest
{
protected $decrypter;
......@@ -13,7 +10,7 @@ class DecryptInput extends TransformsRequest
{
parent::__construct();
$key = md5(csrf_token() . config('app.key'));
$key = md5(csrf_token().config('app.key'));
$this->decrypter = new Encrypter($key);
}
......
......@@ -2,8 +2,6 @@
namespace App\Http\Middleware;
use Closure;
use Symfony\Component\HttpFoundation\ParameterBag;
use Illuminate\Foundation\Http\Middleware\TransformsRequest as Middleware;
class TransformsRequest extends Middleware
......
......@@ -6,7 +6,6 @@ use App\Draw;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class OrganizerRecap extends Mailable
{
......@@ -37,7 +36,7 @@ class OrganizerRecap extends Mailable
$csv = $this->formatCsv($this->draw->participants->map(function ($participant) {
return [
$participant->name,
$participant->email_address
$participant->email_address,
];
}));
......@@ -47,10 +46,9 @@ class OrganizerRecap extends Mailable
->attachData($csv, 'secretsanta.csv', [
'mime' => 'text/csv',
]);
}
protected function formatCsv(iterable $data, $delimiter = ",", $enclosure = '"', $escape_char = "\\")
protected function formatCsv(iterable $data, $delimiter = ',', $enclosure = '"', $escape_char = '\\')
{
$f = fopen('php://memory', 'r+');
foreach ($data as $fields) {
......@@ -60,6 +58,7 @@ class OrganizerRecap extends Mailable
}
rewind($f);
$csv_line = stream_get_contents($f);
return rtrim($csv_line);
}
}
......@@ -2,7 +2,6 @@
namespace App\Providers;
use Form;
use App\Services\CryptedFormBuilder;
use Illuminate\Support\ServiceProvider;
......
......@@ -19,8 +19,9 @@ class CryptedFormBuilder extends FormBuilder
*/
public function input($type, $name, $value = null, $options = [])
{
$key = md5(csrf_token() . config('app.key'));
$key = md5(csrf_token().config('app.key'));
$name = (new Encrypter($key))->encrypt($name);
return parent::input($type, $name, $value, $options);
}
}
......@@ -5,8 +5,8 @@ namespace App\Services;
use Arr;
use Sms;
use Mail;
use Metrics;
use Hashids;
use Metrics;
use App\Draw;
use App\DearSanta;
use App\Participant;
......@@ -111,4 +111,3 @@ class DrawHandler
Sms::message($participant->phone_number, $contentSms);
}
}
......@@ -72,6 +72,8 @@
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
],
"check-style": "php-cs-fixer fix --dry-run --diff",
"fix-style": "php-cs-fixer fix"
}
}
......@@ -12,7 +12,7 @@
*/
Route::get('/', 'RandomFormController@view');
Route::post('/', 'RandomFormController@handle');//->middleware('decrypt.input');
Route::post('/', 'RandomFormController@handle'); //->middleware('decrypt.input');
Route::pattern('santa', '[0-9a-zA-Z]{'.config('hashids.connections')[config('hashids.default')]['length'].'}');
Route::get('/dearsanta/{santa}', 'DearSantaController@view')->name('dearsanta');
......
......@@ -38,23 +38,23 @@ class RequestCase extends TestCase
}
/**
$participants = [
[
'name' => 'toto',
'email' => 'test@test.com',
'target' => 1,
],
[
'name' => 'tata',
'email' => 'test2@test.com',
'target' => 2,
],
[
'name' => 'tutu',
'email' => 'test3@test.com',
'target' => 0,
],
];
* $participants = [
* [
* 'name' => 'toto',
* 'email' => 'test@test.com',
* 'target' => 1,
* ],
* [
* 'name' => 'tata',
* 'email' => 'test2@test.com',
* 'target' => 2,
* ],
* [
* 'name' => 'tutu',
* 'email' => 'test3@test.com',
* 'target' => 0,
* ],
* ];
*/
public function formatParticipants($participants)
{
......
......@@ -91,23 +91,23 @@ class RequestOrganizerTest extends RequestCase
// Check data can be changed
$path = route('organizerPanel.changeEmail', [
'draw' => $draw->id,
'participant' => $participant
'participant' => $participant,
]);
$response = $this->ajaxPost($path, [
'g-recaptcha-response' => 'mocked',
'key' => base64_encode($draw->getEncryptionKey()),
'email' => 'test@test2.com'
'email' => 'test@test2.com',
]);
$before = $participant->email_address;
$after = $participant->fresh()->shareEncryptionKey($draw)->email_address;
$this->assertNotEquals($before, $after);
$this->assertEquals('test@test2.com', $after);
/*
$response
->assertStatus(200)
->assertJson([
'message' => 'Envoyé avec succès !',
]);*/
/*
$response
->assertStatus(200)
->assertJson([
'message' => 'Envoyé avec succès !',
]);*/
}
}
......@@ -6,7 +6,6 @@ use Sms;
use Mail;
use Metrics;
use App\Draw;
use Notification;
use App\DearSanta;
use App\Participant;
use App\Mail\TargetDrawn;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment