主要修复邮箱登陆,
可以根据account搜索用户 添加暂时没做 下一个步 添加 好友
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
#include "IMController.h"
|
||||
|
||||
void IMController::run(std::shared_ptr<agreement_request> request, std::shared_ptr<agreement_response> response) {
|
||||
// msg push 储存库内
|
||||
if (request->m_mph->mp_type() == mp::MP_IM_PUSH_MSG) {
|
||||
|
||||
} else if (request->m_mph->mp_type() == mp::MP_IM_MSG) {
|
||||
}
|
||||
// 传来 im msg
|
||||
else if (request->m_mph->mp_type() == mp::MP_IM_MSG) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef IM2_DB_H
|
||||
#define IM2_DB_H
|
||||
|
||||
|
||||
#include <mysql++.h>
|
||||
|
||||
class DB {
|
||||
|
||||
@@ -3,16 +3,27 @@
|
||||
//
|
||||
|
||||
#include "UserDB.h"
|
||||
#include "template_table/im_user.h"
|
||||
#include "template_table/template_struct.h"
|
||||
|
||||
|
||||
/// 0505 19:34 im_user 重定义
|
||||
|
||||
// select user info
|
||||
std::tuple<bool, PoUser> UserDB::select_user(uint64_t account, const std::string& by_field) {
|
||||
std::tuple<bool, PoUser> UserDB::select_user(const std::string& account, const std::string& by_field) {
|
||||
// 取池链接
|
||||
conn = LinkDB::safe_grab();
|
||||
auto query = conn->query("select * from im_user where %2:field=%1:account;");
|
||||
query.template_defaults[1] = account;
|
||||
|
||||
std::string sql;
|
||||
if (by_field == "account" || by_field == "phone") {
|
||||
sql = "select * from im_user where %2:field=%1:account;";
|
||||
} else {
|
||||
sql = "select * from im_user where %2:field=%1q:account;";
|
||||
}
|
||||
|
||||
auto query = conn->query(sql);
|
||||
query.template_defaults[1] = strtol(account.c_str(), nullptr, 0);
|
||||
query.template_defaults[1] = account.c_str();
|
||||
|
||||
query.template_defaults[2] = by_field.c_str();
|
||||
query.parse();
|
||||
|
||||
@@ -29,7 +40,7 @@ std::tuple<bool, PoUser> UserDB::select_user(uint64_t account, const std::string
|
||||
|
||||
// select key account is existed by account
|
||||
bool UserDB::select_user_exist(uint64_t account) {
|
||||
auto [exist, PoUser] = select_user(account, "account");
|
||||
auto [exist, PoUser] = select_user(std::to_string(account), "account");
|
||||
return exist;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class UserDB : public DB {
|
||||
/// login ...
|
||||
public:
|
||||
// 查询用户
|
||||
std::tuple<bool, PoUser> select_user(uint64_t account, const std::string& by_field);
|
||||
std::tuple<bool, PoUser> select_user(const std::string& account, const std::string& by_field);
|
||||
// 查询用户是否存在
|
||||
bool select_user_exist(uint64_t account);
|
||||
// 添加用户
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
// Created by dongl on 23-5-4.
|
||||
//
|
||||
|
||||
#include "UserFriendsDB.h"
|
||||
#include "linkDB.h"
|
||||
|
||||
#include "UserFriendsDB.h"
|
||||
|
||||
// 查询好友添加权限类型
|
||||
char UserFriendsDB::select_add_type(uint64_t account) {
|
||||
@@ -20,6 +19,34 @@ char UserFriendsDB::select_add_type(uint64_t account) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 搜索好友 搜索用户
|
||||
std::optional<PoUser> UserFriendsDB::select_friends(uint64_t account) {
|
||||
conn = LinkDB::safe_grab();
|
||||
auto query = conn->query("select * from im_user where account=%1:account");
|
||||
query.template_defaults[1] = account;
|
||||
query.parse();
|
||||
|
||||
PoUser user;
|
||||
|
||||
auto ret = query.store();
|
||||
for (const auto &row : ret) {
|
||||
user.account = strtol(row[0].c_str(), nullptr, 0);
|
||||
user.phone = strtol(row[1].c_str(), nullptr, 0);
|
||||
user.email = row[2].c_str();
|
||||
user.username = row[3].c_str();
|
||||
user.password = row[4].c_str();
|
||||
user.password_salt = row[5].c_str();
|
||||
user.client_info = row[6].c_str();
|
||||
}
|
||||
|
||||
// 放回链接
|
||||
LinkDB::release(conn);
|
||||
if (ret.num_rows() < 1) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
// 修改好友列表数据 添加好友
|
||||
/// friends :{
|
||||
/// uid :info { }
|
||||
@@ -140,3 +167,5 @@ UserFriendsDB::select_friends_info(uint64_t account, uint64_t friends) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,15 @@
|
||||
#include <optional>
|
||||
|
||||
#include "DB.h"
|
||||
#include "../../../MP/proto/mp.sri.pb.h"
|
||||
#include "../../../MP/proto/mp.body.pb.h"
|
||||
#include "po/po.h"
|
||||
#include "document.h"
|
||||
|
||||
class UserFriendsDB : public DB {
|
||||
public:
|
||||
// 查询添加类型
|
||||
char select_add_type(uint64_t account);
|
||||
// 查询用户 搜索好友
|
||||
std::optional<PoUser> select_friends(uint64_t account);
|
||||
// 添加好友
|
||||
std::tuple<bool, std::string> add_friends(uint64_t source, uint64_t target);
|
||||
// 查询全部好友 好友列表
|
||||
|
||||
@@ -14,7 +14,7 @@ mp::sri *UserFriendsService::friendImProve(mp::body* body) {
|
||||
|
||||
// 搜索
|
||||
if (subcommand == mp::MP_SUB_TYPE::MP_SEARCH_FRIENDS_ACCOUNT) {
|
||||
FetchUserFriends(strtol(body->account().c_str(), nullptr, 0), "");
|
||||
FetchUser(strtol(body->account().c_str(), nullptr, 0));
|
||||
}
|
||||
// 添加
|
||||
else if (subcommand == mp::MP_SUB_TYPE::MP_ADD_FRIENDS_ACCOUNT) {
|
||||
@@ -91,15 +91,14 @@ void UserFriendsService::FetchUserFriends(uint64_t account, const std::string &d
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索指定账户信息
|
||||
/// MP_REQUEST_FRIENDS MP_SEARCH_FRIENDS_ACCOUNT
|
||||
// 搜索指定账户信息 搜索可添加好友
|
||||
void UserFriendsService::FetchUser(uint64_t account) {
|
||||
// 后续撤掉userDB 在 userfriendsDB内 添加account模糊搜索
|
||||
auto [state, user] = userDB.select_user(account, "account");
|
||||
if (state) {
|
||||
sri->set_username(user.username);
|
||||
sri->set_account(user.account);
|
||||
sri->set_phone(user.phone);
|
||||
sri->set_email(user.email);
|
||||
auto userinfo = userFriendsDb.select_friends(account);
|
||||
if (userinfo.has_value()) {
|
||||
sri->set_username(userinfo.value().username);
|
||||
sri->set_account(userinfo.value().account);
|
||||
sri->set_email(userinfo.value().email);
|
||||
sri->set_msg("搜索成功");
|
||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_SEARCH_SUCCESS);
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,6 @@ private:
|
||||
|
||||
private:
|
||||
UserFriendsDB userFriendsDb = UserFriendsDB();
|
||||
UserDB userDB = UserDB();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
//
|
||||
|
||||
#include "UserService.h"
|
||||
#include "handler.h"
|
||||
#include <experimental/random>
|
||||
|
||||
///************************************************* 登陆 ***********************************************************///
|
||||
@@ -29,7 +28,7 @@ mp::sri* UserService::login(mp::MP_SUB_TYPE subType, const std::string& account
|
||||
void UserService::login_fun(const std::string& account, const std::string& password, const std::string& filed) {
|
||||
|
||||
// 判断密码
|
||||
auto [exist, user] = userDb.select_user(strtol(account.c_str(), nullptr, 0), filed);
|
||||
auto [exist, user] = userDb.select_user(account, filed);
|
||||
|
||||
// 无账户
|
||||
if (!exist) {
|
||||
@@ -38,7 +37,7 @@ void UserService::login_fun(const std::string& account, const std::string& passw
|
||||
return;
|
||||
}
|
||||
|
||||
std::string source = account + password + user.password_salt;
|
||||
std::string source = std::to_string(user.account) + password + user.password_salt;
|
||||
size_t password_hash = std::hash<std::string>()(source);
|
||||
|
||||
if (user.password == std::to_string(password_hash)) {
|
||||
|
||||
Reference in New Issue
Block a user