Files
UNIT3D-Community-Edition/app/Http/Controllers/Auth/ResetPasswordController.php
2019-03-13 11:26:20 -04:00

56 lines
1.5 KiB
PHP
Executable File

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