Skip to content

Commit d2bc791

Browse files
committed
Fix links sent to users when accounts are created
closes pterodactyl#1093
1 parent 304d947 commit d2bc791

File tree

6 files changed

+20
-136
lines changed

6 files changed

+20
-136
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1313
* Logo now links to the correct location on all pages.
1414
* Permissions checking to determine if a user can see the task management page now works correctly.
1515
* Fixed `pterodactyl.environment_variables` to be used correctly for global environment variables. The wrong config variable name was being using previously.
16+
* Fixes tokens being sent to users when their account is created to actually work. Implements Laravel's internal token creation mechanisms rather than trying to do it custom.
1617

1718
### Changed
1819
* Attempting to upload a folder via the web file manager will now display a warning telling the user to use SFTP.

app/Notifications/AccountCreated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AccountCreated extends Notification implements ShouldQueue
2323
/**
2424
* The user model for the created user.
2525
*
26-
* @var object
26+
* @var \Pterodactyl\Models\User
2727
*/
2828
public $user;
2929

@@ -65,7 +65,7 @@ public function toMail($notifiable)
6565
->line('Email: ' . $this->user->email);
6666

6767
if (! is_null($this->token)) {
68-
return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . $this->user->email));
68+
return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . urlencode($this->user->email)));
6969
}
7070

7171
return $message;

app/Services/Helpers/TemporaryPasswordService.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

app/Services/Users/UserCreationService.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Ramsey\Uuid\Uuid;
66
use Illuminate\Contracts\Hashing\Hasher;
77
use Illuminate\Database\ConnectionInterface;
8+
use Illuminate\Contracts\Auth\PasswordBroker;
89
use Pterodactyl\Notifications\AccountCreated;
9-
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
1010
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1111

1212
class UserCreationService
@@ -22,9 +22,9 @@ class UserCreationService
2222
private $hasher;
2323

2424
/**
25-
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
25+
* @var \Illuminate\Contracts\Auth\PasswordBroker
2626
*/
27-
private $passwordService;
27+
private $passwordBroker;
2828

2929
/**
3030
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
@@ -36,18 +36,18 @@ class UserCreationService
3636
*
3737
* @param \Illuminate\Database\ConnectionInterface $connection
3838
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
39-
* @param \Pterodactyl\Services\Helpers\TemporaryPasswordService $passwordService
39+
* @param \Illuminate\Contracts\Auth\PasswordBroker $passwordBroker
4040
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
4141
*/
4242
public function __construct(
4343
ConnectionInterface $connection,
4444
Hasher $hasher,
45-
TemporaryPasswordService $passwordService,
45+
PasswordBroker $passwordBroker,
4646
UserRepositoryInterface $repository
4747
) {
4848
$this->connection = $connection;
4949
$this->hasher = $hasher;
50-
$this->passwordService = $passwordService;
50+
$this->passwordBroker = $passwordBroker;
5151
$this->repository = $repository;
5252
}
5353

@@ -68,15 +68,19 @@ public function handle(array $data)
6868

6969
$this->connection->beginTransaction();
7070
if (! isset($data['password']) || empty($data['password'])) {
71+
$generateResetToken = true;
7172
$data['password'] = $this->hasher->make(str_random(30));
72-
$token = $this->passwordService->handle($data['email']);
7373
}
7474

7575
/** @var \Pterodactyl\Models\User $user */
7676
$user = $this->repository->create(array_merge($data, [
7777
'uuid' => Uuid::uuid4()->toString(),
7878
]), true, true);
7979

80+
if (isset($generateResetToken)) {
81+
$token = $this->passwordBroker->createToken($user);
82+
}
83+
8084
$this->connection->commit();
8185
$user->notify(new AccountCreated($user, $token ?? null));
8286

tests/Unit/Services/Helpers/TemporaryPasswordServiceTest.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/Unit/Services/Users/UserCreationServiceTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Illuminate\Contracts\Hashing\Hasher;
1010
use Illuminate\Database\ConnectionInterface;
1111
use Illuminate\Support\Facades\Notification;
12+
use Illuminate\Contracts\Auth\PasswordBroker;
1213
use Pterodactyl\Notifications\AccountCreated;
1314
use Pterodactyl\Services\Users\UserCreationService;
14-
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
1515
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1616

1717
class UserCreationServiceTest extends TestCase
@@ -29,9 +29,9 @@ class UserCreationServiceTest extends TestCase
2929
private $hasher;
3030

3131
/**
32-
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService|\Mockery\Mock
32+
* @var \Illuminate\Contracts\Auth\PasswordBroker|\Mockery\Mock
3333
*/
34-
private $passwordService;
34+
private $passwordBroker;
3535

3636
/**
3737
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
@@ -48,7 +48,7 @@ public function setUp()
4848
Notification::fake();
4949
$this->connection = m::mock(ConnectionInterface::class);
5050
$this->hasher = m::mock(Hasher::class);
51-
$this->passwordService = m::mock(TemporaryPasswordService::class);
51+
$this->passwordBroker = m::mock(PasswordBroker::class);
5252
$this->repository = m::mock(UserRepositoryInterface::class);
5353
}
5454

@@ -121,7 +121,7 @@ public function testUserIsCreatedWhenNoPasswordIsProvided()
121121
$this->hasher->shouldNotReceive('make');
122122
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
123123
$this->hasher->shouldReceive('make')->once()->andReturn('created-enc-password');
124-
$this->passwordService->shouldReceive('handle')->with($user->email)->once()->andReturn('random-token');
124+
$this->passwordBroker->shouldReceive('createToken')->with($user)->once()->andReturn('random-token');
125125

126126
$this->repository->shouldReceive('create')->with([
127127
'password' => 'created-enc-password',
@@ -152,6 +152,6 @@ public function testUserIsCreatedWhenNoPasswordIsProvided()
152152
*/
153153
private function getService(): UserCreationService
154154
{
155-
return new UserCreationService($this->connection, $this->hasher, $this->passwordService, $this->repository);
155+
return new UserCreationService($this->connection, $this->hasher, $this->passwordBroker, $this->repository);
156156
}
157157
}

0 commit comments

Comments
 (0)