113 lines
3.1 KiB
PHP
113 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Backend\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\ChangePassword\ChangePasswordRequest;
|
|
use App\Repositories\Backend\Auth\ChangePasswordService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\View\View;
|
|
|
|
class AccountSettingController extends Controller
|
|
{
|
|
/**
|
|
* @var ChangePasswordService
|
|
*/
|
|
protected $changePasswordService;
|
|
|
|
/**
|
|
* AccountSettingController constructor.
|
|
*
|
|
* @param ChangePasswordService $changePasswordService
|
|
*/
|
|
public function __construct(ChangePasswordService $changePasswordService)
|
|
{
|
|
$this->changePasswordService = $changePasswordService;
|
|
}
|
|
|
|
/**
|
|
* @param string $currentTab
|
|
*
|
|
* @return View
|
|
*/
|
|
protected function accountSetting(string $currentTab = 'change-currency')
|
|
{
|
|
try {
|
|
$user = loggedInUser();
|
|
$allowedCompanyUsersPermission = loggedInUser()->hasRole('admin-user') ? true : false;
|
|
|
|
if(!$allowedCompanyUsersPermission) {
|
|
if ($currentTab == 'change-currency' || $currentTab == 'api') {
|
|
$currentTab = 'change-email';
|
|
}
|
|
}
|
|
|
|
return view('backend.auth.account_setting.account_setting', [
|
|
'current_tab' => $currentTab,
|
|
'allowed_company_users_permission' => $allowedCompanyUsersPermission,
|
|
]);
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param ChangePasswordRequest $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
protected function updatePassword(ChangePasswordRequest $request)
|
|
{
|
|
try {
|
|
$data = $request->all();
|
|
$response = $this->changePasswordService->updatePassword($data);
|
|
|
|
if ($response['status']) {
|
|
return redirect(route('admin.account-setting.index',['change-password']))->withFlashSuccess($response['message']);
|
|
} else {
|
|
return redirect()->back()->withInput($data)->withFlashError($response['message']);
|
|
}
|
|
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param ChangePasswordRequest $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
protected function checkEmailAddress(Request $request)
|
|
{
|
|
try {
|
|
$data = $request->all();
|
|
return $this->updateEmailService->checkEmailAddress($data);
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
protected function updateEmailAddress(Request $request)
|
|
{
|
|
try {
|
|
$data = $request->all();
|
|
$response = $this->updateEmailService->updateEmailAddress($data);
|
|
|
|
if ($response['status']) {
|
|
return redirect()->back()->withFlashSuccess($response['message']);
|
|
} else {
|
|
return redirect()->back()->withInput($data)->withFlashError($response['message']);
|
|
}
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
}
|
|
}
|
|
}
|