2018-11-21 06:29:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\API\Http\Controllers\Customer;
|
|
|
|
|
|
|
|
|
|
use Webkul\API\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
use Auth;
|
|
|
|
|
use Cart;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Customer controller for the APIs of Profile customer
|
|
|
|
|
*
|
|
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class CustomerController extends Controller
|
|
|
|
|
{
|
|
|
|
|
protected $customer;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
if(auth()->guard('customer')->check()) {
|
|
|
|
|
$this->customer = auth()->guard('customer')->user();
|
|
|
|
|
} else {
|
2018-11-22 12:43:03 +00:00
|
|
|
$this->customer = 'unauthorized';
|
2018-11-21 06:29:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To get the details of user to display on profile
|
|
|
|
|
*
|
|
|
|
|
* @return response JSON
|
|
|
|
|
*/
|
|
|
|
|
public function getProfile() {
|
2018-11-22 12:43:03 +00:00
|
|
|
if($this->customer == 'unauthorized') {
|
|
|
|
|
return response()->json($this->customer, 401);
|
|
|
|
|
} else {
|
|
|
|
|
$customer = [
|
|
|
|
|
'id' => $this->customer->id,
|
|
|
|
|
'first_name' => $this->customer->first_name,
|
|
|
|
|
'last_name' => $this->customer->last_name,
|
|
|
|
|
'gender' => $this->customer->gender,
|
|
|
|
|
'date_of_birth' => $this->customer->date_of_birth,
|
|
|
|
|
'email' => $this->customer->email,
|
|
|
|
|
'subscribed_to_news_letter' => $this->customer->subscribed_to_news_letter,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json($customer, 200);
|
2018-11-21 06:29:18 +00:00
|
|
|
}
|
|
|
|
|
}
|