Files
UNIT3D-Community-Edition/app/Http/Controllers/Auth/ResetPasswordController.php
2022-01-07 23:35:33 -05:00

52 lines
1.5 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\Group;
use App\Models\UserActivation;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Str;
class ResetPasswordController extends Controller
{
use ResetsPasswords;
protected string $redirectTo = '/';
public function __construct()
{
$this->middleware('guest');
}
protected function resetPassword($user, $password): void
{
$validatingGroup = \cache()->rememberForever('validating_group', fn () => Group::where('slug', '=', 'validating')->pluck('id'));
$memberGroup = \cache()->rememberForever('member_group', fn () => Group::where('slug', '=', 'user')->pluck('id'));
$user->password = \bcrypt($password);
$user->remember_token = Str::random(60);
if ($user->group_id === $validatingGroup[0]) {
$user->group_id = $memberGroup[0];
}
$user->active = true;
$user->save();
UserActivation::where('user_id', '=', $user->id)->delete();
$this->guard()->login($user);
}
}