Skip to content

Commit 1c37a8f

Browse files
committed
Fixes account creation and password reset abilities.
1 parent 3dc286b commit 1c37a8f

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

app/Observers/UserObserver.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
namespace Pterodactyl\Observers;
2626

2727
use DB;
28+
use Hash;
29+
use Carbon;
2830
use Pterodactyl\Events;
2931
use Pterodactyl\Models\User;
3032
use Pterodactyl\Notifications\AccountCreated;
@@ -52,12 +54,20 @@ public function created(User $user)
5254
{
5355
event(new Events\User\Created($user));
5456

55-
$token = DB::table('password_resets')->where('email', $user->email)->orderBy('created_at', 'desc')->first();
56-
$user->notify((new AccountCreated([
57+
if ($user->password === 'unset') {
58+
$token = hash_hmac('sha256', str_random(40), config('app.key'));
59+
DB::table('password_resets')->insert([
60+
'email' => $user->email,
61+
'token' => Hash::make($token),
62+
'created_at' => Carbon::now()->toDateTimeString(),
63+
]);
64+
}
65+
66+
$user->notify(new AccountCreated([
5767
'name' => $user->name_first,
5868
'username' => $user->username,
59-
'token' => (! is_null($token)) ? $token->token : null,
60-
])));
69+
'token' => (isset($token)) ? $token : null,
70+
]));
6171
}
6272

6373
/**

app/Repositories/UserRepository.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,12 @@ public function create(array $data)
8383
'username' => $data['username'],
8484
'name_first' => $data['name_first'],
8585
'name_last' => $data['name_last'],
86-
'password' => Hash::make((empty($data['password'])) ? str_random(30) : $data['password']),
86+
'password' => (empty($data['password'])) ? 'unset' : Hash::make($data['password']),
8787
'root_admin' => $data['root_admin'],
8888
'language' => Settings::get('default_language', 'en'),
8989
]);
9090
$user->save();
9191

92-
// Setup a Password Reset to use when they set a password.
93-
// Only used if no password is provided.
94-
if (empty($data['password'])) {
95-
$token = str_random(32);
96-
DB::table('password_resets')->insert([
97-
'email' => $user->email,
98-
'token' => $token,
99-
'created_at' => Carbon::now()->toDateTimeString(),
100-
]);
101-
}
102-
10392
DB::commit();
10493

10594
return $user;

config/auth.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
'passwords' => [
9494
'users' => [
9595
'provider' => 'users',
96-
'email' => 'emails.password',
9796
'table' => 'password_resets',
9897
'expire' => 60,
9998
],

resources/themes/pterodactyl/auth/passwords/reset.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<div class="col-xs-12">
7777
{!! csrf_field() !!}
7878
<input type="hidden" name="token" value="{{ $token }}">
79-
<button type="submit" class="btn btn-primary btn-block btn-flat">@lang('auth.reset_password')</button>
79+
<button type="submit" class="btn btn-primary btn-block btn-flat g-recaptcha" @if(config('recaptcha.enabled')) data-sitekey="{{ config('recaptcha.website_key') }}" data-callback='onSubmit' @endif>@lang('auth.reset_password')</button>
8080
</div>
8181
</div>
8282
</form>

0 commit comments

Comments
 (0)