2010-12-02 03:36:49 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-11-21 12:03:53 +01:00
|
|
|
* Copyright (c) 2008-2018, Tomasz Sowa
|
2010-12-02 03:36:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2010-12-02 03:36:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "notify.h"
|
|
|
|
#include "templates/templates.h"
|
|
|
|
#include "core/request.h"
|
|
|
|
#include "core/config.h"
|
|
|
|
#include "core/users.h"
|
|
|
|
#include "core/dirs.h"
|
2010-12-06 01:25:46 +01:00
|
|
|
#include "core/plugin.h"
|
2010-12-02 03:36:49 +01:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
2010-12-02 03:36:49 +01:00
|
|
|
|
|
|
|
|
2010-12-07 13:52:52 +01:00
|
|
|
Notify::Notify()
|
2010-12-02 03:36:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
void Notify::SetCur(Cur * pcur)
|
2010-12-02 03:36:49 +01:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur = pcur;
|
2010-12-02 03:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
//void Notify::SetConfig(Config * pconfig)
|
|
|
|
//{
|
|
|
|
// config = pconfig;
|
|
|
|
//}
|
2010-12-02 03:36:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Notify::SetUsers(Users * pusers)
|
|
|
|
{
|
|
|
|
users = pusers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notify::SetDirs(Dirs * pdirs)
|
|
|
|
{
|
|
|
|
dirs = pdirs;
|
|
|
|
}
|
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
void Notify::SetThreadManager(ThreadManager * pmanager)
|
|
|
|
{
|
|
|
|
thread_manager = pmanager;
|
|
|
|
}
|
2010-12-02 03:36:49 +01:00
|
|
|
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
|
|
|
|
//void Notify::SetFileLog(FileLog * file_log)
|
|
|
|
//{
|
|
|
|
// this->file_log = file_log;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-02 03:36:49 +01:00
|
|
|
void Notify::Init()
|
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
//notify_thread.SetConfig(config);
|
2010-12-02 03:36:49 +01:00
|
|
|
notify_thread.SetUsers(users);
|
|
|
|
notify_thread.SetNotifyPool(¬ify_pool);
|
|
|
|
notify_thread.SetPatterns(&patterns);
|
2018-11-21 12:03:53 +01:00
|
|
|
//notify_thread.SetFileLog(file_log);
|
2012-05-19 19:04:33 +02:00
|
|
|
thread_manager->Add(¬ify_thread, L"notifications");
|
2010-12-02 03:36:49 +01:00
|
|
|
|
2011-08-26 01:53:49 +02:00
|
|
|
patterns.SetDirectories(config->txt_templates_dir, config->txt_templates_dir_default);
|
|
|
|
patterns.SetLocale(&TemplatesFunctions::locale);
|
|
|
|
patterns.SetLocaleFilter(&TemplatesFunctions::locale_filter);
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
notify_template_cms = AddTemplate(L"notify_email_cms.txt");
|
|
|
|
notify_template_activate_account = AddTemplate(L"notify_confirm_account.txt");
|
2012-03-09 23:56:54 +01:00
|
|
|
notify_template_reset_password = AddTemplate(L"notify_reset_password.txt");
|
2010-12-06 01:25:46 +01:00
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
plugin->Call((Session*)0, WINIX_NOTIFY_ADD_TEMPLATE);
|
2010-12-02 03:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Notify::ReadTemplates()
|
|
|
|
{
|
2011-08-26 01:53:49 +02:00
|
|
|
patterns.Reload();
|
2010-12-02 03:36:49 +01:00
|
|
|
notify_thread.PatternsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Notify::ItemChanged(int notify_code, const Item & item)
|
|
|
|
{
|
|
|
|
if( notify_code == 0 )
|
|
|
|
return;
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
msg.Clear();
|
2010-12-02 03:36:49 +01:00
|
|
|
msg.code = notify_code;
|
2011-01-26 13:45:38 +01:00
|
|
|
msg.template_index = notify_template_cms;
|
2010-12-02 03:36:49 +01:00
|
|
|
CreateItemLink(item, msg.item_link, msg.dir_link);
|
|
|
|
|
2010-12-06 01:25:46 +01:00
|
|
|
ItemChanged(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// raw form
|
|
|
|
void Notify::ItemChanged(const NotifyMsg & msg)
|
|
|
|
{
|
2010-12-02 03:36:49 +01:00
|
|
|
notify_pool.Add(msg);
|
2010-12-07 13:52:52 +01:00
|
|
|
notify_thread.WakeUpThread(); // we are in the first locked thread
|
2010-12-02 03:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
void Notify::ActivateAccount(const std::wstring & name, const std::wstring & email, long code)
|
|
|
|
{
|
|
|
|
msg.Clear();
|
|
|
|
msg.code = WINIX_NOTIFY_CODE_CONFIRM_ACCOUNT;
|
|
|
|
msg.name = name;
|
|
|
|
msg.email = email;
|
2013-05-16 23:02:17 +02:00
|
|
|
msg.lang = config->locale_default_id;
|
2012-02-28 22:09:44 +01:00
|
|
|
msg.activate_code = code;
|
|
|
|
msg.template_index = notify_template_activate_account;
|
|
|
|
CreateActivateLink(name, code, msg.item_link);
|
|
|
|
|
|
|
|
notify_pool.Add(msg);
|
|
|
|
notify_thread.WakeUpThread(); // we are in the first locked thread
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-09 23:56:54 +01:00
|
|
|
void Notify::ResetPassword(const std::wstring & name, const std::wstring & email, long code)
|
|
|
|
{
|
|
|
|
msg.Clear();
|
|
|
|
msg.code = WINIX_NOTIFY_CODE_RESET_PASSWORD;
|
|
|
|
msg.name = name;
|
|
|
|
msg.email = email;
|
2013-05-16 23:02:17 +02:00
|
|
|
msg.lang = config->locale_default_id; // !! IMPROVE ME a better language can be chose (the same as the user has)
|
2012-03-09 23:56:54 +01:00
|
|
|
msg.activate_code = code;
|
|
|
|
msg.template_index = notify_template_reset_password;
|
|
|
|
CreateResetPasswordLink(name, code, msg.item_link);
|
|
|
|
|
|
|
|
notify_pool.Add(msg);
|
|
|
|
notify_thread.WakeUpThread(); // we are in the first locked thread
|
|
|
|
}
|
|
|
|
|
2010-12-02 03:36:49 +01:00
|
|
|
|
|
|
|
size_t Notify::AddTemplate(const std::wstring & file_name)
|
|
|
|
{
|
2011-08-26 01:53:49 +02:00
|
|
|
return patterns.Add(file_name, false);
|
2010-12-02 03:36:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Notify::CreateItemLink(const Item & item, std::wstring & item_link, std::wstring & dir_link)
|
|
|
|
{
|
2012-02-28 22:09:44 +01:00
|
|
|
tmp_path.clear();
|
2010-12-02 03:36:49 +01:00
|
|
|
|
|
|
|
if( item.type == Item::dir )
|
|
|
|
{
|
|
|
|
dirs->MakePath(item.id, tmp_path);
|
2011-08-18 01:09:47 +02:00
|
|
|
item_link = config->url_proto;
|
2012-04-22 20:23:44 +02:00
|
|
|
item_link += config->base_url; // !! IMPROVE ME what about subdomains?
|
2010-12-02 03:36:49 +01:00
|
|
|
item_link += tmp_path;
|
|
|
|
dir_link = item_link;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dirs->MakePath(item.parent_id, tmp_path);
|
2011-08-18 01:09:47 +02:00
|
|
|
item_link = config->url_proto;
|
2012-04-22 20:23:44 +02:00
|
|
|
item_link += config->base_url; // !! IMPROVE ME what about subdomains?
|
2010-12-02 03:36:49 +01:00
|
|
|
item_link += tmp_path;
|
|
|
|
dir_link = item_link;
|
|
|
|
item_link += item.url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
void Notify::CreateActivateLink(const std::wstring & name, long code, std::wstring & link)
|
|
|
|
{
|
|
|
|
wchar_t buff[50];
|
|
|
|
|
|
|
|
link = config->url_proto;
|
2012-04-22 20:23:44 +02:00
|
|
|
link += config->base_url;// !! IMPROVE ME what about subdomains?
|
2013-05-16 21:26:44 +02:00
|
|
|
link += L"/account/activate/login:";
|
2012-02-28 22:09:44 +01:00
|
|
|
UrlEncode(name, link, false);
|
|
|
|
link += L"/code:";
|
|
|
|
Toa(code, buff, sizeof(buff)/sizeof(wchar_t));
|
|
|
|
link += buff;
|
|
|
|
}
|
2012-03-09 23:56:54 +01:00
|
|
|
|
|
|
|
void Notify::CreateResetPasswordLink(const std::wstring & name, long code, std::wstring & link)
|
|
|
|
{
|
|
|
|
wchar_t buff[50];
|
|
|
|
|
|
|
|
link = config->url_proto;
|
2012-04-22 20:23:44 +02:00
|
|
|
link += config->base_url;// !! IMPROVE ME what about subdomains?
|
2013-05-16 21:26:44 +02:00
|
|
|
link += L"/passwd/resetpassword/login:";
|
2012-03-09 23:56:54 +01:00
|
|
|
UrlEncode(name, link, false);
|
|
|
|
link += L"/code:";
|
|
|
|
Toa(code, buff, sizeof(buff)/sizeof(wchar_t));
|
|
|
|
link += buff;
|
|
|
|
}
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|