33namespace Pterodactyl \Http \Controllers \Base ;
44
55use Pterodactyl \Models \User ;
6+ use Illuminate \Auth \AuthManager ;
67use Prologue \Alerts \AlertsMessageBag ;
8+ use Illuminate \Contracts \Session \Session ;
79use Pterodactyl \Http \Controllers \Controller ;
810use Pterodactyl \Services \Users \UserUpdateService ;
911use Pterodactyl \Http \Requests \Base \AccountDataFormRequest ;
@@ -15,6 +17,11 @@ class AccountController extends Controller
1517 */
1618 protected $ alert ;
1719
20+ /**
21+ * @var \Illuminate\Auth\SessionGuard
22+ */
23+ protected $ sessionGuard ;
24+
1825 /**
1926 * @var \Pterodactyl\Services\Users\UserUpdateService
2027 */
@@ -24,12 +31,14 @@ class AccountController extends Controller
2431 * AccountController constructor.
2532 *
2633 * @param \Prologue\Alerts\AlertsMessageBag $alert
34+ * @param \Illuminate\Auth\AuthManager $authManager
2735 * @param \Pterodactyl\Services\Users\UserUpdateService $updateService
2836 */
29- public function __construct (AlertsMessageBag $ alert , UserUpdateService $ updateService )
37+ public function __construct (AlertsMessageBag $ alert , AuthManager $ authManager , UserUpdateService $ updateService )
3038 {
3139 $ this ->alert = $ alert ;
3240 $ this ->updateService = $ updateService ;
41+ $ this ->sessionGuard = $ authManager ->guard ();
3342 }
3443
3544 /**
@@ -50,21 +59,26 @@ public function index()
5059 *
5160 * @throws \Pterodactyl\Exceptions\Model\DataValidationException
5261 * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
53- * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
5462 */
5563 public function update (AccountDataFormRequest $ request )
5664 {
57- $ data = [];
65+ // Prevent logging this specific session out when the password is changed. This will
66+ // automatically update the user's password anyways, so no need to do anything else here.
5867 if ($ request ->input ('do_action ' ) === 'password ' ) {
59- $ data ['password ' ] = $ request ->input ('new_password ' );
60- } elseif ($ request ->input ('do_action ' ) === 'email ' ) {
61- $ data ['email ' ] = $ request ->input ('new_email ' );
62- } elseif ($ request ->input ('do_action ' ) === 'identity ' ) {
63- $ data = $ request ->only (['name_first ' , 'name_last ' , 'username ' ]);
68+ $ this ->sessionGuard ->logoutOtherDevices ($ request ->input ('new_password ' ));
69+ } else {
70+ if ($ request ->input ('do_action ' ) === 'email ' ) {
71+ $ data = ['email ' => $ request ->input ('new_email ' )];
72+ } elseif ($ request ->input ('do_action ' ) === 'identity ' ) {
73+ $ data = $ request ->only (['name_first ' , 'name_last ' , 'username ' ]);
74+ } else {
75+ $ data = [];
76+ }
77+
78+ $ this ->updateService ->setUserLevel (User::USER_LEVEL_USER );
79+ $ this ->updateService ->handle ($ request ->user (), $ data );
6480 }
6581
66- $ this ->updateService ->setUserLevel (User::USER_LEVEL_USER );
67- $ this ->updateService ->handle ($ request ->user (), $ data );
6882 $ this ->alert ->success (trans ('base.account.details_updated ' ))->flash ();
6983
7084 return redirect ()->route ('account ' );
0 commit comments