Completed
Push — master ( 5d7f0a...75aa15 )
by Angus
07:35
created

Signup::_no_more_signup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php defined('BASEPATH') or exit('No direct script access allowed');
2
3
class Signup extends No_Auth_Controller {
4 9 View Code Duplication
	public function __construct() {
5 9
		parent::__construct();
6
7 8
		$this->load->library('form_validation');
8 8
		$this->form_validation->set_error_delimiters(
9 8
			$this->config->item('error_start_delimiter', 'ion_auth'),
10 8
			$this->config->item('error_end_delimiter', 'ion_auth')
11
		);
12
13 8
		$this->load->model('Auth_Model', 'Auth');
14 8
	}
15
16
	//Signup is done in multiple parts.
17
	// 1. User visits user/signup, inputs email. Site checks if email is new, and if so, sends verify email to said address.
18
	//        Page now shows a continuation code box + a note saying you can also click link in email.
19
	// 2. User clicks link in email, is now taken to proper sign-up page. We now know the email is valid.
20
	//        Signup continues like normal.
21
22 8
	public function index($verificationCode = NULL) : void {
0 ignored issues
show
Unused Code introduced by
The parameter $verificationCode is not used and could be removed.

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

Loading history...
23 8
		$this->header_data['title'] = 'Signup';
24 8
		$this->header_data['page']  = 'signup';
25
26 8
		$this->_no_more_signup();
27 4
		//if(is_null($verificationCode)) {
28
		//	$this->_initial_signup();
29 4
		//} else {
30
		//	$this->_continue_signup($verificationCode);
31 6
		//}
32
	}
33
34 4
	//This initial signup occurs when the user is first shown the page.
35
	private function _initial_signup() : void {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
36
		//user is provided with an email form
37
		//user enters email, submits, email is sent to verify it exists and to continue setup.
38 4
39 4
		$this->form_validation->set_rules('email', 'Email:', 'trim|required|valid_email|is_unique_email', array(
40
			'required'        => 'Email field is empty.',
41
			'valid_email'     => 'Email is an invalid format',
42
			'is_unique_email' => 'Email already exists.'
43
		));
44 4
45 2
		if ($isValid = ($this->form_validation->run() === TRUE)) {
46
			$email = $this->Auth->parseEmail($this->input->post('email'));
47 2
48 2
			$this->body_data['email'] = $email;
49 1
			if($this->Auth->verificationStart($email)) {
50
				$this->_render_page('User/Signup_Verification');
51 1
			} else {
52 1
				$this->session->set_flashdata('notices', 'Signup failed?');
53
				$isValid = FALSE;
54
			}
55
		}
56
57 4
		//login wasn't valid, failed, or this is a fresh login attempt
58 View Code Duplication
		if(!$isValid){
59 3
			//display the email validation form
60
			$this->body_data['form_email'] = array(
61
					'name'        => 'email',
62
					'id'          => 'email',
63
					'type'        => 'email',
64
65
					'class'       => 'form-control input-lg',
66
					'tabindex'    => '1',
67
68
					'placeholder' => 'Email Address',
69
					'value'       => '',
70
71
					'required'    => ''
72 3
			);
73
			$this->body_data['form_submit'] = array(
74
					'name'     => 'submit',
75
					'type'     => 'submit',
76
77
					'class'    => 'btn btn-primary btn-block btn-lg',
78
					'tagindex' => '2',
79
80
					'value'    => 'Send verification email.'
81
			);
82 3
83
			$this->_render_page('User/Signup');
84 4
		}
85
	}
86
87 4
	//This continued signup occurs after the user clicks the verification link in their email.
88
	private function _continue_signup($verificationCode) : void {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
89 4
		//check if validation is valid, if so return email, if not redirect to signup
90
		if(!($email = $this->Auth->verificationCheck($verificationCode))) redirect('user/signup');
91
92 3
		//validation is valid, proceed as normal
93 3
		$this->form_validation->set_rules('username',         'Username',           'required|min_length[4]|max_length[15]|valid_username|is_unique_username');
94 3
		$this->form_validation->set_rules('password',         'Password',           'required|valid_password');
95 3
		$this->form_validation->set_rules('password_confirm', 'Confirm Password',   'required|matches[password]');
96
		$this->form_validation->set_rules('terms',            'Terms & Conditions', 'required');
97
		//TODO: timezone
98
		//TODO: receive email
99 3
100 2
		if ($isValid = ($this->form_validation->run() === TRUE)) {
101 2
			$username = $this->input->post('username');
102
			$password = $this->input->post('password');
103
104 2
			$additional_data = array(
105
				'username' => $username // ion_auth is extremely retarded, and doesn't save username if email is being used as identity, we need to force it.
106
			); //TODO: For extra user info.
107 2
108
			if($this->ion_auth->register($username, $password, $email, $additional_data)) {
109
				//Signup succeeded.
110 1
111
				$this->Auth->verificationComplete($email);
112 1
113
				redirect('help');
114
			} else { //@codeCoverageIgnore
115 1
				//Signup failed.
116
				$isValid = FALSE;
117
			}
118
		}
119
120 2
		//signup wasn't valid, failed, or this is a fresh signup attempt
121
		if(!$isValid){
122 2
			//display the create user form
123
			$this->body_data['verificationCode'] = $verificationCode;
124 2
125 2
			$this->body_data['form_username'] = array(
126 2
				'name'        => 'username',
127 2
				'id'          => 'username',
128
				'type'        => 'text',
129 2
130 2
				'class'       => 'form-control input-lg',
131 2
				'title'       => 'Username must be 4-15 characters, and can only contain a-z, A-Z, 0-9, _ & - characters.',
132
				'tabindex'    => '1',
133 2
134 2
				'placeholder' => 'Username (4-15 characters)',
135 2
				'value'       => $this->form_validation->set_value('username'),
136
				'pattern'     => '[a-zA-Z0-9_-]{4,15}',
137 2
138
				'required'    => ''
139 2
			);
140 2
			$this->body_data['form_email'] = array(
141 2
				'name'        => 'email',
142 2
				'id'          => 'email',
143
				'type'        => 'text',
144 2
145 2
				'class'       => 'form-control input-lg',
146
				'tabindex'    => '-1',
147 2
148 2
				'placeholder' => 'Email Address',
149 2
				'value'       => $email,
150
				'readonly'    => '1',
151 2
152
				'required'    => ''
153 2
			);
154
			$this->body_data['form_password'] = array(
155
				'name'         => 'password',
156
				'id'           => 'password',
157
				'type'         => 'password',
158
159
				'class'        => 'form-control input-lg',
160
				'title'        => 'Password must be between 6 & 64 characters.',
161
				'tabindex'     => '2',
162
163
				'placeholder'  => 'Password',
164
				'value'        => '',
165
				'pattern'      => '.{6,64}',
166
				'autocomplete' => 'off',
167
168
				'required'     => ''
169 2
			);
170
			$this->body_data['form_password_confirm'] = array(
171
				'name'        => 'password_confirm',
172
				'id'          => 'password_confirm',
173
				'type'        => 'password',
174
175
				'class'       => 'form-control input-lg',
176
				'title'       => 'This field must match the password field',
177
				'tabindex'    => '3',
178
179
				'placeholder' => 'Confirm Password',
180
				'value'       => '',
181
182
				'required'    => ''
183 2
			);
184
			$this->body_data['form_terms'] = array(
185
				'name'         => 'terms',
186
				'id'           => 'terms',
187
				'type'         => 'checkbox',
188
189
				'hidden'       => TRUE,
190
				'tagindex'     => '4',
191
				'title'        => 'You must click to accept TOS.',
192
193
				'value'        => '1',
194
				'autocomplete' => 'off',
195
196
				'required'     => ''
197 2
			);
198
			$this->body_data['form_submit'] = array(
199
				'name'     => 'submit',
200
				'type'     => 'submit',
201
202
				'class'    => 'btn btn-primary btn-block btn-lg',
203
				'tagindex' => '5',
204
205
				'value'    => 'Register'
206
			);
207 2
208
			$this->_render_page('User/Signup_Continued');
209 2
		}
210
	}
211
212
	private function _no_more_signup() : void {
213
		$this->_render_page('User/Signup_Closed');
214
	}
215
}
216