1
0
Эх сурвалжийг харах

Ticket #5365 - Improve activation/confirmation/welcome letters sending.

AntonLV 8 сар өмнө
parent
commit
31eff167eb

+ 32 - 1
inc/classes/BxDolAccount.php

@@ -471,7 +471,38 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
 
         return $bResult;
     }
-    
+
+    /**
+     * Send "welcome" email
+     */
+    public function sendWelcomeEmail($iAccountId = false)
+    {
+        if(getParam('sys_account_welcome_letter') != 'on')
+            return false;
+
+        $iAccountId = (int)$iAccountId;
+        if(!$iAccountId)
+            $iAccountId = $this->_iAccountID;
+
+        $aAccountInfo = $this->getInfo($iAccountId);
+        if(empty($aAccountInfo) || !is_array($aAccountInfo))
+            return false;
+
+        if((int)$aAccountInfo['welcome_sent'] != 0)
+            return true;
+
+        $sEmailTemplate = 't_Welcome';
+        $aEmailReplaceVars = [
+            'name' => $this->getDisplayName($iAccountId),
+        ];
+
+        $bResult = sendMailTemplate($sEmailTemplate, $iAccountId, (int)$aAccountInfo['profile_id'], $aEmailReplaceVars, BX_EMAIL_SYSTEM);
+        if($bResult)
+            $this->_oQuery->updateWelcomeSent(1, $iAccountId);
+
+        return $bResult;
+    }
+
     public function sendResetPasswordEmail($iAccountId = false)
     {
         $iAccountId = (int)$iAccountId;

+ 11 - 0
inc/classes/BxDolAccountQuery.php

@@ -301,6 +301,17 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
         return $this->_updateField ($iID, 'phone_confirmed', $isConfirmed ? 1 : 0);
     }
     
+    /**
+     * Update 'welcome_sent' field.
+     * @param  int    $isSent   - 0: mark as sent, 1: as not sent
+     * @param  int    $iID      - account id
+     * @return number of affected rows
+     */
+    public function updateWelcomeSent($isSent, $iID)
+    {
+        return $this->_updateField ($iID, 'welcome_sent', $isSent ? 1 : 0);
+    }
+
     /**
      * Update 'phone' field.
      * @param  int    $sPhone - phone number

+ 4 - 3
install/sql/system.sql

@@ -294,6 +294,7 @@ CREATE TABLE IF NOT EXISTS `sys_email_templates` (
 INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES
 ('system', '_sys_et_txt_name_system_admin_email', 't_AdminEmail', '_sys_et_txt_subject_admin_email', '_sys_et_txt_body_admin_email'),
 ('system', '_sys_et_txt_name_system_confirmation', 't_Confirmation', '_sys_et_txt_subject_confirmation', '_sys_et_txt_body_confirmation'),
+('system', '_sys_et_txt_name_system_welcome', 't_Welcome', '_sys_et_txt_subject_welcome', '_sys_et_txt_body_welcome'),
 ('system', '_sys_et_txt_name_system_forgot', 't_Forgot', '_sys_et_txt_subject_forgot', '_sys_et_txt_body_forgot'),
 ('system', '_sys_et_txt_name_system_mem_expiration', 't_MemExpiration', '_sys_et_txt_subject_mem_expiration', '_sys_et_txt_body_mem_expiration'),
 ('system', '_sys_et_txt_name_system_mem_changed', 't_MemChanged', '_sys_et_txt_subject_mem_changed', '_sys_et_txt_body_mem_changed'),
@@ -424,8 +425,6 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_session_lifetime_in_min', '_adm_stg_cpt_option_sys_session_lifetime_in_min', '129600', 'digit', '', '', '', '', 110),
 (@iCategoryId, 'sys_session_auth', '_adm_stg_cpt_option_sys_session_auth', 'on', 'checkbox', '', '', '', '', 112),
 
-(@iCategoryId, 'sys_account_activation_letter', '_adm_stg_cpt_option_sys_account_activation_letter', '', 'checkbox', '', '', '', '', 120),
-
 (@iCategoryId, 'sys_logs_storage_default', '_adm_stg_cpt_option_sys_logs_storage_default', 'Folder', 'select', 'Folder,PHPLog,STDErr', '', '', '', 130),
 (@iCategoryId, 'sys_logs_level', '_adm_stg_cpt_option_sys_logs_level', 'DEBUG', 'select', 'ERROR,WARNING,INFO,DEBUG', '', '', '', 132),
 
@@ -698,7 +697,8 @@ SET @iCategoryId = LAST_INSERT_ID();
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'sys_account_online_time', '_adm_stg_cpt_option_sys_account_online_time', '5', 'digit', '', 'Avail', '_adm_stg_err_option_sys_account_online_time', 1),
 (@iCategoryId, 'sys_account_autoapproval', '_adm_stg_cpt_option_sys_account_autoapproval', 'on', 'checkbox', '', '', '', 10),
-(@iCategoryId, 'sys_account_confirmation_type', '_adm_stg_cpt_option_sys_account_confirmation_type', 'email', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:22:"get_confirmation_types";s:5:"class";s:18:"BaseServiceAccount";}', '', '', 12),
+(@iCategoryId, 'sys_account_confirmation_type', '_adm_stg_cpt_option_sys_account_confirmation_type', 'email', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:22:"get_confirmation_types";s:5:"class";s:18:"BaseServiceAccount";}', '', '', 11),
+(@iCategoryId, 'sys_account_welcome_letter', '_adm_stg_cpt_option_sys_account_welcome_letter', '', 'checkbox', '', '', '', '', 12),
 (@iCategoryId, 'sys_account_activation_2fa_enable', '_adm_stg_cpt_option_sys_account_2fa_enable', '', 'checkbox', '', '', '', 13),
 (@iCategoryId, 'sys_account_activation_2fa_lifetime', '_adm_stg_cpt_option_sys_account_2fa_lifetime', '0', 'digit', '', '', '', 14),
 (@iCategoryId, 'sys_account_auto_profile_creation', '_adm_stg_cpt_option_sys_account_auto_profile_creation', 'on', 'checkbox', '', '', '', 15),
@@ -1452,6 +1452,7 @@ CREATE TABLE `sys_accounts` (
   `email_confirmed` tinyint(4) NOT NULL DEFAULT '0',
   `phone` varchar(255) NOT NULL,
   `phone_confirmed` tinyint(4) NOT NULL DEFAULT '0',
+  `welcome_sent` tinyint(4) NOT NULL DEFAULT '0',
   `receive_updates` tinyint(4) NOT NULL DEFAULT '1',
   `receive_news` tinyint(4) NOT NULL DEFAULT '1',
   `password` varchar(40) NOT NULL,

+ 11 - 1
modules/boonex/english/data/langs/system/en.xml

@@ -1597,7 +1597,7 @@
     <string name="_adm_stg_inf_option_smart_app_banner"><![CDATA[]]></string>
     <string name="_adm_stg_cpt_option_smart_app_banner_ios_app_id"><![CDATA[iOS app ID for Smart App Banner]]></string>
     <string name="_adm_stg_inf_option_smart_app_banner_ios_app_id"><![CDATA[]]></string>
-    <string name="_adm_stg_cpt_option_sys_account_activation_letter"><![CDATA[Enable account activation letter]]></string>
+    <string name="_adm_stg_cpt_option_sys_account_welcome_letter"><![CDATA[Enable welcome letter]]></string>
     <string name="_adm_stg_cpt_option_sys_account_confirmation_type"><![CDATA[Account is confirmed when]]></string>
     <string name="_adm_stg_cpt_option_sys_account_hide_unconfirmed_accounts"><![CDATA[Hide profiles which have unconfirmed account]]></string>
     <string name="_adm_stg_cpt_option_sys_account_2fa_enable"><![CDATA[Enable 2 Factor Authentication]]></string>
@@ -2589,6 +2589,14 @@ If it is not enabled then please consider implement this optimization, since it
 <p>or use the code:</p>
 <p><span class="h3">{conf_code}</span></p>
 <p> </p>
+{email_footer}]]></string>
+    <string name="_sys_et_txt_body_welcome"><![CDATA[{email_header}
+<p>Hello {name},</p>
+<p>You are welcome to {site_name}</p>
+<p> </p>
+<p>You've confirmed your profile and is ready to use our site.</p>
+<p>Feel free to contact us if you need some help.</p>
+<p> </p>
 {email_footer}]]></string>
     <string name="_sys_et_txt_body_delayed_module_uninstall"><![CDATA[{email_header}
 <p>Module: <b>{Module}</b></p>
@@ -2696,6 +2704,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_et_txt_name_system_comment_replied"><![CDATA[The letter is sent to members whose comment was replied]]></string>
 	<string name="_sys_et_txt_name_system_reported"><![CDATA[New report notification]]></string>
 	<string name="_sys_et_txt_name_system_confirmation"><![CDATA[Profile e-mail confirmation message]]></string>
+        <string name="_sys_et_txt_name_system_welcome"><![CDATA[Welcome message]]></string>
 	<string name="_sys_et_txt_name_system_delayed_module_uninstall"><![CDATA[Delayed module uninstall notification]]></string>
 	<string name="_sys_et_txt_name_system_forgot"><![CDATA[Reset password message]]></string>
 	<string name="_sys_et_txt_name_system_mem_changed"><![CDATA[The letter is sent to members whose membership level was changed]]></string>
@@ -2719,6 +2728,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_et_txt_subject_comment_replied"><![CDATA[User {sender_display_name} replied to your comment.]]></string>
 	<string name="_sys_et_txt_subject_system_reported"><![CDATA[New report notification]]></string>
 	<string name="_sys_et_txt_subject_confirmation"><![CDATA[Confirm your email address]]></string>
+        <string name="_sys_et_txt_subject_welcome"><![CDATA[You are welcome to {site_name}]]></string>
 	<string name="_sys_et_txt_subject_delayed_module_uninstall"><![CDATA[Delayed {Module} module uninstall: {Result}]]></string>
 	<string name="_sys_et_txt_subject_forgot"><![CDATA[Reset your password]]></string>
 	<string name="_sys_et_txt_subject_mem_changed"><![CDATA[Your membership level was changed]]></string>

+ 11 - 1
modules/boonex/russian/data/langs/system/ru.xml

@@ -1573,7 +1573,7 @@
     <string name="_adm_stg_inf_option_smart_app_banner"><![CDATA[]]></string>
     <string name="_adm_stg_cpt_option_smart_app_banner_ios_app_id"><![CDATA[Идентификатор iOS прилижения для Smart App Banner]]></string>
     <string name="_adm_stg_inf_option_smart_app_banner_ios_app_id"><![CDATA[]]></string>
-    <string name="_adm_stg_cpt_option_sys_account_activation_letter"><![CDATA[Включить сообщение об активации аккаунта]]></string>
+    <string name="_adm_stg_cpt_option_sys_account_welcome_letter"><![CDATA[Включить приветственное письмо]]></string>
     <string name="_adm_stg_cpt_option_sys_account_confirmation_type"><![CDATA[Аккаунт подтвержден когда]]></string>
     <string name="_adm_stg_cpt_option_sys_account_hide_unconfirmed_accounts"><![CDATA[Скрывать профили у неподтвержденных аккаунтов]]></string>
     <string name="_adm_stg_cpt_option_sys_account_2fa_enable"><![CDATA[Включить двухфакторную аутентификацию]]></string>
@@ -2564,6 +2564,14 @@
 <p>или используя код:</p>
 <p><span class="h3">{conf_code}</span></p>
 <p> </p>
+{email_footer}]]></string>
+    <string name="_sys_et_txt_body_welcome"><![CDATA[{email_header}
+<p>Привет, {name} ({email}).</p>
+<p>Добро пожаловать в {site_name}</p>
+<p> </p>
+<p>Вы подтвердили свой профиль и готовы пользоваться нашим сайтом.</p>
+<p>Не стесняйтесь обращаться к нам, если вам понадобится помощь.</p>
+<p> </p>
 {email_footer}]]></string>
     <string name="_sys_et_txt_body_delayed_module_uninstall"><![CDATA[{email_header}
 <p>Модуль: <b>{Module}</b></p>
@@ -2672,6 +2680,7 @@
 	<string name="_sys_et_txt_name_system_comment_replied"><![CDATA[Сообщение для посылки пользователям, чьи комментарии были отвечены]]></string>
 	<string name="_sys_et_txt_name_system_reported"><![CDATA[Уведомление о новой жалобе]]></string>
 	<string name="_sys_et_txt_name_system_confirmation"><![CDATA[Сообщение для подтверждения эл. адреса профиля]]></string>
+        <string name="_sys_et_txt_name_system_welcome"><![CDATA[Приветственное сообщение]]></string>
 	<string name="_sys_et_txt_name_system_delayed_module_uninstall"><![CDATA[Уведомление об отложенном демонтировании модуля]]></string>
 	<string name="_sys_et_txt_name_system_forgot"><![CDATA[Сообщение о сбросе пароля]]></string>
 	<string name="_sys_et_txt_name_system_mem_changed"><![CDATA[Сообщение для посылки пользователям, чей уровень членства был изменён]]></string>
@@ -2695,6 +2704,7 @@
 	<string name="_sys_et_txt_subject_comment_replied"><![CDATA[{sender_display_name} ответил на Ваш комментарий]]></string>
 	<string name="_sys_et_txt_subject_system_reported"><![CDATA[Уведомление о новой жалобе]]></string>
 	<string name="_sys_et_txt_subject_confirmation"><![CDATA[Пожалуйста, подтвердите свой email. (ОБЯЗАТЕЛЬНО)]]></string>
+        <string name="_sys_et_txt_subject_welcome"><![CDATA[Добро пожаловать в {site_name}]]></string>
 	<string name="_sys_et_txt_subject_delayed_module_uninstall"><![CDATA[Отложенный демонтаж модуля {Module}: {Result}]]></string>
 	<string name="_sys_et_txt_subject_forgot"><![CDATA[Сбросьте свой пароль]]></string>
 	<string name="_sys_et_txt_subject_mem_changed"><![CDATA[Уровень Вашего членства был изменён]]></string>

+ 1 - 1
template/scripts/BxBaseAccountForms.php

@@ -228,7 +228,7 @@ class BxBaseAccountForms extends BxDolProfileForms
         $sStatus = $oProfile->getStatus();
         $isAutoApprove = !$isSetPendingApproval;
         if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove)
-            $oProfile->approve(BX_PROFILE_ACTION_AUTO, $iProfileId, getParam('sys_account_activation_letter') == 'on');
+            $oProfile->approve(BX_PROFILE_ACTION_AUTO, $iProfileId, false);
 
         /**
          * @hooks

+ 2 - 0
template/scripts/BxBaseServiceAccount.php

@@ -944,6 +944,8 @@ class BxBaseServiceAccount extends BxDol
         // login to user's account automatically
         bx_login($aData['account_id'], bx_is_remember_me());
 
+        $oAccount->sendWelcomeEmail();
+
         return (int)$aData['account_id'];
     }
 }