Skip to content

Commit 7a15cea

Browse files
authored
BUGFIX single sign on issues (#373)
* UPDATE order processing and SSO * BUGFIX broken feed parsing * NEW bcrypt encryption * UPDATE PHPCS fix
1 parent fa5fd48 commit 7a15cea

File tree

12 files changed

+714
-380
lines changed

12 files changed

+714
-380
lines changed

_config/config.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ Name: foxystripeconfig
44
SilverStripe\Security\Member:
55
extensions:
66
- Dynamic\FoxyStripe\ORM\CustomerExtension
7+
customer_map:
8+
int:
9+
customer_id: 'Customer_ID'
10+
string:
11+
customer_first_name: 'FirstName'
12+
customer_last_name: 'Surname'
13+
customer_email: 'Email'
14+
customer_password: 'Password'
15+
customer_password_salt: 'Salt'
16+
customer_password_hash_type: 'PasswordEncryption'
717

818
PageController:
919
extensions:
@@ -16,4 +26,12 @@ SilverStripe\Forms\FormField:
1626
SilverStripe\Core\Injector\Injector:
1727
TimeZoneData:
1828
properties:
19-
format: '%Region/%Name'
29+
format: '%Region/%Name'
30+
31+
SilverStripe\Security\Security:
32+
password_encryption_algorithm: 'bcrypt'
33+
34+
'SilverStripe\Security\PasswordEncryptor':
35+
encryptors:
36+
bcrypt:
37+
'Dynamic\FoxyStripe\Security\PasswordEncryptor_BCrypt':

src/API/Client/CustomerClient.php

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
namespace Dynamic\FoxyStripe\API\Client;
4+
5+
use Dynamic\FoxyStripe\Model\FoxyStripeClient;
6+
use Foxy\FoxyClient\FoxyClient;
7+
use SilverStripe\Core\Config\Configurable;
8+
use SilverStripe\Core\Extensible;
9+
use SilverStripe\Core\Injector\Injectable;
10+
use SilverStripe\Security\Member;
11+
12+
/**
13+
* Class CustomerClient
14+
* @package Dynamic\FoxyStripe\API\Client
15+
*/
16+
class CustomerClient extends FoxyStripeClient
17+
{
18+
use Configurable;
19+
use Extensible;
20+
use Injectable;
21+
22+
/**
23+
* @var array
24+
*/
25+
private static $customer_map = [
26+
'Customer_ID' => 'id',
27+
'FirstName' => 'first_name',
28+
'Surname' => 'last_name',
29+
'Email' => 'email',
30+
'Salt' => 'password_salt',
31+
'Password' => 'password_hash',
32+
];
33+
34+
/**
35+
* @var string
36+
*/
37+
private static $foxy_password_hash_type = 'bcrypt';
38+
39+
/**
40+
* @var Member
41+
*/
42+
private $customer;
43+
44+
/**
45+
* CustomerClient constructor.
46+
*/
47+
public function __construct(Member $customer)
48+
{
49+
parent::__construct();
50+
51+
$this->setCustomer($customer);
52+
}
53+
54+
/**
55+
* @param $customer
56+
* @return $this
57+
*/
58+
public function setCustomer($customer)
59+
{
60+
$this->customer = $customer;
61+
62+
return $this;
63+
}
64+
65+
/**
66+
* @return Member
67+
*/
68+
public function getCustomer()
69+
{
70+
return $this->customer;
71+
}
72+
73+
/**
74+
* @return string
75+
*/
76+
private function getAPIURI($single = false)
77+
{
78+
$parts = [FoxyClient::PRODUCTION_API_HOME, 'customers'];
79+
80+
if ($single) {
81+
$parts[] = $this->getCustomer()->Customer_ID;
82+
}
83+
84+
return implode('/', $parts);
85+
}
86+
87+
private function getNewCustomerAPIURI()
88+
{
89+
return implode('/', [$this->getCurrentStore(), 'customers']);
90+
}
91+
92+
/**
93+
* @return mixed
94+
*/
95+
public function putCustomer()
96+
{
97+
$data = $this->getSendData();
98+
$client = $this->getClient();
99+
100+
if (!$this->getCustomer()->Customer_ID) {
101+
$response = $client->post($this->getNewCustomerAPIURI(), $this->getSendData());
102+
} else {
103+
$response = $client->patch($this->getAPIURI(true), $this->getSendData());
104+
}
105+
106+
return $response;
107+
}
108+
109+
/**
110+
* @return mixed
111+
*/
112+
public function fetchCustomer()
113+
{
114+
$client = $this->getClient();
115+
116+
$result = $client->get($this->getAPIURI(true));
117+
118+
return $result;
119+
}
120+
121+
/**
122+
* @return mixed
123+
*/
124+
public function fetchCustomers()
125+
{
126+
$client = $this->getClient();
127+
128+
$result = $client->get($this->getAPIURI(true));
129+
130+
return $result;
131+
}
132+
133+
/**
134+
*
135+
*/
136+
public function deleteCustomer()
137+
{
138+
}
139+
140+
/**
141+
* @return array
142+
*/
143+
protected function getSendData()
144+
{
145+
$data = [];
146+
147+
if ($customer = $this->getCustomer()) {
148+
foreach ($this->config()->get('customer_map') as $localField => $remoteField) {
149+
if ($customer->{$localField}) {
150+
$data[$remoteField] = $customer->{$localField};
151+
}
152+
}
153+
}
154+
155+
return $data;
156+
}
157+
}

src/Admin/FoxyStripeAdmin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function save_foxystripe_setting($data, $form)
154154
try {
155155
$config->write();
156156
} catch (ValidationException $ex) {
157-
$form->sessionMessage($ex->getResult()->message(), 'bad');
157+
//$form->sessionMessage($ex->getResult()->getMessages(), 'bad');
158158

159159
return $this->getResponseNegotiator()->respond($this->request);
160160
}

0 commit comments

Comments
 (0)