Skip to content

Commit

Permalink
Update NPM dependencies and improve Argon2 support detection
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Oct 24, 2020
1 parent 86f805a commit ffc4a98
Show file tree
Hide file tree
Showing 6 changed files with 447 additions and 546 deletions.
32 changes: 17 additions & 15 deletions app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Exception;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Hashing\HashManager;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -50,16 +51,6 @@ class SettingsController extends Controller
'argon2id' => 'Argon2id',
];

/**
* The hash algorithms PHP constants.
*
* @var array
*/
private $hashCompatibility = [
'argon' => 'PASSWORD_ARGON2I',
'argon2id' => 'PASSWORD_ARGON2ID',
];

/**
* The application instance.
*
Expand Down Expand Up @@ -174,11 +165,7 @@ public function updateSecurity(Request $request)
'recaptcha-secret-key' => ['required_with:recaptcha', 'max:50'],
'hash' => [
'required', 'string', Rule::in($hash), function ($attribute, $value, $fail) {
if (! array_key_exists($value, $this->hashCompatibility)) {
return;
}

if (! defined($this->hashCompatibility[$value])) {
if (! $this->isHashSupported($value)) {
$fail(trans('admin.settings.security.hash-error'));
}
},
Expand Down Expand Up @@ -430,4 +417,19 @@ protected function getAvailableLocaleCodes()
return basename($path);
});
}

protected function isHashSupported(string $algo)
{
if ($algo === 'bcrypt') {
return true;
}

try {
$hashManager = $this->app->make(HashManager::class);

return $hashManager->driver($algo)->make('hello') !== null;
} catch (Exception $e) {
return false;
}
}
}
9 changes: 8 additions & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ public function updateEmail(Request $request)
'email' => ['required', 'string', 'email', 'max:50', 'unique:users'],
]);

$request->user()->update($request->only('email'));
$user = $request->user();

$user->forceFill([
'email' => $request->input('email'),
'email_verified_at' => null,
])->save();

$user->sendEmailVerificationNotification();

return redirect()->route('profile.index')->with('success', trans('messages.profile.updated'));
}
Expand Down
7 changes: 4 additions & 3 deletions app/Support/Discord/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Azuriom\Support\Discord\Embeds\EmbedField;
use Azuriom\Support\Discord\Embeds\EmbedFooter;
use Azuriom\Support\Discord\Embeds\EmbedThumbnail;
use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -37,7 +38,7 @@ class Embed implements Arrayable
/**
* Timestamp of embed content.
*
* @var \DateTimeInterface|null
* @var \Carbon\CarbonInterface|null
*/
protected $timestamp;

Expand Down Expand Up @@ -133,7 +134,7 @@ public function url(?string $url)
*/
public function timestamp(?DateTimeInterface $timestamp)
{
$this->timestamp = $timestamp;
$this->timestamp = Carbon::instance($timestamp);

return $this;
}
Expand Down Expand Up @@ -227,7 +228,7 @@ public function toArray()
'title' => $this->title,
'description' => $this->description,
'url' => $this->url,
'timestamp' => optional($this->timestamp)->format(DateTimeInterface::ATOM),
'timestamp' => optional($this->timestamp)->toAtomString(),
'color' => $this->color,
'footer' => optional($this->footer)->toArray(),
'thumbnail' => optional($this->thumbnail)->toArray(),
Expand Down

0 comments on commit ffc4a98

Please sign in to comment.