/*
 * @Author: Your Name lishengyin@sz-sunwin.com
 * @Date: 2022-06-15 22:08:07
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-06-27 09:51:37
 * @FilePath: /ins/source/controllers/src/api_v1_User.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "api_v1_User.hpp"

using namespace api::v1;

// Add definition of your processing function here
void User::login(const HttpRequestPtr &req,std::function<void (const HttpResponsePtr &)> &&callback,
    std::string &&userId, const std::string &password){
    Json::Value ret;
    if(userId == "1" && password == "123456"){
        ret["result"]="ok";
        ret["token"]=drogon::utils::getUuid();
        auto resp=HttpResponse::newHttpJsonResponse(ret);
        callback(resp);
        return;
    }
    ret["result"]="ok";
    ret["msg"] = "Account password is incorrect";
    auto resp=HttpResponse::newHttpJsonResponse(ret);
    callback(resp);
}

void User::getInfo(const HttpRequestPtr &req, std::function<void (const HttpResponsePtr &)> &&callback, 
    std::string userId, const std::string &token)const{
    //验证token有效性等
    //读数据库或缓存获取用户信息
    Json::Value ret;
    ret["result"]="ok";
    ret["user_name"]="Jack";
    ret["user_id"]=userId;
    ret["gender"]=1;
    auto resp=HttpResponse::newHttpJsonResponse(ret);
    callback(resp);
}