SignUpForm::getFormActions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace UserManagement\Forms;
3
4
use SilverStripe\Forms\FieldList;
5
use SilverStripe\Forms\Form;
6
use SilverStripe\Forms\EmailField;
7
use SilverStripe\Forms\DateField;
8
use SilverStripe\Forms\FormAction;
9
use SilverStripe\Forms\TextField;
10
use SilverStripe\Security\Member;
11
use SilverStripe\SiteConfig\SiteConfig;
12
use SilverStripe\Control\Controller;
13
use SilverStripe\Forms\OptionsetField;
14
use SilverStripe\Forms\ConfirmedPasswordField;
15
use SilverStripe\Security\Security;
16
use SilverStripe\Security\RequestAuthenticationHandler;
17
use SilverStripe\Core\Injector\Injector;
18
use SilverStripe\Security\IdentityStore;
19
20
/**
21
 * Class SignUpForm
22
 *
23
 * @package user-management
24
 */
25
class SignUpForm extends Form
26
{
27
28
    protected $siteConfig;
29
    
30
    /**
31
     * Constructor
32
     */
33 4
    public function __construct($controller, $name)
34
    {
35 4
        $this->setsiteConfig();
36 4
        $this->setAttribute('id', 'SignUpForm');
37 4
        parent::__construct($controller, $name, $this->getFormFields($controller), $this->getFormActions());
38
    }
39
    
40
    /**
41
     * Form action, Register user and redirect to the call
42
     * back url with auto login.
43
     * @param array $data
44
     * @param \SilverStripe\Forms\Form $form
45
     *
46
     */
47 1
    public function doSubmit($data, Form $form)
48
    {
49
       
50
        
51 1
            $signUpPersonal = Member::create();
52 1
            $form->saveInto($signUpPersonal);
53 1
        if (isset($data['DOB']) && $data['DOB']) {
54
                $signUpPersonal->DOB = date('Y-m-d', strtotime($data['DOB']));
55
        }
56 1
            $signUpPersonal->write();
57 1
            $Member = Member::get()->byId($signUpPersonal->ID);
58 1
            $assignGroup = $signUpPersonal->Groups();
59 1
            $assignGroup->add($this->siteConfig->CustomerGroup());
60 1
            Injector::inst()->get(IdentityStore::class)->logIn($Member);
61
            //TO DO
62
            //$this->sessionMessage('Profile Created!', 'good');
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63 1
            return $this->controller->redirect($this->siteConfig->LoginCallBackUrl()->URLSegment); #TODO
64
    }
65
66
67
        /**
68
         * @param Controller $controller the controller instance that
69
         * is being passed to the form
70
         * @return FieldList Fields for this form.
71
         */
72 4
    protected function getFormFields($controller = null)
73
    {
74 4
        $fields = FieldList::create(
75 4
            TextField::create("FirstName", "FirstName"),
76 4
            TextField::create("Surname", "Surname"),
77 4
            TextField::create("NickName", "NickName"),
78 4
            DateField::create("DOB", "DOB"),
79 4
            ConfirmedPasswordField::create("Password", "Password"),
80 4
            EmailField::create("Email", "Email"),
81 4
            TextField::create("Mobile", "Mobile"),
82 4
            TextField::create("SecurityQuestion", "SecurityQuestion"),
83 4
            TextField::create("SecurityAnswer", "SecurityAnswer")
84
        );
85
        // Update the fields using updateSignUpForm
86 4
        $this->extend('updateSignUpForm', $fields);
87 4
        return $fields;
88
    }
89
90
    /**
91
     * @return FieldList Actions for this form.
92
     */
93 2
    protected function getFormActions()
94
    {
95 2
        return FieldList::create(
96 2
            FormAction::create("doSubmit", "Submit")
97
        );
98
    }
99
100
    /**
101
     * Assign siteconfig object
102
     */
103 2
    protected function setsiteConfig()
104
    {
105 2
        $this->siteConfig = SiteConfig::current_site_config();
106
    }
107
}
108