mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
refactor profile module
This commit is contained in:
parent
08bc694186
commit
8851bae78f
@ -109,13 +109,6 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
->where('advs_advs.status', 'approved');
|
||||
}
|
||||
|
||||
public function myAdvsByUser()
|
||||
{
|
||||
return $this->userAdv()
|
||||
->where('advs_advs.status', 'approved')
|
||||
->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function foreignCurrency($currency, $price, $isUpdate, $settings)
|
||||
{
|
||||
$currencies = setting_value('visiosoft.module.advs::enabled_currencies');
|
||||
|
||||
@ -478,4 +478,11 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
|
||||
->where('advs_advs.status', 'approved')
|
||||
->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function myAdvsByUser()
|
||||
{
|
||||
return $this->model->userAdv()
|
||||
->where('advs_advs.status', 'approved')
|
||||
->where('advs_advs.finish_at', '>', date('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,4 +39,6 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
|
||||
public function extendAds($allAds, $isAdmin = false);
|
||||
|
||||
public function getByUsersIDs($usersIDs);
|
||||
|
||||
public function myAdvsByUser();
|
||||
}
|
||||
|
||||
@ -14,10 +14,8 @@ use Illuminate\Support\Facades\Cookie;
|
||||
use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface;
|
||||
use Visiosoft\LocationModule\City\CityRepository;
|
||||
use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface;
|
||||
use function PMA\Util\get;
|
||||
use Visiosoft\AdvsModule\Adv\AdvModel;
|
||||
use Visiosoft\AdvsModule\Adv\Event\priceChange;
|
||||
use Visiosoft\AdvsModule\Adv\Event\UpdateAd;
|
||||
use Visiosoft\AdvsModule\Adv\Event\viewAd;
|
||||
use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder;
|
||||
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||
|
||||
@ -27,7 +27,7 @@ function doneTyping(phoneNum) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
data: {'phoneNumber': countryCode + phoneNum.substr(1)},
|
||||
url: 'ajax/phone-validation',
|
||||
url: 'api/phone-validation',
|
||||
success: function (response) {
|
||||
if (response.userExists) {
|
||||
phoneInput.addClass('rejected-phone');
|
||||
|
||||
@ -25,10 +25,10 @@ $('.edit-this-address').on('click', function () {
|
||||
resetForm();
|
||||
|
||||
//Set Update Form Action
|
||||
$("#newAdd-address").attr("action", '/profile/adress/ajaxUpdate/' + edit_address_id);
|
||||
$("#newAdd-address").attr("action", '/profile/adress/ajax-update/' + edit_address_id);
|
||||
|
||||
//Get Address Detail
|
||||
crud({"id": edit_address_id}, '/profile/adress/ajaxDetail', 'POST', function (callback) {
|
||||
crud({"id": edit_address_id}, '/profile/adress/ajax-detail', 'POST', function (callback) {
|
||||
var address_detail = callback.data;
|
||||
var address_field = ['adress_name', 'adress_gsm_phone', 'adress_first_name', 'adress_last_name'];
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@
|
||||
{{ trans('visiosoft.module.profile::message.disable_account') }}
|
||||
</label>
|
||||
<button type="button" class="btn btn-danger"
|
||||
onclick="window.location.href='/profile/closeAccount'">
|
||||
onclick="window.location.href='/profile/close-account'">
|
||||
{{ trans("visiosoft.module.profile::field.disable_account.name") }}
|
||||
</button>
|
||||
|
||||
|
||||
@ -1,30 +1,9 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Adress;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Visiosoft\ProfileModule\Adress\Contract\AdressInterface;
|
||||
use Anomaly\Streams\Platform\Model\Profile\ProfileAdressEntryModel;
|
||||
|
||||
class AdressModel extends ProfileAdressEntryModel implements AdressInterface
|
||||
{
|
||||
public function getAdress($id = null) {
|
||||
if($id == null)
|
||||
{
|
||||
return AdressModel::query();
|
||||
}
|
||||
return AdressModel::query()->where('id',$id)->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function getAdressFirst($id) {
|
||||
return $this->getAdress($id)->first();
|
||||
}
|
||||
|
||||
public function getUserAdress($id = null)
|
||||
{
|
||||
if ($id != null) {
|
||||
return $this->query()->where('user_id',$id)->whereNull('deleted_at')->get();
|
||||
}
|
||||
return $this->query()->where('user_id', Auth::id())->whereNull('deleted_at')->get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -23,8 +23,10 @@ class AdressRepository extends EntryRepository implements AdressRepositoryInterf
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function findByUser($user_id)
|
||||
public function getUserAddresses($userId = null)
|
||||
{
|
||||
return $this->newQuery()->where('user_id', $user_id)->get();
|
||||
$userId = $userId ? $userId : \auth()->id();
|
||||
|
||||
return $this->findAllBy('user_id', $userId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,17 +7,17 @@ class GetAddressByUser
|
||||
{
|
||||
|
||||
/**
|
||||
* @var $id
|
||||
* @var $userId
|
||||
*/
|
||||
protected $id;
|
||||
protected $userId;
|
||||
|
||||
/**
|
||||
* GetProduct constructor.
|
||||
* @param $id
|
||||
* @param $userId
|
||||
*/
|
||||
public function __construct($id)
|
||||
public function __construct($userId)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26,8 +26,8 @@ class GetAddressByUser
|
||||
*/
|
||||
public function handle(AdressRepositoryInterface $adressRepository)
|
||||
{
|
||||
if ($this->id) {
|
||||
return $adressRepository->findByUser($this->id);
|
||||
if ($this->userId) {
|
||||
return $adressRepository->getUserAddresses($this->userId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -4,5 +4,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
|
||||
interface AdressRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function findByUser($user_id);
|
||||
|
||||
public function getUserAddresses($userId = null);
|
||||
}
|
||||
|
||||
@ -1,28 +1,22 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Http\Controller;
|
||||
|
||||
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
|
||||
use Anomaly\Streams\Platform\Model\Profile\ProfileAdressEntryModel;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\ProfileModule\Adress\AdressModel;
|
||||
use Visiosoft\ProfileModule\Adress\Form\AdressFormBuilder;
|
||||
use Visiosoft\ProfileModule\Adress\Table\AdressTableBuilder;
|
||||
use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
|
||||
class AddressController extends AdminController
|
||||
{
|
||||
private $address;
|
||||
|
||||
public function __construct(AdressModel $address)
|
||||
private $adressRepository;
|
||||
|
||||
public function __construct(AdressRepositoryInterface $adressRepository)
|
||||
{
|
||||
$this->address = $address;
|
||||
parent::__construct();
|
||||
$this->adressRepository = $adressRepository;
|
||||
}
|
||||
|
||||
public function index(AdressTableBuilder $table)
|
||||
public function index()
|
||||
{
|
||||
$address = $this->address->getUserAdress();
|
||||
$address = $this->adressRepository->getUserAddresses();
|
||||
return $this->view->make('visiosoft.module.profile::address/list', compact('address'));
|
||||
}
|
||||
|
||||
@ -39,9 +33,9 @@ class AddressController extends AdminController
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$address = $this->address->newQuery()->find($id);
|
||||
$address = $this->adressRepository->find($id);
|
||||
|
||||
if ($address->user_id == Auth::id()) {
|
||||
if ($address->user_id == \auth()->id()) {
|
||||
$address->delete();
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Http\Controller\Admin;
|
||||
|
||||
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
|
||||
use Anomaly\Streams\Platform\Model\Profile\ProfileAdressEntryModel;
|
||||
use Illuminate\Http\Request;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface;
|
||||
use Visiosoft\ProfileModule\Adress\Form\AdressFormBuilder;
|
||||
use Visiosoft\ProfileModule\Adress\Table\AdressTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
@ -11,6 +10,14 @@ use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
class AdressController extends AdminController
|
||||
{
|
||||
|
||||
private $adressRepository;
|
||||
|
||||
public function __construct(AdressRepositoryInterface $adressRepository)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->adressRepository = $adressRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an index of existing entries.
|
||||
*
|
||||
@ -42,46 +49,4 @@ class AdressController extends AdminController
|
||||
|
||||
return $form->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an existing entry.
|
||||
*
|
||||
* @param AdressFormBuilder $form
|
||||
* @param $id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function edit(AdressFormBuilder $form, $id)
|
||||
{
|
||||
$form->setOption('heading', "visiosoft.module.profile::field");
|
||||
|
||||
return $form->render($id);
|
||||
}
|
||||
|
||||
public function adresList(AdressTableBuilder $table, $id)
|
||||
{
|
||||
$table->setColumns(['adress_name','user']);
|
||||
$table->setButtons(['edit' => [
|
||||
'href' => '/admin/profile/adress/editAdress/{entry.id}',
|
||||
],]);
|
||||
return $table->render();
|
||||
}
|
||||
|
||||
public function adressUpdate(AdressFormBuilder $form,Request $request,$id)
|
||||
{
|
||||
$error = $form->build()->validate()->getFormErrors()->getMessages();
|
||||
if(!empty($error))
|
||||
{
|
||||
return $this->redirect->back();
|
||||
}
|
||||
$New_value = $request->all();
|
||||
unset($New_value['_token'],$New_value['action']);
|
||||
ProfileAdressEntryModel::find($id)->update($New_value);
|
||||
$message = [];
|
||||
$message[] = trans('visiosoft.module.profile::message.adress_success_update');
|
||||
if($request->get('action') == "save_create")
|
||||
{
|
||||
return redirect('admin/profile/adress/create')->with('success', $message);
|
||||
}
|
||||
return $this->redirect->back()->with('success', $message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,10 +5,11 @@ use Visiosoft\AddblockExtension\Command\addBlock;
|
||||
|
||||
class CacheController extends PublicController
|
||||
{
|
||||
|
||||
public function getUserInfo()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$user = $user ? $user->first_name . ' ' . $user->last_name : $user;
|
||||
$user = $user ? $user->name() : $user;
|
||||
|
||||
$getAddBlockHtml = new addBlock('navigation/dropdown', []);
|
||||
$addBlockHtml = $getAddBlockHtml->handle();
|
||||
|
||||
@ -1,226 +1,136 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Http\Controller;
|
||||
|
||||
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
|
||||
use Anomaly\Streams\Platform\Http\Controller\PublicController;
|
||||
use Anomaly\Streams\Platform\Model\Options\OptionsAdvertisementEntryModel;
|
||||
use Anomaly\Streams\Platform\Model\Users\UsersUsersEntryModel;
|
||||
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Rinvex\Subscriptions\Models\Plan;
|
||||
use Rinvex\Subscriptions\Models\PlanSubscription;
|
||||
use Visiosoft\AdvsModule\Adv\AdvModel;
|
||||
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Country\CountryModel;
|
||||
use Visiosoft\AlgoliaModule\Search\SearchModel;
|
||||
use Visiosoft\CloudsiteModule\CloudsiteModule;
|
||||
use Visiosoft\CloudsiteModule\Site\SiteModel;
|
||||
use Visiosoft\OrdersModule\Orderdetail\Event\AgainPuchaseOrder;
|
||||
use Visiosoft\PackagesModule\Http\Controller\PackageFEController;
|
||||
use Visiosoft\MessagesModule\Message\MessageModel;
|
||||
use Visiosoft\PackagesModule\Package\PackageModel;
|
||||
use Visiosoft\PackagesModule\User\UserModel;
|
||||
use Visiosoft\ProfileModule\Adress\AdressModel;
|
||||
use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface;
|
||||
use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface;
|
||||
use Visiosoft\ProfileModule\Adress\Form\AdressFormBuilder;
|
||||
use Visiosoft\ProfileModule\Profile\Form\ProfileFormBuilder;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class MyProfileController extends PublicController
|
||||
{
|
||||
private $adressRepository;
|
||||
private $userRepository;
|
||||
private $advRepository;
|
||||
private $countryRepository;
|
||||
|
||||
public function __construct(
|
||||
AdressRepositoryInterface $adressRepository,
|
||||
UserRepositoryInterface $userRepository
|
||||
UserRepositoryInterface $userRepository,
|
||||
AdvRepositoryInterface $advRepository,
|
||||
CountryRepositoryInterface $countryRepository
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
if (!Auth::user()) {
|
||||
redirect('/login?redirect=' . url()->current())->send();
|
||||
}
|
||||
|
||||
$this->adressRepository = $adressRepository;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->advRepository = $advRepository;
|
||||
$this->countryRepository = $countryRepository;
|
||||
}
|
||||
|
||||
protected $user;
|
||||
|
||||
public function home(ProfileFormBuilder $form, AdvRepositoryInterface $advRepository)
|
||||
public function home(ProfileFormBuilder $form)
|
||||
{
|
||||
$advs_count = new AdvModel();
|
||||
$advs_count = count($advs_count->myAdvsByUser()->get());
|
||||
$adsCount = count($this->advRepository->myAdvsByUser()->get());
|
||||
$user = $this->userRepository->find(\auth()->id());
|
||||
$country = $this->countryRepository->all();
|
||||
|
||||
$user = $this->userRepository->find(Auth::id());
|
||||
|
||||
$country = CountryModel::all();
|
||||
|
||||
return $this->view->make('visiosoft.module.profile::profile.detail',
|
||||
compact('user', 'country', 'form', 'advs_count'));
|
||||
return $this->view->make(
|
||||
'visiosoft.module.profile::profile.detail',
|
||||
compact('user', 'country', 'form', 'adsCount')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function extendAds($id, $type, SettingRepositoryInterface $settings)
|
||||
public function addressAjaxCreate(AdressFormBuilder $form)
|
||||
{
|
||||
$isActivePackages = new AdvModel();
|
||||
$isActivePackages = $isActivePackages->is_enabled('packages');
|
||||
|
||||
if ($isActivePackages) {
|
||||
|
||||
//Search Last Time Packages By User
|
||||
$TimePackages = new PackageFEController();
|
||||
$LastTimePackages = $TimePackages->getPackagesByUser('lasttime');
|
||||
|
||||
//no packages by user
|
||||
if ($LastTimePackages == false) {
|
||||
return response()->json(['success' => false, 'msg' => trans('visiosoft.module.profile::message.no_extend_package')]);
|
||||
}
|
||||
|
||||
//Search Time packages By id
|
||||
$TimePackages = $TimePackages->getTimePackages($LastTimePackages['package_id']);
|
||||
$adv = new AdvModel();
|
||||
$adv->finish_at_Ads($id, $TimePackages['time']);
|
||||
|
||||
// auto approved find
|
||||
$auto_approved = $settings->value('visiosoft.module.advs::auto_approve');
|
||||
if ($auto_approved == true) {
|
||||
$type = "approved";
|
||||
}
|
||||
$adv->statusAds($id, $type);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
} else {
|
||||
return response()->json(['success' => false, 'msg' => trans('visiosoft.module.profile::message.no_packages_module')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function statusAds($id, $type, Dispatcher $events, AdvModel $advModel)
|
||||
{
|
||||
$ad = $advModel->getAdv($id);
|
||||
$auto_approved = setting_value('visiosoft.module.advs::auto_approve');
|
||||
$default_published_time = setting_value('visiosoft.module.advs::default_published_time');
|
||||
|
||||
if ($auto_approved == true AND $type == 'pending_admin') {
|
||||
$type = "approved";
|
||||
}
|
||||
|
||||
if ($type == "approved") {
|
||||
$advModel->publish_at_Ads($id);
|
||||
if ($ad->finish_at == NULL AND $type == "approved") {
|
||||
if ($advModel->is_enabled('packages')) {
|
||||
$packageModel = new PackageModel();
|
||||
$published_time = $packageModel->reduceTimeLimit($ad->cat1);
|
||||
if ($published_time != null) {
|
||||
$default_published_time = $published_time;
|
||||
}
|
||||
}
|
||||
$advModel->finish_at_Ads($id, $default_published_time);
|
||||
}
|
||||
}
|
||||
$isActiveAlgolia = new AdvModel();
|
||||
$isActiveAlgolia = $isActiveAlgolia->is_enabled('algolia');
|
||||
if ($isActiveAlgolia) {
|
||||
$algolia = new SearchModel();
|
||||
$algolia->updateStatus($id, $type);
|
||||
}
|
||||
$status = $advModel->statusAds($id, $type);
|
||||
|
||||
return response()->json(['status' => $status]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function adressAjaxCreate(AdressFormBuilder $form, Request $request)
|
||||
{
|
||||
$message = [];
|
||||
|
||||
$error = $form->build()->validate()->getFormErrors()->getMessages();
|
||||
if (!empty($error)) {
|
||||
$message['status'] = "error";
|
||||
$message['msg'] = trans('visiosoft.module.profile::message.required_all');
|
||||
return $message;
|
||||
}
|
||||
$new_adress = $request->request->all();
|
||||
unset($new_adress['_token']);
|
||||
$new_adress['user_id'] = Auth::id();
|
||||
|
||||
$adressModel = new AdressModel();
|
||||
$address = $adressModel->getAdress()->create($new_adress);
|
||||
|
||||
$message['status'] = "success";
|
||||
$message['data'] = $address;
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function adressAjaxUpdate(AdressFormBuilder $form, $id)
|
||||
{
|
||||
$address = $this->adressRepository->find($id);
|
||||
if (isset($id) and $address != null and $address->user_id == Auth::id()) {
|
||||
$message = [];
|
||||
try {
|
||||
$error = $form->build()->validate()->getFormErrors()->getMessages();
|
||||
if (!empty($error)) {
|
||||
$message['status'] = "error";
|
||||
$message['msg'] = trans('visiosoft.module.profile::message.required_all');
|
||||
return $message;
|
||||
throw new \Exception(trans('visiosoft.module.profile::message.required_all'));
|
||||
}
|
||||
$new_adress = $this->request->all();
|
||||
unset($new_adress['_token']);
|
||||
|
||||
$address->update($new_adress);
|
||||
$new_address = \request()->all();
|
||||
$new_address['user_id'] = \auth()->id();
|
||||
unset($new_address['_token']);
|
||||
|
||||
$message['status'] = "updated";
|
||||
$message['data'] = $address;
|
||||
return $message;
|
||||
$address = $this->adressRepository->create($new_address);
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'data' => $address
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'msg' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
$message['status'] = "error";
|
||||
$message['msg'] = trans('visiosoft.module.profile::message.ajax_address_error');
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function adressAjaxDetail()
|
||||
public function addressAjaxUpdate(AdressFormBuilder $form, $id)
|
||||
{
|
||||
$address = $this->adressRepository->find($this->request->id);
|
||||
if (isset($this->request->id) and $address != null and $address->user_id == Auth::id()) {
|
||||
$message['status'] = "success";
|
||||
$message['data'] = $address;
|
||||
return $message;
|
||||
try {
|
||||
$address = $this->adressRepository->find($id);
|
||||
if ($address && $address->user_id == \auth()->id()) {
|
||||
$error = $form->build()->validate()->getFormErrors()->getMessages();
|
||||
if (!empty($error)) {
|
||||
throw new \Exception(trans('visiosoft.module.profile::message.required_all'));
|
||||
}
|
||||
|
||||
$new_adress = \request()->all();
|
||||
unset($new_adress['_token']);
|
||||
|
||||
$address->update($new_adress);
|
||||
|
||||
return [
|
||||
'status' => 'update',
|
||||
'data' => $address,
|
||||
];
|
||||
}
|
||||
|
||||
throw new \Exception(trans('visiosoft.module.profile::message.ajax_address_error'));
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'msg' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
$message['status'] = "error";
|
||||
$message['msg'] = trans('visiosoft.module.profile::message.ajax_address_error');
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
public function showMessage($id)
|
||||
public function addressAjaxDetail()
|
||||
{
|
||||
$message = new MessageModel();
|
||||
$message = $message->showMessage($id);
|
||||
$messageInfo = $message[0];
|
||||
$messageDetail = $message[1];
|
||||
|
||||
if ($message[0]->adv_user_id == auth()->id()) {
|
||||
return $this->view->make('visiosoft.module.profile::profile.message-detail', compact('messageInfo', 'messageDetail'));
|
||||
} else {
|
||||
abort(403);
|
||||
try {
|
||||
$address = $this->adressRepository->find(\request()->id);
|
||||
if ($address && $address->user_id == \auth()->id()) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'data' => $address,
|
||||
];
|
||||
} else {
|
||||
throw new \Exception(trans('visiosoft.module.profile::message.ajax_address_error'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'msg' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function disableAccount()
|
||||
{
|
||||
|
||||
UsersUsersEntryModel::query()->find(Auth::id())->update(['enabled' => 0]);
|
||||
Auth::logout();
|
||||
$this->userRepository->find(Auth::id())->update(['enabled' => 0]);
|
||||
\auth()->logout();
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
public function notification(Request $request)
|
||||
public function notification()
|
||||
{
|
||||
$all = $request->all();
|
||||
$all = \request()->all();
|
||||
unset($all['_']);
|
||||
$status = $this->userRepository->newQuery()->where('id', Auth::id())->update($all);
|
||||
return response()->json($status);
|
||||
$user = $this->userRepository->find(\auth()->id())->update($all);
|
||||
return response()->json($user);
|
||||
|
||||
}
|
||||
|
||||
@ -229,19 +139,19 @@ class MyProfileController extends PublicController
|
||||
return $this->view->make('visiosoft.module.profile::profile/ads');
|
||||
}
|
||||
|
||||
public function updateAjaxProfile(UserRepositoryInterface $user)
|
||||
public function updateAjaxProfile()
|
||||
{
|
||||
$profile = $user->find(Auth::id());
|
||||
if (isset($this->request->action) and $this->request->action == "update") {
|
||||
$profile = $this->userRepository->find(\auth()->id());
|
||||
if (isset(\request()->action) && \request()->action == "update") {
|
||||
$profile->update([
|
||||
'first_name' => $this->request->first_name,
|
||||
'last_name' => $this->request->last_name,
|
||||
'gsm_phone' => $this->request->gsm_phone,
|
||||
'office_phone' => $this->request->office_phone,
|
||||
'land_phone' => $this->request->land_phone,
|
||||
'first_name' => \request()->first_name,
|
||||
'last_name' => \request()->last_name,
|
||||
'gsm_phone' => \request()->gsm_phone,
|
||||
'office_phone' => \request()->office_phone,
|
||||
'land_phone' => \request()->land_phone,
|
||||
]);
|
||||
}
|
||||
return response()->json(['status' => 'success', 'data' => $profile]);
|
||||
return ['status' => 'success', 'data' => $profile];
|
||||
}
|
||||
|
||||
public function checkUser()
|
||||
|
||||
@ -1,29 +1,6 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Http\Controller;
|
||||
|
||||
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
|
||||
use Anomaly\Streams\Platform\Addon\Extension\ExtensionCollection;
|
||||
use Anomaly\UsersModule\User\Authenticator\Contract\AuthenticatorExtensionInterface;
|
||||
use Anomaly\UsersModule\User\Contract\UserInterface;
|
||||
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
|
||||
use Anomaly\UsersModule\User\Event\UserWasLoggedIn;
|
||||
use Anomaly\UsersModule\User\User;
|
||||
use Anomaly\UsersModule\User\UserPassword;
|
||||
use http\Env\Response;
|
||||
use Visiosoft\AdvsModule\Adv\AdvModel;
|
||||
use Visiosoft\AdvsModule\Http\Controller\AdvsController;
|
||||
use Visiosoft\CartsModule\Saleitem\Command\ProcessSaleitem;
|
||||
use Visiosoft\CartsModule\Saleitem\SaleitemModel;
|
||||
use Visiosoft\CloudsiteModule\Site\Event\CreateSite;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Visiosoft\CloudsiteModule\Site\SiteModel;
|
||||
use Visiosoft\ProfileModule\Profile\ProfileRepository;
|
||||
use Visiosoft\SubscriptionsModule\User\UserModel;
|
||||
|
||||
/**
|
||||
* Class UserAuthenticator
|
||||
@ -34,132 +11,18 @@ use Visiosoft\SubscriptionsModule\User\UserModel;
|
||||
*/
|
||||
class UserAuthenticator
|
||||
{
|
||||
protected $guard;
|
||||
protected $events;
|
||||
protected $container;
|
||||
protected $extensions;
|
||||
protected $settings;
|
||||
protected $advModel;
|
||||
|
||||
private $userRepository;
|
||||
|
||||
public function __construct(
|
||||
Guard $guard,
|
||||
Dispatcher $events,
|
||||
Container $container,
|
||||
ExtensionCollection $extensions,
|
||||
AdvModel $advModel,
|
||||
SettingRepositoryInterface $settings)
|
||||
public function __construct(UserRepositoryInterface $userRepository)
|
||||
{
|
||||
$this->guard = $guard;
|
||||
$this->events = $events;
|
||||
$this->container = $container;
|
||||
$this->extensions = $extensions;
|
||||
$this->advModel = $advModel;
|
||||
$this->settings = $settings;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to login a user.
|
||||
*
|
||||
* @param array $credentials
|
||||
* @param bool $remember
|
||||
* @return bool|UserInterface
|
||||
*/
|
||||
|
||||
function valid_email($email)
|
||||
public function phoneValidation()
|
||||
{
|
||||
return !!filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
|
||||
public function attempt(Request $request, $remember = false, ProfileRepository $profileRepository)
|
||||
{
|
||||
$credentials = $request->toArray();
|
||||
if ($credentials) {
|
||||
unset($credentials['_token'], $credentials['remember_me']);
|
||||
if (!$this->valid_email($credentials['email'])) {
|
||||
$credentials['username'] = $credentials['email'];
|
||||
unset($credentials['email']);
|
||||
$validation = $profileRepository->validPasswordByUsername($credentials['username']);
|
||||
} else {
|
||||
$validation = $profileRepository->validPasswordByEmail($credentials['email']);
|
||||
}
|
||||
if ($validation == "noUser") {
|
||||
return Redirect::back()->with('error', [trans('visiosoft.module.profile::message.login_error')]);
|
||||
}
|
||||
if ($validation == "reset") {
|
||||
return Redirect::back()->with('info', [trans('visiosoft.module.profile::message.login_info_old_user')]);
|
||||
}
|
||||
if ($validation == "noMail") {
|
||||
return Redirect::back()->with('info', [trans('visiosoft.module.profile::message.login_noMail_old_user')
|
||||
, trans('visiosoft.module.profile::message.login_noMail_old_user2'), trans('visiosoft.module.profile::message.login_noMail_old_user3')]);
|
||||
}
|
||||
if (isset($credentials['username'])) {
|
||||
$profile = $profileRepository->findProfileForLogin('gsm_phone', $credentials['username']);
|
||||
if ($profile != null) {
|
||||
$find_user = $profileRepository->findUserForLogin('id', $profile->user_id);
|
||||
$credentials['username'] = $find_user->username;
|
||||
}
|
||||
}
|
||||
if ($response = $this->authenticate($credentials)) {
|
||||
if ($response instanceof UserInterface) {
|
||||
$this->login($response, $remember);
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Redirect::back()->with('error', [trans('visiosoft.module.profile::message.login_error')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the credentials.
|
||||
*
|
||||
* @param array $credentials
|
||||
* @return bool|UserInterface
|
||||
*/
|
||||
public function authenticate(array $credentials)
|
||||
{
|
||||
$authenticators = $this->extensions
|
||||
->search('anomaly.module.users::authenticator.*')
|
||||
->enabled();
|
||||
|
||||
/* @var AuthenticatorExtensionInterface $authenticator */
|
||||
foreach ($authenticators as $authenticator) {
|
||||
|
||||
$response = $authenticator->authenticate($credentials);
|
||||
|
||||
if ($response instanceof UserInterface) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($response instanceof RedirectResponse) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force login a user.
|
||||
*
|
||||
* @param UserInterface $user
|
||||
* @param bool $remember
|
||||
*/
|
||||
public function login(UserInterface $user, $remember = false)
|
||||
{
|
||||
$this->guard->login($user, $remember);
|
||||
|
||||
$this->events->dispatch(new UserWasLoggedIn($user));
|
||||
}
|
||||
|
||||
public function phoneValidation(Request $request, UserRepositoryInterface $userRepository)
|
||||
{
|
||||
$phoneNum = str_replace(' ', '', $request->phoneNumber);
|
||||
$userExists = $userRepository->findBy('gsm_phone', $phoneNum);
|
||||
if ($userExists) {
|
||||
return response()->json(['userExists' => true]);
|
||||
} else {
|
||||
return response()->json(['userExists' => false]);
|
||||
}
|
||||
$phoneNum = str_replace(' ', '', request()->phoneNumber);
|
||||
$userExists = $this->userRepository->findBy('gsm_phone', $phoneNum);
|
||||
return $userExists ? ['userExists' => true] : ['userExists' => false];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,32 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Visiosoft\ProfileModule\Http\Middleware;
|
||||
<?php namespace Visiosoft\ProfileModule\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class authCheck
|
||||
{
|
||||
|
||||
private $auth;
|
||||
private $request;
|
||||
|
||||
public function __construct(Guard $auth,Request $request)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Guard $auth
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if ($this->auth->check()) {
|
||||
return redirect($this->request->get('redirect', '/'));
|
||||
if (auth()->check()) {
|
||||
return redirect($request->get('redirect', '/'));
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,42 +59,82 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
|
||||
* @type array|null
|
||||
*/
|
||||
protected $routes = [
|
||||
/* Ads */
|
||||
// Admin AdressController
|
||||
'admin/profile' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@index',
|
||||
'admin/profile/create' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@create',
|
||||
|
||||
// Admin UsersController
|
||||
'admin/users/export' => [
|
||||
'as' => 'users::exportUsers',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\Admin\UsersController@exportUsers'
|
||||
],
|
||||
|
||||
// UserAuthenticator
|
||||
'api/phone-validation' => 'Visiosoft\ProfileModule\Http\Controller\UserAuthenticator@phoneValidation',
|
||||
|
||||
// MyProfileController
|
||||
'check-user' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@checkUser'
|
||||
],
|
||||
'ajax/update-user-info' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@updateAjaxProfile'
|
||||
],
|
||||
'profile/notification' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@notification'
|
||||
],
|
||||
'profile/close-account' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@disableAccount'
|
||||
],
|
||||
'profile/adress/ajax-detail' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@addressAjaxDetail'
|
||||
],
|
||||
'profile/adress/ajax-update/{id}' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@addressAjaxUpdate'
|
||||
],
|
||||
'profile/ads' => [
|
||||
'middleware' => 'auth',
|
||||
'as' => 'profile::ads',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@myAds'
|
||||
],
|
||||
|
||||
/*Address */
|
||||
'admin/profile' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@index',
|
||||
'admin/profile/create' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@create',
|
||||
'admin/profile/edit/{id}' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@adresList',
|
||||
'admin/profile/editAdress/{id}' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@edit',
|
||||
'admin/profile/update/{id}' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@adressupdate',
|
||||
'profile/adress/update/{id}' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@adressUpdate',
|
||||
|
||||
'profile/adress/ajaxCreate' => [
|
||||
'profile/address/ajax-create' => [
|
||||
'middleware' => 'auth',
|
||||
'as' => 'visiosoft.module.profile::adress_ajax_create',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@adressAjaxCreate'
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@addressAjaxCreate'
|
||||
],
|
||||
'profile/adress/ajaxUpdate/{id}' => [
|
||||
'as' => 'visiosoft.module.profile::adress_ajax_update',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@adressAjaxUpdate'
|
||||
],
|
||||
'profile/adress/ajaxDetail' => [
|
||||
'as' => 'visiosoft.module.profile::adress_ajax_detail',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@adressAjaxDetail'
|
||||
],
|
||||
|
||||
/* Profile */
|
||||
'profile/edit' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@edit',
|
||||
'profile/update' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@update',
|
||||
'profile' => [
|
||||
'middleware' => 'auth',
|
||||
'as' => 'profile::profile',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@home'
|
||||
],
|
||||
'ajax/phone-validation' => 'Visiosoft\ProfileModule\Http\Controller\UserAuthenticator@phoneValidation',
|
||||
|
||||
// AddressController
|
||||
'profile/adress/delete/{id}' => [
|
||||
'as' => 'visiosoft.module.profile::address_soft_delete',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@delete'
|
||||
],
|
||||
'profile/adress/edit/{id}' => [
|
||||
'as' => 'visiosoft.module.profile::address_edit',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@edit'
|
||||
],
|
||||
'profile/adress/create' => [
|
||||
'as' => 'visiosoft.module.profile::adress_create',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@create'
|
||||
],
|
||||
'profile/address' => [
|
||||
'as' => 'profile::address',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@index',
|
||||
],
|
||||
|
||||
// CacheController
|
||||
'ajax/get-user-info' => 'Visiosoft\ProfileModule\Http\Controller\CacheController@getUserInfo',
|
||||
|
||||
// Others
|
||||
'register' => [
|
||||
'middleware' => [
|
||||
authCheck::class
|
||||
@ -103,49 +143,6 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
|
||||
'as' => 'anomaly.module.users::register',
|
||||
'uses' => 'Anomaly\UsersModule\Http\Controller\RegisterController@register',
|
||||
],
|
||||
|
||||
/* Login */
|
||||
'login-in' => 'Visiosoft\ProfileModule\Http\Controller\UserAuthenticator@attempt',
|
||||
|
||||
|
||||
'profile/class/status/{id},{type}' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@statusAds',
|
||||
'profile/class/extendTime/{id},{type}' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@extendAds',
|
||||
'profile/message/show/{id}' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@showMessage',
|
||||
'profile/closeAccount' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@disableAccount',
|
||||
'profile/notification' => [
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@notification',
|
||||
],
|
||||
|
||||
'ajax/update-user-info' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@updateAjaxProfile',
|
||||
|
||||
|
||||
//Address
|
||||
'profile/address' => [
|
||||
'as' => 'profile::address',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@index',
|
||||
],
|
||||
'profile/adress/create' => [
|
||||
'as' => 'visiosoft.module.profile::adress_create',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@create'
|
||||
],
|
||||
'profile/adress/edit/{id}' => [
|
||||
'as' => 'visiosoft.module.profile::address_edit',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@edit'
|
||||
],
|
||||
'profile/adress/delete/{id}' => [
|
||||
'as' => 'visiosoft.module.profile::address_soft_delete',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@delete'
|
||||
],
|
||||
'admin/users/export' => [
|
||||
'as' => 'users::exportUsers',
|
||||
'uses' => 'Visiosoft\ProfileModule\Http\Controller\Admin\UsersController@exportUsers'
|
||||
],
|
||||
|
||||
|
||||
// Cache links
|
||||
'ajax/get-user-info' => 'Visiosoft\ProfileModule\Http\Controller\CacheController@getUserInfo',
|
||||
|
||||
'check-user' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@checkUser',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user