-
Notifications
You must be signed in to change notification settings - Fork 138
/
forgot.php
157 lines (127 loc) · 4.53 KB
/
forgot.php
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
* CC-BY License - http://creativecommons.org/licenses/by/3.0/
*/
require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
bx_import( 'BxDolEmailTemplates' );
bx_import( 'BxTemplFormView' );
class BxDolForgotCheckerHelper extends BxDolFormCheckerHelper
{
public static function checkEmail($s)
{
if (!preg_match("/(([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?/", $s))
return false;
$iID = (int)db_value( "SELECT `ID` FROM `Profiles` WHERE `Email` = '$s'" );
if (!$iID)
return _t( '_MEMBER_NOT_RECOGNIZED', $site['title'] );
return true;
}
}
// --------------- page variables and login
$_page['name_index'] = 1;
$logged['member'] = member_auth( 0, false );
$_page['header'] = _t( "_Forgot password?" );
$_page['header_text'] = _t( "_Password retrieval", $site['title'] );
// --------------- page components
$_ni = $_page['name_index'];
$aForm = array(
'form_attrs' => array(
'name' => 'forgot_form',
'action' => BX_DOL_URL_ROOT . 'forgot.php',
'method' => 'post',
),
'params' => array (
'db' => array(
'submit_name' => 'do_submit',
),
'checker_helper' => 'BxDolForgotCheckerHelper',
),
'inputs' => array(
array(
'type' => 'email',
'name' => 'Email',
'caption' => _t('_My Email'),
'value' => isset($_POST['Email']) ? $_POST['Email'] : '',
'required' => true,
'checker' => array(
'func' => 'email',
'error' => _t( '_Incorrect Email' )
),
),
array(
'type' => 'captcha',
'name' => 'captcha',
'caption' => _t('_Enter Captcha'),
'required' => true,
'checker' => array(
'func' => 'captcha',
'error' => _t( '_Incorrect Captcha' ),
),
),
array(
'type' => 'submit',
'name' => 'do_submit',
'value' => _t( "_Retrieve my information" ),
),
)
);
$oForm = new BxTemplFormView($aForm);
$oForm->initChecker();
if ( $oForm->isSubmittedAndValid() ) {
// Check if entered email is in the base
$sEmail = process_db_input($_POST['Email'], BX_TAGS_STRIP);
$memb_arr = db_arr( "SELECT `ID` FROM `Profiles` WHERE `Email` = '$sEmail'" );
$recipient = $sEmail;
$rEmailTemplate = new BxDolEmailTemplates();
$aTemplate = $rEmailTemplate -> getTemplate( 't_Forgot', $memb_arr['ID'] ) ;
$aPlus['Password'] = generateUserNewPwd($memb_arr['ID']);
$aProfile = getProfileInfo($memb_arr['ID']);
$mail_ret = sendMail( $recipient, $aTemplate['Subject'], $aTemplate['Body'], $memb_arr['ID'], $aPlus, 'html', false, true );
// create system event
require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolAlerts.php');
$oZ = new BxDolAlerts('profile', 'password_restore', $memb_arr['ID']);
$oZ->alert();
$_page['header'] = _t( "_Recognized" );
$_page['header_text'] = _t( "_RECOGNIZED", $site['title'] );
if ($mail_ret)
$action_result = _t( "_MEMBER_RECOGNIZED_MAIL_SENT", $site['url'], $site['title'] );
else
$action_result = _t( "_MEMBER_RECOGNIZED_MAIL_NOT_SENT", $site['title'] );
$sForm = '';
} else {
$action_result = _t( "_FORGOT", $site['title'] );
$sForm = $oForm->getCode();
}
$sPageCode = <<<BLAH
<div class="bx-def-margin-sec-bottom bx-def-font-large">
$action_result
</div>
$sForm
BLAH;
$_page_cont[$_ni]['page_main_code'] = DesignBoxContent($_page['header_text'], $sPageCode, 11);
// --------------- [END] page components
PageCode();
// --------------- page components functions
function generateUserNewPwd($ID)
{
$sPwd = genRndPwd();
$sSalt = genRndSalt();
$sQuery = "
UPDATE `Profiles`
SET
`Password` = '" . encryptUserPwd($sPwd, $sSalt) . "',
`Salt` = '$sSalt'
WHERE
`ID`= ?
";
db_res($sQuery, [$ID]);
createUserDataFile($ID);
require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolAlerts.php');
$oZ = new BxDolAlerts('profile', 'edit', $ID);
$oZ->alert();
return $sPwd;
}