SingleSignOnController::sso()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 14
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 27
rs 9.7998
1
<?php
2
3
namespace Dynamic\Foxy\SingleSignOn\Controller;
4
5
use Dynamic\Foxy\Model\FoxyHelper;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Security\Member;
8
use SilverStripe\Security\Security;
9
10
/**
11
 * Class SingleSignOnController
12
 * @package Dynamic\Foxy\SingleSignOn\Controller
13
 */
14
class SingleSignOnController extends Controller
15
{
16
    /**
17
     * @var array
18
     */
19
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
20
        '' => 'sso',
21
    ];
22
23
    /**
24
     * @var array
25
     */
26
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
27
        'sso',
28
    ];
29
30
    /**
31
     * @param $request
32
     */
33
    public function sso($request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
    public function sso(/** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        // GET variables from FoxyCart Request
36
        $fcsid = $this->request->getVar('fcsid');
37
        $timestampNew = strtotime('+30 days');
38
        $helper = FoxyHelper::create();
39
40
        // get current member if logged in. If not, create a 'fake' user with Customer_ID = 0
41
        // fake user will redirect to FC checkout, ask customer to log in
42
        // to do: consider a login/registration form here if not logged in
43
        if (!$Member = Security::getCurrentUser()) {
44
            $Member = new Member();
45
            $Member->Customer_ID = 0;
46
        }
47
48
        $auth_token = sha1($Member->Customer_ID . '|' . $timestampNew . '|' . $helper->getStoreSecret());
49
50
        $params = [
51
            'fc_auth_token' => $auth_token,
52
            'fcsid' => $fcsid,
53
            'fc_customer_id' => $Member->Customer_ID,
54
            'timestamp' => $timestampNew,
55
        ];
56
57
        $httpQuery = http_build_query($params);
58
59
        $this->redirect("{$helper::StoreURL()}/checkout?$httpQuery");
60
    }
61
}
62