api code global jain
This commit is contained in:
44
app/Repositories/Backend/Auth/ChangePasswordService.php
Normal file
44
app/Repositories/Backend/Auth/ChangePasswordService.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Backend\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\BaseService;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ChangePasswordService extends BaseService
|
||||
{
|
||||
/**
|
||||
* Associated Repository Model.
|
||||
*/
|
||||
const MODEL = User::class;
|
||||
|
||||
public function updatePassword(array $request): array
|
||||
{
|
||||
$response = [
|
||||
'status' => static::STATUS_FALSE,
|
||||
'message' => 'Something went wrong,'
|
||||
];
|
||||
|
||||
try {
|
||||
$object = loggedInUser();
|
||||
|
||||
if (Hash::check($request['current_password'], $object->password)) {
|
||||
$object->password = Hash::make($request['new_password']);
|
||||
|
||||
if ($object->save()) {
|
||||
$response['status'] = static::STATUS_TRUE;
|
||||
$response['message'] = trans('account_setting.validate.change_password.message_1');
|
||||
}
|
||||
} else {
|
||||
$response['message'] = trans('account_setting.validate.change_password.message_2');
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user