XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
LostPassAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/forms/LostPassEditForm.class.php';
13require_once XOOPS_MODULE_PATH . '/user/class/LostPassMailBuilder.class.php';
14
15/***
16 * @internal
17 * @public
18 * The process of lostpass. This action sends a mail even if the input mail
19 * address isn't registered in the site. Because displaying error message in
20 * such case shows the part of the personal information. We will discuss about
21 * this spec.
22 */
23class User_LostPassAction extends User_Action
24{
25 /***
26 * @var User_LostPassEditForm
27 */
28 public $mActionForm = null;
29
30 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
31 {
32 $this->mActionForm =new User_LostPassEditForm();
33 $this->mActionForm->prepare();
34 }
35
36 public function isSecure()
37 {
38 return false;
39 }
40
42 public function hasPermission(&$controller, &$xoopsUser, $moduleConfig)
43 {
44 return !$controller->mRoot->mContext->mUser->mIdentity->isAuthenticated();
45 }
46
47 public function getDefaultView(&$controller, &$xoopsUser)
48 {
49 $root =& XCube_Root::getSingleton();
50 $code = $root->mContext->mRequest->getRequest('code'); // const $code
51 $email = $root->mContext->mRequest->getRequest('email'); // const $email
52 if (0 == strlen($code) || 0 == strlen($email)) {
53 return USER_FRAME_VIEW_INPUT;
54 } else {
55 return $this->_updatePassword($controller);
56 }
57 }
58
59 public function _updatePassword(&$controller)
60 {
61 $extraVars = [];
62 $this->mActionForm->fetch();
63
64 $userHandler =& xoops_gethandler('user');
65 $criteria =new CriteriaCompo(new Criteria('email', $this->mActionForm->get('email')));
66 $criteria->add(new Criteria('pass', $this->mActionForm->get('code'), '=', '', 'LEFT(%s, 5)'));
67 $lostUserArr =& $userHandler->getObjects($criteria);
68
69 if (is_array($lostUserArr) && count($lostUserArr) > 0) {
70 $lostUser =& $lostUserArr[0];
71 } else {
72 return USER_FRAME_VIEW_ERROR;
73 }
74
75 $newpass = xoops_makepass();
76 $extraVars['newpass'] = $newpass;
77
78 $lostUser->set('pass', User_Utils::encryptPassword($newpass), true);
79 if (!$userHandler->insert($lostUser, true)) {
80 return USER_FRAME_VIEW_ERROR;
81 }
82
83 $builder =new User_LostPass2MailBuilder();
84 //$getXConfig = getXoopsConfig(); gigamaster fix error 'lost-password'
85 $getXConfig = $controller->mRoot->mContext->getXoopsConfig();
86
87
88 $director =new User_LostPassMailDirector($builder, $lostUser, $controller->mRoot->mContext->$getXConfig, $extraVars);
89 $director->contruct();
90 $xoopsMailer =& $builder->getResult();
91 XCube_DelegateUtils::call('Legacy.Event.RegistUser.SendMail', new XCube_Ref($xoopsMailer), 'LostPass2');
92 if (!$xoopsMailer->send()) {
93 // $xoopsMailer->getErrors();
94 return USER_FRAME_VIEW_ERROR;
95 }
96
97 return USER_FRAME_VIEW_SUCCESS;
98 }
99
100 public function execute(&$controller, &$xoopsUser)
101 {
102 $this->mActionForm->fetch();
103 $this->mActionForm->validate();
104
105 if ($this->mActionForm->hasError()) {
106 return USER_FRAME_VIEW_INPUT;
107 }
108
109 $userHandler =& xoops_gethandler('user');
110 $lostUserArr =& $userHandler->getObjects(new Criteria('email', $this->mActionForm->get('email')));
111
112 if (is_array($lostUserArr) && (count($lostUserArr) > 0) ) {
113 $lostUser =& $lostUserArr[0];
114 } else {
115 return USER_FRAME_VIEW_ERROR;
116 }
117
118 $builder =new User_LostPass1MailBuilder();
119 //$getXConfig = getXoopsConfig();
120
121 $root =& XCube_Root::getSingleton();
122 $getXConfig = $root->mContext->getXoopsConfig(); // gigamaster fix lost-password
123
124
125 $director =new User_LostPassMailDirector($builder, $lostUser, $controller->mRoot->mContext->$getXConfig);
126 $director->contruct();
127 $xoopsMailer =& $builder->getResult();
128 XCube_DelegateUtils::call('Legacy.Event.RegistUser.SendMail', new XCube_Ref($xoopsMailer), 'LostPass1');
129
130 if (!$xoopsMailer->send()) {
131 // $xoopsMailer->getErrors();
132 return USER_FRAME_VIEW_ERROR;
133 }
134
135 return USER_FRAME_VIEW_SUCCESS;
136 }
137
138 public function executeViewInput(&$controller, &$xoopsUser, &$render)
139 {
140 $render->setTemplateName('user_lostpass.html');
141 $render->setAttribute('actionForm', $this->mActionForm);
142 }
143
144 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
145 {
146 $controller->executeRedirect(XOOPS_URL . '/', 3, _MD_USER_MESSAGE_SEND_PASSWORD);
147 }
148
149 public function executeViewError(&$controller, &$xoopsUser, &$render)
150 {
151 $controller->executeRedirect(XOOPS_URL . '/', 3, _MD_USER_ERROR_SEND_MAIL);
152 }
153}
static encryptPassword($password)