-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.php
More file actions
143 lines (121 loc) · 5.72 KB
/
code.php
File metadata and controls
143 lines (121 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* Create Member
*
* @param array $values Values from form
* @param array $profileFields Profile field values from registration
* @param array|NULL $postBeforeRegister The row from core_post_before_registering if applicable
* @param \IPS\Helpers\Form $form The form object
* @return \IPS\Member|bool Returns member object if registration is successful, otherwise false
*/
public static function _createMember($values, $profileFields, $postBeforeRegister, &$form)
{
/* Check if email is provided and not empty */
if (empty($values['email_address'])) {
\IPS\Output::i()->error('Email address is required.', 'email_required_error', 403, '');
return false;
}
/* Check for disposable email */
if (static::checkDisposableEmail($values['email_address'])) {
\IPS\Output::i()->error('Disposable email addresses are not allowed.', 'disposable_email_error', 403, '');
return false;
}
/* Create */
$member = new \IPS\Member;
$member->name = $values['username'];
$member->email = $values['email_address'];
$member->setLocalPassword($values['password']);
$member->allow_admin_mails = $values['reg_admin_mails'];
$member->member_group_id = \IPS\Settings::i()->member_group;
$member->members_bitoptions['view_sigs'] = true;
$member->last_visit = time();
if (isset(\IPS\Request::i()->cookie['language']) && \IPS\Request::i()->cookie['language']) {
$member->language = \IPS\Request::i()->cookie['language'];
} elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$member->language = \IPS\Lang::autoDetectLanguage($_SERVER['HTTP_ACCEPT_LANGUAGE']);
}
if (\IPS\Settings::i()->allow_reg != 'disabled') {
/* Initial Save */
$member->save();
/* This looks a bit weird, but the extensions expect an account to exist at this point, so we'll let the system save it now, then do what we need to do, then save again */
foreach (\IPS\Member\ProfileStep::loadAll() as $step) {
$extension = $step->extension;
$extension::formatFormValues($values, $member, $form);
}
}
/* Save anything the profile extensions did */
$member->save();
/* Security Questions */
if (\IPS\Settings::i()->security_questions_enabled && \in_array(\IPS\Settings::i()->security_questions_prompt, array('register', 'optional'))) {
if (isset($values['security_questions_optout_title'])) {
$member->members_bitoptions['security_questions_opt_out'] = true;
/* Log MFA Opt-out */
$member->logHistory('core', 'mfa', array('handler' => 'questions', 'enable' => false, 'optout' => true));
} else {
$answers = array();
foreach ($values as $k => $v) {
if (preg_match('/^security_question_q_(\d+)$/', $k, $matches)) {
$answers[$v] = array(
'answer_question_id' => $v,
'answer_member_id' => $member->member_id,
'answer_answer' => \IPS\Text\Encrypt::fromPlaintext($values['security_question_a_' . $matches[1]])->tag()
);
}
}
if (\count($answers)) {
\IPS\Db::i()->insert('core_security_answers', $answers);
}
$member->members_bitoptions['has_security_answers'] = true;
/* Log MFA Enable */
$member->logHistory('core', 'mfa', array('handler' => 'questions', 'enable' => true));
}
$member->save();
}
/* Cycle profile fields */
foreach ($profileFields as $id => $fieldValue) {
$field = \IPS\core\ProfileFields\Field::loadWithMember(mb_substr($id, 6), null, null, null);
if ($field->type == 'Editor') {
$field->claimAttachments($member->member_id);
}
}
/* Save custom field values */
\IPS\Db::i()->replace('core_pfields_content', array_merge(array('member_id' => $member->member_id), $profileFields));
/* Log that we gave consent for admin emails */
$member->logHistory('core', 'admin_mails', array('enabled' => (bool) $member->allow_admin_mails));
/* Log that we gave consent for terms and privacy */
if (\IPS\Settings::i()->privacy_type != 'none') {
$member->logHistory('core', 'terms_acceptance', array('type' => 'privacy'));
}
$member->logHistory('core', 'terms_acceptance', array('type' => 'terms'));
/* Handle validation */
$member->postRegistration(false, false, $postBeforeRegister, static::_refUrl());
/* Save and return */
return $member;
}
/**
* Check if an email address is disposable
*
* @param string $email The email address to check
* @return bool True if the email is disposable, otherwise false
*/
protected static function checkDisposableEmail($email)
{
$api_url = 'https://api.api-aries.online/v1/checkers/proxy/email/?email=' . urlencode($email);
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Type: TOKEN TYPE', // learn more: https://support.api-aries.online/hc/articles/1/3/3/email-checker
'APITOKEN: API KEY' // learn more: https://support.api-aries.online/hc/articles/1/3/3/email-checker
));
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response code: " . $httpcode . PHP_EOL;
echo "Response: " . $response . PHP_EOL;
if ($httpcode === 200) {
$data = json_decode($response, true);
if ($data && isset($data['disposable']) && strtolower($data['disposable']) === 'yes') {
return true;
}
}
return false;
}