XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
LostPassMailBuilder.class.php
1<?php
2
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12/***
13 * @internal
14 * This class commands a builder to build mail. It's a kind of builder pattern,
15 * and made for separating the building logic and the business logic.
16 */
18{
19 public $mBuilder;
20 public $mXoopsUser;
21 public $mXoopsConfig;
22 public $mExtraVars;
23
24 public function __construct(&$builder, &$user, &$xoopsConfig, $extraVars = [])
25 {
26 $this->mBuilder = &$builder;
27 $this->mXoopsUser = &$user;
28 $this->mXoopsConfig = &$xoopsConfig;
29 $this->mExtraVars = $extraVars;
30 }
31
32 public function contruct()
33 {
34 $this->mBuilder->setToUsers($this->mXoopsUser, $this->mXoopsConfig);
35 $this->mBuilder->setFromEmail($this->mXoopsUser, $this->mXoopsConfig);
36 $this->mBuilder->setSubject($this->mXoopsUser, $this->mXoopsConfig);
37 $this->mBuilder->setTemplate();
38 $this->mBuilder->setBody($this->mXoopsUser, $this->mXoopsConfig, $this->mExtraVars);
39 }
40}
41
42/***
43 * @internal
44 * This class is a builder for User_LostPassMailDirector and the base class,
45 * and the base class for other builders. Use lostpass1.tpl as the template.
46 * That's the first mail at procedure of the password regenerated, and written
47 * about the special URL which generates new password.
48 */
50{
51 public $mMailer;
52
53 public function __construct()
54 {
55 $this->mMailer = &getMailer();
56 $this->mMailer->useMail();
57 }
58
59 public function setToUsers($user, $xoopsConfig)
60 {
61 $this->mMailer->setToUsers($user);
62 }
63
64 public function setFromEmail($user, $xoopsConfig)
65 {
66 $root =& XCube_Root::getSingleton();
67 $xoopsConfig = $root->mContext->mXoopsConfig;
68 $this->mMailer->setFromEmail(defined('XOOPS_NOTIFY_FROM_EMAIL') ? XOOPS_NOTIFY_FROM_EMAIL : $xoopsConfig['adminmail']);
69 $this->mMailer->setFromName(defined('XOOPS_NOTIFY_FROM_NAME') ? XOOPS_NOTIFY_FROM_NAME : $xoopsConfig['sitename']);
70 }
71
72 public function setSubject($user, $xoopsConfig)
73 {
74 $root =& XCube_Root::getSingleton();
75 $xoopsConfig = $root->mContext->mXoopsConfig;
76 $this->mMailer->setSubject(sprintf(_MD_USER_LANG_NEWPWDREQ, $xoopsConfig['sitename']));
77 }
78
82 public function setTemplate()
83 {
84 $root = &XCube_Root::getSingleton();
85 $language = $root->mContext->getXoopsConfig('language');
86 $this->mMailer->setTemplateDir(XOOPS_MODULE_PATH . '/user/language/' . $language . '/mail_template/');
87 $this->mMailer->setTemplate('lostpass1.tpl');
88 }
89
90 public function setBody($user, $xoopsConfig, $extraVars)
91 {
92 $root =& XCube_Root::getSingleton();
93 $xoopsConfig = $root->mContext->mXoopsConfig;
94 $this->mMailer->assign('SITENAME', $xoopsConfig['sitename']);
95 $this->mMailer->assign('ADMINMAIL', (!defined('XOOPS_NOTIFY_FROM_EMAIL') || XOOPS_NOTIFY_FROM_EMAIL === $xoopsConfig['adminmail']) ? $xoopsConfig['adminmail'] : '');
96 $this->mMailer->assign('SITEURL', XOOPS_URL . '/');
97 $this->mMailer->assign('IP', $_SERVER['REMOTE_ADDR']);
98 $queryString = http_build_query(
99 [
100 'email' => $user->getShow('email'),
101 'code' => substr($user->get('pass'), 0, 5),
102 ]
103 );
104 $this->mMailer->assign('NEWPWD_LINK', XOOPS_URL . '/lostpass.php?' . $queryString);
105 }
106
107 public function &getResult()
108 {
109 return $this->mMailer;
110 }
111}
112
113/***
114 * @internal
115 * This class is a builder which uses lostpass2.tpl as the template. That's the
116 * second mail at procedure of the password regenerated, and written about the
117 * new generated password of the user.
118 */
120{
121 public function setTemplate()
122 {
123 $root = &XCube_Root::getSingleton();
124 $language = $root->mContext->getXoopsConfig('language');
125 $this->mMailer->setTemplateDir(XOOPS_MODULE_PATH . '/user/language/' . $language . '/mail_template/');
126 $this->mMailer->setTemplate('lostpass2.tpl');
127 }
128
129 public function setSubject($user, $xoopsConfig)
130 {
131 $root =& XCube_Root::getSingleton();
132 $xoopsConfig = $root->mContext->mXoopsConfig;
133 $this->mMailer->setSubject(sprintf(_MD_USER_LANG_NEWPWDREQ, $xoopsConfig['sitename']));
134 }
135
136 public function setBody($user, $xoopsConfig, $extraVars)
137 {
138 $root =& XCube_Root::getSingleton();
139 $xoopsConfig = $root->mContext->mXoopsConfig;
140 $this->mMailer->assign('SITENAME', $xoopsConfig['sitename']);
141 $this->mMailer->assign('ADMINMAIL', (!defined('XOOPS_NOTIFY_FROM_EMAIL') || XOOPS_NOTIFY_FROM_EMAIL === $xoopsConfig['adminmail']) ? $xoopsConfig['adminmail'] : '');
142 $this->mMailer->assign('SITEURL', XOOPS_URL . '/');
143 $this->mMailer->assign('IP', $_SERVER['REMOTE_ADDR']);
144 $this->mMailer->assign('NEWPWD', $extraVars['newpass']);
145 }
146}