已解决
可以添加好友 获取验证码delete bug 注册 待完成 配合client 实现添加好友后, client gui 好友列表立马回显,
This commit is contained in:
parent
643ee53ee6
commit
c1e7ae4662
22
MP/Body.h
22
MP/Body.h
@ -19,14 +19,22 @@ public:
|
|||||||
body->set_password(password);
|
body->set_password(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
Body(uint64_t target, uint64_t source, const std::string& data) {
|
Body(mp::MP_SUB_TYPE subType, const std::string& account, const std::string& password, const std::string& data) {
|
||||||
body = new mp::body();
|
body = new mp::body();
|
||||||
|
|
||||||
body->set_target(target);
|
body->set_subcommand(subType);
|
||||||
body->set_source(source);
|
body->set_account(account);
|
||||||
|
body->set_password(password);
|
||||||
body->set_data(data);
|
body->set_data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Body(mp::MP_SUB_TYPE subType, const std::string& account) {
|
||||||
|
body = new mp::body();
|
||||||
|
|
||||||
|
body->set_subcommand(subType);
|
||||||
|
body->set_account(account);
|
||||||
|
}
|
||||||
|
|
||||||
Body(mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source, const std::string& data) {
|
Body(mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source, const std::string& data) {
|
||||||
body = new mp::body();
|
body = new mp::body();
|
||||||
|
|
||||||
@ -36,6 +44,14 @@ public:
|
|||||||
body->set_subcommand(subType);
|
body->set_subcommand(subType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Body(mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source) {
|
||||||
|
body = new mp::body();
|
||||||
|
|
||||||
|
body->set_target(target);
|
||||||
|
body->set_source(source);
|
||||||
|
body->set_subcommand(subType);
|
||||||
|
}
|
||||||
|
|
||||||
Body() {
|
Body() {
|
||||||
body = new mp::body();
|
body = new mp::body();
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,32 @@
|
|||||||
|
|
||||||
// 账户或者 手机号|邮箱|账户 请求 登陆注册
|
// 账户或者 手机号|邮箱|账户 请求 登陆注册
|
||||||
Request::Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string& account, const std::string& password) :
|
Request::Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string& account, const std::string& password) :
|
||||||
Mph(type), Body(subType, account, password), Cqi() {
|
Mph(type), Body(subType, account, password), Cqi() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IM 文本聊天请求
|
// IM 文本聊天请求
|
||||||
Request::Request(mp::MP_TYPE type, uint64_t target, uint64_t source, const std::string& data) :
|
Request::Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source, const std::string& data) :
|
||||||
Mph(type), Body(target, source, data), Cqi() {
|
Mph(type), Body(subType, target, source, data), Cqi() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Request::Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source) :
|
||||||
|
Mph(type), Body(subType, target, source), Cqi() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Request::Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType,const std::string &account,
|
||||||
|
const std::string &password,const std::string &data) :
|
||||||
|
Mph(type), Body(subType, account, password, data) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Request::Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string &account) :
|
||||||
|
Mph(type), Body(subType, account), Cqi(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Request::~Request() {
|
Request::~Request() {
|
||||||
delete request;
|
delete request;
|
||||||
}
|
}
|
||||||
@ -43,3 +59,5 @@ std::string Request::packet() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,10 @@
|
|||||||
class Request : public Mph, Body, Cqi {
|
class Request : public Mph, Body, Cqi {
|
||||||
public:
|
public:
|
||||||
Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string& account, const std::string& password);
|
Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string& account, const std::string& password);
|
||||||
Request(mp::MP_TYPE type, uint64_t target, uint64_t source, const std::string& data);
|
Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string& account, const std::string& password, const std::string& data);
|
||||||
|
Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source, const std::string& data);
|
||||||
|
Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, uint64_t target, uint64_t source);
|
||||||
|
Request(mp::MP_TYPE type, mp::MP_SUB_TYPE subType, const std::string& account);
|
||||||
|
|
||||||
~Request() override;
|
~Request() override;
|
||||||
public:
|
public:
|
||||||
|
@ -5,25 +5,19 @@
|
|||||||
#include "CodeController.h"
|
#include "CodeController.h"
|
||||||
|
|
||||||
void CodeController::run(std::shared_ptr<agreement_request> request, std::shared_ptr<agreement_response> response) {
|
void CodeController::run(std::shared_ptr<agreement_request> request, std::shared_ptr<agreement_response> response) {
|
||||||
auto* sri = new mp::sri();
|
mp::sri* sri = nullptr;
|
||||||
|
|
||||||
// 请求验证码
|
// 请求验证码
|
||||||
if (request->m_body.subcommand() == mp::MP_SUB_TYPE::MP_CODE_EMAIL) {
|
if (request->m_body.subcommand() == mp::MP_SUB_TYPE::MP_CODE_EMAIL) {
|
||||||
// 生成验证码
|
// 生成验证码
|
||||||
std::string code = peVerifCodeService.gen_code();
|
std::string code = peVerifCodeService.gen_code();
|
||||||
// 发送验证码至邮
|
// 发送验证码至邮
|
||||||
bool state = peVerifCodeService.send_email(request->m_body.account(), code);
|
sri = peVerifCodeService.send_email(request->m_body.account(), code);
|
||||||
|
if (sri->subcommand() == mp::MP_SUB_TYPE::MP_CODE_SUCCESS) {
|
||||||
if (state) {
|
|
||||||
// 设置session 字段
|
// 设置session 字段
|
||||||
session->set_session(request->m_bev, "code", code);
|
session->set_session(request->m_bev, "code", code);
|
||||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_CODE_SUCCESS);
|
|
||||||
sri->set_msg("验证码已发送");
|
|
||||||
} else {
|
|
||||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_CODE_FAIL);
|
|
||||||
sri->set_msg("未知问题,验证码获取失败");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response->set(sri, request->m_bev);
|
response->set(sri, request->m_bev);
|
||||||
// delete sri;
|
|
||||||
}
|
}
|
||||||
|
@ -66,13 +66,16 @@ bool UserDB::insert_user_friends(uint64_t account, uint64_t friends) {
|
|||||||
conn = LinkDB::safe_grab();
|
conn = LinkDB::safe_grab();
|
||||||
auto q = conn->query("insert into im_user_friends (account, friends, restrictions) "
|
auto q = conn->query("insert into im_user_friends (account, friends, restrictions) "
|
||||||
"values (%1:account, JSON_OBJECT(%2:key, "
|
"values (%1:account, JSON_OBJECT(%2:key, "
|
||||||
"JSON_OBJECT('belong_grouping', 0, 'add_time', %3:time, 'add_source', 0)), '0')");
|
"JSON_OBJECT('belong_grouping', 0, 'username', '用户%4:username', 'add_time', %3:time, 'add_source', 0)), '0')");
|
||||||
|
|
||||||
q.template_defaults[1] = account;
|
q.template_defaults[1] = account;
|
||||||
q.template_defaults[2] = friends == 0 ? account : friends;
|
q.template_defaults[2] = friends == 0 ? account : friends;
|
||||||
q.template_defaults[3] = time(nullptr);
|
q.template_defaults[3] = time(nullptr);
|
||||||
|
q.template_defaults[4] = account;
|
||||||
q.parse();
|
q.parse();
|
||||||
|
|
||||||
|
printf("%s\n", q.str().c_str());
|
||||||
|
|
||||||
auto ret = q.exec();
|
auto ret = q.exec();
|
||||||
|
|
||||||
// 放回链接
|
// 放回链接
|
||||||
@ -126,7 +129,6 @@ std::optional<uint64_t> UserDB::fetch_account() {
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 放回链接
|
// 放回链接
|
||||||
LinkDB::release(conn);
|
LinkDB::release(conn);
|
||||||
return std::strtol(ret[0][0], nullptr,0);
|
return std::strtol(ret[0][0], nullptr,0);
|
||||||
|
@ -8,11 +8,14 @@
|
|||||||
// 查询好友添加权限类型
|
// 查询好友添加权限类型
|
||||||
char UserFriendsDB::select_add_type(uint64_t account) {
|
char UserFriendsDB::select_add_type(uint64_t account) {
|
||||||
conn = LinkDB::safe_grab();
|
conn = LinkDB::safe_grab();
|
||||||
auto query = conn->query("select restrictions from im_user_friends where account=%0:account");
|
auto query = conn->query("select restrictions from im_user_friends where account=%1:account");
|
||||||
|
query.template_defaults[1] = account;
|
||||||
query.parse();
|
query.parse();
|
||||||
|
|
||||||
|
printf("%s\n", query.str().c_str());
|
||||||
|
|
||||||
// 查看添加授权类型 0 直接添加 1 验证问题 2 账户审核
|
// 查看添加授权类型 0 直接添加 1 验证问题 2 账户审核
|
||||||
auto ret = query.store(account)[0][0][0]; // 因为 account 唯一 所以结果 至多一个
|
auto ret = query.store()[0][0][0]; // 因为 account 唯一 所以结果 至多一个
|
||||||
|
|
||||||
// 放回链接
|
// 放回链接
|
||||||
LinkDB::release(conn);
|
LinkDB::release(conn);
|
||||||
@ -101,7 +104,7 @@ std::tuple<bool, std::string> UserFriendsDB::add_friends(uint64_t account, uint6
|
|||||||
|
|
||||||
// 放回链接
|
// 放回链接
|
||||||
LinkDB::release(conn);
|
LinkDB::release(conn);
|
||||||
return {ret, "添加失败"};
|
return {ret, "暂无错误"};
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserFriendsDB::insert_friends_to_be_added(uint64_t account, uint64_t friends) {
|
void UserFriendsDB::insert_friends_to_be_added(uint64_t account, uint64_t friends) {
|
||||||
|
@ -17,7 +17,19 @@ std::string PEVerifCodeService::gen_code() {
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PEVerifCodeService::send_email(const std::string &target_email, const std::string &code) {
|
mp::sri* PEVerifCodeService::send_email(const std::string &target_email, const std::string &code) {
|
||||||
|
sri_clear();
|
||||||
|
|
||||||
emailcode = code == "0" ? emailcode : code;
|
emailcode = code == "0" ? emailcode : code;
|
||||||
return send_email_def(target_email, emailcode);
|
bool state = send_email_def(target_email, emailcode);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
sri->set_subcommand(mp::MP_SUB_TYPE::MP_CODE_SUCCESS);
|
||||||
|
sri->set_msg("验证码已发送");
|
||||||
|
} else {
|
||||||
|
sri->set_subcommand(mp::MP_SUB_TYPE::MP_CODE_FAIL);
|
||||||
|
sri->set_msg("未知问题,验证码获取失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sri;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
class PEVerifCodeService : public Service {
|
class PEVerifCodeService : public Service {
|
||||||
public:
|
public:
|
||||||
std::string gen_code();
|
std::string gen_code();
|
||||||
bool send_email(const std::string& target_email, const std::string& code = "0");
|
mp::sri* send_email(const std::string& target_email, const std::string& code = "0");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string emailcode;
|
std::string emailcode;
|
||||||
|
@ -22,9 +22,11 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
mp::sri* sri;
|
mp::sri* sri;
|
||||||
|
std::mutex mutex;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void sri_clear(){
|
virtual void sri_clear(){
|
||||||
|
mutex.lock();
|
||||||
sri->clear_subcommand();
|
sri->clear_subcommand();
|
||||||
sri->clear_account();
|
sri->clear_account();
|
||||||
sri->clear_username();
|
sri->clear_username();
|
||||||
@ -33,6 +35,7 @@ protected:
|
|||||||
sri->clear_token();
|
sri->clear_token();
|
||||||
sri->clear_msg();
|
sri->clear_msg();
|
||||||
sri->clear_data();
|
sri->clear_data();
|
||||||
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,16 +48,13 @@ mp::sri* UserFriendsService::add_contact_person(mp::body *body) {
|
|||||||
}
|
}
|
||||||
// 回答问题
|
// 回答问题
|
||||||
else if (type == '1') {
|
else if (type == '1') {
|
||||||
if ("") {
|
// 取数据库中的问题 返回类型添加一个 mp::MP_SUB_TYPE::MP_ADD_XXX
|
||||||
add_friends(body);
|
sri->set_subcommand(mp::MP_SUB_TYPE::MP_ADD_SUCCESS);
|
||||||
} else {
|
sri->set_msg("xxxx");
|
||||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_ADD_FAIL);
|
|
||||||
sri->set_msg("答案错误");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 账户审核
|
// 账户审核
|
||||||
else if (type == '2') {
|
else if (type == '2') {
|
||||||
|
// 添加 用户的带添加段内
|
||||||
}
|
}
|
||||||
|
|
||||||
return sri;
|
return sri;
|
||||||
|
@ -127,7 +127,7 @@ mp::sri *UserService::register_(mp::MP_SUB_TYPE subType, const std::string &phon
|
|||||||
bool UserService::register_(uint64_t account, const std::string &password) {
|
bool UserService::register_(uint64_t account, const std::string &password) {
|
||||||
// 查看账户是否存在
|
// 查看账户是否存在
|
||||||
auto exist = userDb.select_user_exist(account);
|
auto exist = userDb.select_user_exist(account);
|
||||||
if (!exist) {
|
if (exist) {
|
||||||
sri->set_msg("账户已经存在");
|
sri->set_msg("账户已经存在");
|
||||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_REGISTER_FAIL);
|
sri->set_subcommand(mp::MP_SUB_TYPE::MP_REGISTER_FAIL);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user