Skip to content

Commit cc73fee

Browse files
committed
继续完善
1 parent 05d59be commit cc73fee

10 files changed

Lines changed: 114 additions & 49 deletions

File tree

‎kbe/src/lib/cstdkbe/platform.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
5757
#include <windows.h>
5858
#include <unordered_map>
5959
#include <functional>
60+
#include <regex>
6061
#else
6162
// linux include
6263
#include <errno.h>
@@ -78,6 +79,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
7879
#include <tr1/unordered_map>
7980
#include <tr1/functional>
8081
#include <tr1/memory>
82+
#include <tr1/regex>
8183
#include <linux/types.h>
8284
#include <sys/time.h>
8385
#include <sys/types.h>

‎kbe/src/lib/db_mysql/kbe_table_mysql.cpp‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ KBEEmailVerificationTableMysql::~KBEEmailVerificationTableMysql()
451451
}
452452

453453
//-------------------------------------------------------------------------------------
454-
bool KBEEmailVerificationTableMysql::queryAccount(DBInterface * dbi, const std::string& name, ACCOUNT_INFOS& info)
454+
bool KBEEmailVerificationTableMysql::queryAccount(DBInterface * dbi, int8 type, const std::string& name, ACCOUNT_INFOS& info)
455455
{
456456
std::string sqlstr = "select code, datas from kbe_email_verification where accountName like \"";
457457

@@ -487,7 +487,7 @@ bool KBEEmailVerificationTableMysql::queryAccount(DBInterface * dbi, const std::
487487
}
488488

489489
//-------------------------------------------------------------------------------------
490-
bool KBEEmailVerificationTableMysql::logAccount(DBInterface * dbi, ACCOUNT_INFOS& info)
490+
bool KBEEmailVerificationTableMysql::logAccount(DBInterface * dbi, int8 type, ACCOUNT_INFOS& info)
491491
{
492492
std::string sqlstr = "insert into kbe_email_verification (accountName, datas, code, logtime) values(";
493493

@@ -562,7 +562,7 @@ bool KBEEmailVerificationTableMysql::activateAccount(DBInterface * dbi, const st
562562
mysql_free_result(pResult);
563563
}
564564

565-
if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailServerInfo_.deadline)
565+
if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailAtivationInfo_.deadline)
566566
return false;
567567

568568
if(info.name.size() == 0)
@@ -630,7 +630,7 @@ bool KBEEmailVerificationTableMysql::activateAccount(DBInterface * dbi, const st
630630

631631
try
632632
{
633-
delAccount(dbi, info.name);
633+
delAccount(dbi, (int8)V_TYPE_CREATEACCOUNT, info.name);
634634
}
635635
catch (...)
636636
{
@@ -640,7 +640,7 @@ bool KBEEmailVerificationTableMysql::activateAccount(DBInterface * dbi, const st
640640
}
641641

642642
//-------------------------------------------------------------------------------------
643-
bool KBEEmailVerificationTableMysql::delAccount(DBInterface * dbi, const std::string& name)
643+
bool KBEEmailVerificationTableMysql::delAccount(DBInterface * dbi, int8 type, const std::string& name)
644644
{
645645
std::string sqlstr = "delete from kbe_email_verification where accountName=";
646646

@@ -651,8 +651,12 @@ bool KBEEmailVerificationTableMysql::delAccount(DBInterface * dbi, const std::st
651651

652652
sqlstr += "\"";
653653
sqlstr += tbuf;
654-
sqlstr += "\"";
654+
sqlstr += "\", and type=";
655655

656+
kbe_snprintf(tbuf, MAX_BUF, "%d", type);
657+
sqlstr += tbuf;
658+
sqlstr += ")";
659+
656660
SAFE_RELEASE_ARRAY(tbuf);
657661

658662
if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
@@ -668,6 +672,7 @@ bool KBEEmailVerificationTableMysql::syncToDB(DBInterface* dbi)
668672

669673
std::string sqlstr = "CREATE TABLE IF NOT EXISTS kbe_email_verification "
670674
"(accountName varchar(255) not null,"
675+
"type tinyint not null DEFAULT 0,"
671676
"datas varchar(255),"
672677
"code varchar(255), PRIMARY KEY idKey (code),"
673678
"logtime bigint(20) not null DEFAULT 0)"
@@ -676,9 +681,19 @@ bool KBEEmailVerificationTableMysql::syncToDB(DBInterface* dbi)
676681
ret = dbi->query(sqlstr.c_str(), sqlstr.size(), true);
677682
KBE_ASSERT(ret);
678683

679-
// 删除24小时之前的记录
680-
sqlstr = "delete from kbe_email_verification where logtime<";
681-
sqlstr += KBEngine::StringConv::val2str(time(NULL) - g_kbeSrvConfig.emailServerInfo_.deadline);
684+
// 删除xx小时之前的记录
685+
sqlstr = (boost::format("delete from kbe_email_verification where logtime<%1% and type=%2%") %
686+
KBEngine::StringConv::val2str(time(NULL) - g_kbeSrvConfig.emailAtivationInfo_.deadline) %
687+
((int8)KBEEmailVerificationTable::V_TYPE_CREATEACCOUNT)).str();
688+
689+
sqlstr = (boost::format("delete from kbe_email_verification where logtime<%1% and type=%2%") %
690+
KBEngine::StringConv::val2str(time(NULL) - g_kbeSrvConfig.emailResetPasswordInfo_.deadline) %
691+
((int8)KBEEmailVerificationTable::V_TYPE_RESETPASSWORD)).str();
692+
693+
sqlstr = (boost::format("delete from kbe_email_verification where logtime<%1% and type=%2%") %
694+
KBEngine::StringConv::val2str(time(NULL) - g_kbeSrvConfig.emailBindInfo_.deadline) %
695+
((int8)KBEEmailVerificationTable::V_TYPE_BIND_MAIL)).str();
696+
682697
ret = dbi->query(sqlstr.c_str(), sqlstr.size(), true);
683698
KBE_ASSERT(ret);
684699
return ret;

‎kbe/src/lib/db_mysql/kbe_table_mysql.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class KBEEntityTypeMysql : public KBEEntityType
9191
class KBEEmailVerificationTableMysql : public KBEEmailVerificationTable
9292
{
9393
public:
94+
9495
KBEEmailVerificationTableMysql();
9596
virtual ~KBEEmailVerificationTableMysql();
9697

@@ -99,9 +100,9 @@ class KBEEmailVerificationTableMysql : public KBEEmailVerificationTable
99100
*/
100101
virtual bool syncToDB(DBInterface* dbi);
101102

102-
virtual bool queryAccount(DBInterface * dbi, const std::string& name, ACCOUNT_INFOS& info);
103-
virtual bool logAccount(DBInterface * dbi, ACCOUNT_INFOS& info);
104-
virtual bool delAccount(DBInterface * dbi, const std::string& name);
103+
virtual bool queryAccount(DBInterface * dbi, int8 type, const std::string& name, ACCOUNT_INFOS& info);
104+
virtual bool logAccount(DBInterface * dbi, int8 type, ACCOUNT_INFOS& info);
105+
virtual bool delAccount(DBInterface * dbi, int8 type, const std::string& name);
105106
virtual bool activateAccount(DBInterface * dbi, const std::string& code, ACCOUNT_INFOS& info);
106107
protected:
107108
};

‎kbe/src/lib/dbmgr_lib/kbe_tables.hpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ class KBEEntityType : public KBETable
146146
class KBEEmailVerificationTable : public KBETable
147147
{
148148
public:
149+
enum V_TYPE
150+
{
151+
V_TYPE_CREATEACCOUNT = 1,
152+
V_TYPE_RESETPASSWORD = 2,
153+
V_TYPE_BIND_MAIL = 3
154+
};
155+
149156
KBEEmailVerificationTable():
150157
KBETable()
151158
{
@@ -156,9 +163,9 @@ class KBEEmailVerificationTable : public KBETable
156163
{
157164
}
158165

159-
virtual bool queryAccount(DBInterface * dbi, const std::string& name, ACCOUNT_INFOS& info) = 0;
160-
virtual bool logAccount(DBInterface * dbi, ACCOUNT_INFOS& info) = 0;
161-
virtual bool delAccount(DBInterface * dbi, const std::string& name) = 0;
166+
virtual bool queryAccount(DBInterface * dbi, int8 type, const std::string& name, ACCOUNT_INFOS& info) = 0;
167+
virtual bool logAccount(DBInterface * dbi, int8 type, ACCOUNT_INFOS& info) = 0;
168+
virtual bool delAccount(DBInterface * dbi, int8 type, const std::string& name) = 0;
162169
virtual bool activateAccount(DBInterface * dbi, const std::string& code, ACCOUNT_INFOS& info) = 0;
163170
protected:
164171
};

‎kbe/src/lib/server/serverconfig.cpp‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ bool ServerConfig::loadConfig(std::string fileName)
187187
if(childnode)
188188
emailServerInfo_.smtp_auth = xml->getValInt(childnode);
189189

190-
childnode = xml->enterNode(rootNode, "deadline");
190+
childnode = xml->enterNode(rootNode, "cb_port");
191191
if(childnode)
192-
emailServerInfo_.deadline = xml->getValInt(childnode);
192+
emailServerInfo_.cb_port = xml->getValInt(childnode);
193193

194194
TiXmlNode* rootNode1 = xml->enterNode(rootNode, "email_activation");
195195
if(rootNode1 != NULL)
@@ -202,25 +202,41 @@ bool ServerConfig::loadConfig(std::string fileName)
202202
if(childnode1)
203203
emailAtivationInfo_.message = childnode1->ToText()->Value();
204204

205-
childnode1 = xml->enterNode(rootNode1, "cb_port");
205+
childnode1 = xml->enterNode(rootNode1, "deadline");
206206
if(childnode1)
207-
emailAtivationInfo_.cb_port = xml->getValInt(childnode1);
207+
emailAtivationInfo_.deadline = xml->getValInt(childnode1);
208208
}
209209

210210
rootNode1 = xml->enterNode(rootNode, "email_resetpassword");
211211
if(rootNode1 != NULL)
212212
{
213213
TiXmlNode* childnode1 = xml->enterNode(rootNode1, "subject");
214214
if(childnode1)
215-
emailResetPassword_.subject = childnode1->ToText()->Value();
215+
emailResetPasswordInfo_.subject = childnode1->ToText()->Value();
216216

217217
childnode1 = xml->enterNode(rootNode1, "message");
218218
if(childnode1)
219-
emailResetPassword_.message = childnode1->ToText()->Value();
219+
emailResetPasswordInfo_.message = childnode1->ToText()->Value();
220220

221-
childnode1 = xml->enterNode(rootNode1, "cb_port");
221+
childnode1 = xml->enterNode(rootNode1, "deadline");
222222
if(childnode1)
223-
emailResetPassword_.cb_port = xml->getValInt(childnode1);
223+
emailResetPasswordInfo_.deadline = xml->getValInt(childnode1);
224+
}
225+
226+
rootNode1 = xml->enterNode(rootNode, "email_bind");
227+
if(rootNode1 != NULL)
228+
{
229+
TiXmlNode* childnode1 = xml->enterNode(rootNode1, "subject");
230+
if(childnode1)
231+
emailBindInfo_.subject = childnode1->ToText()->Value();
232+
233+
childnode1 = xml->enterNode(rootNode1, "message");
234+
if(childnode1)
235+
emailBindInfo_.message = childnode1->ToText()->Value();
236+
237+
childnode1 = xml->enterNode(rootNode1, "deadline");
238+
if(childnode1)
239+
emailBindInfo_.deadline = xml->getValInt(childnode1);
224240
}
225241
}
226242

‎kbe/src/lib/server/serverconfig.hpp‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,14 @@ struct EmailServerInfo
8686
std::string username;
8787
std::string password;
8888
uint8 smtp_auth;
89-
uint32 deadline;
90-
};
91-
92-
struct EmailAtivationInfo
93-
{
94-
std::string subject;
95-
std::string message;
9689
uint32 cb_port;
9790
};
9891

99-
struct EmailResetPassword
92+
struct EmailSendInfo
10093
{
10194
std::string subject;
10295
std::string message;
103-
uint32 cb_port;
96+
uint32 deadline;
10497
};
10598

10699
// 引擎组件信息结构体
@@ -276,9 +269,9 @@ class ServerConfig : public Singleton<ServerConfig>
276269
uint32 thread_init_create_, thread_pre_create_, thread_max_create_;
277270

278271
EmailServerInfo emailServerInfo_;
279-
EmailAtivationInfo emailAtivationInfo_;
280-
EmailResetPassword emailResetPassword_;
281-
272+
EmailSendInfo emailAtivationInfo_;
273+
EmailSendInfo emailResetPasswordInfo_;
274+
EmailSendInfo emailBindInfo_;
282275

283276
};
284277

‎kbe/src/server/dbmgr/dbtasks.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ You should have received a copy of the GNU Lesser General Public License
1818
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <regex>
2221
#include "dbtasks.hpp"
2322
#include "dbmgr.hpp"
2423
#include "buffered_dbtasks.hpp"
@@ -532,7 +531,7 @@ bool DBTaskCreateMailAccount::db_thread_process()
532531
{
533532
}
534533

535-
success_ = pTable1->logAccount(pdbi_, info);
534+
success_ = pTable1->logAccount(pdbi_, (int8)KBEEmailVerificationTable::V_TYPE_CREATEACCOUNT, info);
536535
return false;
537536
}
538537

‎kbe/src/server/loginapp/account_activate_handler.cpp‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ clients_()
4545
return;
4646
}
4747

48-
if (pEndPoint_->bind(htons(g_kbeSrvConfig.emailAtivationInfo_.cb_port),
48+
if (pEndPoint_->bind(htons(g_kbeSrvConfig.emailServerInfo_.cb_port),
4949
Loginapp::getSingleton().getNetworkInterface().extaddr().ip) == -1)
5050
{
5151
ERROR_MSG(boost::format("AccountActivateHandler::bind(%1%): \n") %
@@ -70,7 +70,7 @@ clients_()
7070

7171
INFO_MSG(boost::format("AccountActivateHandler::bind: %1%:%2%\n") %
7272
inet_ntoa((struct in_addr&)Loginapp::getSingleton().getNetworkInterface().extaddr().ip) %
73-
g_kbeSrvConfig.emailAtivationInfo_.cb_port);
73+
g_kbeSrvConfig.emailServerInfo_.cb_port);
7474
}
7575

7676
//-------------------------------------------------------------------------------------
@@ -135,14 +135,44 @@ int AccountActivateHandler::handleInputNotification(int fd)
135135
if(client.state == 1)
136136
clients_.erase(iter);
137137

138+
int type = 0;
139+
std::string keys = "accountactivate?";
138140
std::string s = buffer;
139-
std::string::size_type fi1 = s.find("accountactivate?");
141+
std::string::size_type fi1 = s.find(keys);
142+
if(fi1 == std::string::npos)
143+
{
144+
keys = "resetpassword?";
145+
fi1 = s.find(keys);
146+
if(fi1 == std::string::npos)
147+
{
148+
keys = "bindmail?";
149+
fi1 = s.find(keys);
150+
if(fi1 != std::string::npos)
151+
{
152+
type = 3;
153+
}
154+
}
155+
else
156+
{
157+
type = 2;
158+
}
159+
}
160+
else
161+
{
162+
type = 1;
163+
}
164+
140165
std::string::size_type fi2 = s.find(" HTTP/");
166+
167+
if(fi2 <= fi1)
168+
{
169+
return 0;
170+
}
141171

142172
std::string code;
143173
if(fi1 != std::string::npos && fi2 != std::string::npos)
144174
{
145-
int ilen = strlen("accountactivate?");
175+
int ilen = keys.size();
146176
code.assign(s.c_str() + fi1 + ilen, fi2 - (fi1 + ilen));
147177
}
148178

@@ -167,11 +197,14 @@ int AccountActivateHandler::handleInputNotification(int fd)
167197
return 0;
168198
}
169199

170-
// Ïòdbmgr¼¤»îÕ˺Å
171-
Mercury::Bundle bundle;
172-
bundle.newMessage(DbmgrInterface::accountActivate);
173-
bundle << code;
174-
bundle.send(Loginapp::getSingleton().getNetworkInterface(), dbmgrinfos->pChannel);
200+
if(type == 1)
201+
{
202+
// Ïòdbmgr¼¤»îÕ˺Å
203+
Mercury::Bundle bundle;
204+
bundle.newMessage(DbmgrInterface::accountActivate);
205+
bundle << code;
206+
bundle.send(Loginapp::getSingleton().getNetworkInterface(), dbmgrinfos->pChannel);
207+
}
175208
}
176209
else
177210
{

‎kbe/src/server/loginapp/loginapp.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ You should have received a copy of the GNU Lesser General Public License
1818
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <regex>
2221
#include "jwsmtp.h"
2322
#include "loginapp.hpp"
2423
#include "threadtasks.hpp"
@@ -428,7 +427,7 @@ void Loginapp::onReqCreateMailAccountResult(Mercury::Channel* pChannel, MemorySt
428427
{
429428
threadPool_.addTask(new SendActivateEMailTask(accountName, retdatas,
430429
getNetworkInterface().extEndpoint().addr().ipAsString(),
431-
g_kbeSrvConfig.emailAtivationInfo_.cb_port));
430+
g_kbeSrvConfig.emailServerInfo_.cb_port));
432431
}
433432

434433
PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.remove(accountName);

‎kbe/src/server/loginapp/threadtasks.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SendActivateEMailTask::~SendActivateEMailTask()
3737
//-------------------------------------------------------------------------------------
3838
bool SendActivateEMailTask::process()
3939
{
40-
Deadline maildeadline(g_kbeSrvConfig.emailServerInfo_.deadline);
40+
Deadline maildeadline(g_kbeSrvConfig.emailAtivationInfo_.deadline);
4141
std::wstring wdeadline = maildeadline.wprint();
4242

4343
jwsmtp::mailer m(emailaddr_.c_str(), g_kbeSrvConfig.emailServerInfo_.username.c_str(), g_kbeSrvConfig.emailAtivationInfo_.subject.c_str(),

0 commit comments

Comments
 (0)