1: <?php
2: 3: 4: 5:
6:
7: if (!defined('XOOPS_ROOT_PATH')) exit();
8:
9: require_once XOOPS_MODULE_PATH . "/user/forms/LostPassEditForm.class.php";
10: require_once XOOPS_MODULE_PATH . "/user/class/LostPassMailBuilder.class.php";
11:
12: 13: 14: 15: 16: 17: 18: 19:
20: class User_LostPassAction extends User_Action
21: {
22: 23: 24:
25: var $mActionForm = null;
26:
27: function prepare(&$controller, &$xoopsUser, $moduleConfig)
28: {
29: $this->mActionForm =new User_LostPassEditForm();
30: $this->mActionForm->prepare();
31: }
32:
33: function isSecure()
34: {
35: return false;
36: }
37:
38:
39: function hasPermission(&$controller, &$xoopsUser, $moduleConfig)
40: {
41: return !$controller->mRoot->mContext->mUser->mIdentity->isAuthenticated();
42: }
43:
44: function getDefaultView(&$controller, &$xoopsUser)
45: {
46: $root =& XCube_Root::getSingleton();
47: $code = $root->mContext->mRequest->getRequest('code');
48: $email = $root->mContext->mRequest->getRequest('email');
49: if (strlen($code) == 0 || strlen($email) == 0) {
50: return USER_FRAME_VIEW_INPUT;
51: } else {
52: return $this->_updatePassword($controller);
53: }
54: }
55:
56: function _updatePassword(&$controller) {
57: $this->mActionForm->fetch();
58:
59: $userHandler =& xoops_gethandler('user');
60: $criteria =new CriteriaCompo(new Criteria('email', $this->mActionForm->get('email')));
61: $criteria->add(new Criteria('pass', $this->mActionForm->get('code'), '=', '', 'LEFT(%s, 5)'));
62: $lostUserArr =& $userHandler->getObjects($criteria);
63:
64: if (is_array($lostUserArr) && count($lostUserArr) > 0) {
65: $lostUser =& $lostUserArr[0];
66: }
67: else {
68: return USER_FRAME_VIEW_ERROR;
69: }
70:
71: $newpass = xoops_makepass();
72: $extraVars['newpass'] = $newpass;
73: $builder =new User_LostPass2MailBuilder();
74: $director =new User_LostPassMailDirector($builder, $lostUser, $controller->mRoot->mContext->getXoopsConfig(), $extraVars);
75: $director->contruct();
76: $xoopsMailer =& $builder->getResult();
77: if (!$xoopsMailer->send()) {
78:
79: return USER_FRAME_VIEW_ERROR;
80: }
81: $lostUser->set('pass',md5($newpass), true);
82: $userHandler->insert($lostUser, true);
83:
84: return USER_FRAME_VIEW_SUCCESS;
85: }
86:
87: function execute(&$controller, &$xoopsUser)
88: {
89: $this->mActionForm->fetch();
90: $this->mActionForm->validate();
91:
92: if ($this->mActionForm->hasError()) {
93: return USER_FRAME_VIEW_INPUT;
94: }
95:
96: $userHandler =& xoops_gethandler('user');
97: $lostUserArr =& $userHandler->getObjects(new Criteria('email', $this->mActionForm->get('email')));
98:
99: if (is_array($lostUserArr) && count($lostUserArr) > 0) {
100: $lostUser =& $lostUserArr[0];
101: }
102: else {
103: return USER_FRAME_VIEW_ERROR;
104: }
105:
106: $builder =new User_LostPass1MailBuilder();
107: $director =new User_LostPassMailDirector($builder, $lostUser, $controller->mRoot->mContext->getXoopsConfig());
108: $director->contruct();
109: $xoopsMailer =& $builder->getResult();
110:
111: if (!$xoopsMailer->send()) {
112:
113: return USER_FRAME_VIEW_ERROR;
114: }
115:
116: return USER_FRAME_VIEW_SUCCESS;
117: }
118:
119: function executeViewInput(&$controller, &$xoopsUser, &$render)
120: {
121: $render->setTemplateName("user_lostpass.html");
122: $render->setAttribute("actionForm", $this->mActionForm);
123: }
124:
125: function executeViewSuccess(&$controller, &$xoopsUser, &$render)
126: {
127: $controller->executeRedirect(XOOPS_URL . '/', 3, _MD_USER_MESSAGE_SEND_PASSWORD);
128: }
129:
130: function executeViewError(&$controller, &$xoopsUser, &$render)
131: {
132: $controller->executeRedirect(XOOPS_URL . '/', 3, _MD_USER_ERROR_SEND_MAIL);
133: }
134: }
135:
136: ?>
137: