Commit ff9adba1 authored by jan.koester's avatar jan.koester
Browse files

fixed

parent 26d8d212
Loading
Loading
Loading
Loading
+3 −7
Changes for client/client.cpp: 3 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -81,17 +81,16 @@ authdb::client::Client::Client(ClientConnection& clt) : _Con(clt){

authdb::client::Client::~Client(){
}
#include <iostream>

bool authdb::client::Client::ClientAuth(){
    json_object *jresponse = json_object_new_object();
    json_object *cmd=json_object_new_array();
    json_object *login=json_object_new_object();
    json_object *userauth=json_object_new_object();

    json_object_set_string(userauth,"login");
    json_object_object_add(userauth,"type",json_object_new_string("client"));
    json_object_object_add(userauth,"name",json_object_new_string(_Con._UserName.c_str()));
    json_object_object_add(userauth,"key",json_object_new_string(_Con._UserPassword.c_str()));
    json_object_object_add(userauth,"name",json_object_new_string(_Con._CltName.c_str()));
    json_object_object_add(userauth,"key",json_object_new_string(_Con._CltSecret.c_str()));

    json_object_array_add(cmd,login);
    json_object_object_add(login,"login",userauth);
@@ -109,8 +108,6 @@ bool authdb::client::Client::ClientAuth(){

    resp.push_back('\0');

    std::cout << resp.data() <<std::endl;

    json_object_put(jresponse);

    json_object *jrequest;
@@ -147,7 +144,6 @@ bool authdb::client::Client::UserAuth(){
    json_object *login=json_object_new_object();
    json_object *userauth=json_object_new_object();

    json_object_set_string(userauth,"login");
    json_object_object_add(userauth,"type",json_object_new_string("user"));
    json_object_object_add(userauth,"name",json_object_new_string(_Con._UserName.c_str()));
    json_object_object_add(userauth,"key",json_object_new_string(_Con._UserPassword.c_str()));
+3 −2
Changes for client/examples/clientlogin.cpp: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@
int main(int argc, char *argv[]){
    authdb::client::ClientConnection con;
    con.setUrl(argv[1]);
    con.setUsername(argv[2]);
    con.setUserPassword(argv[3]);
    con.setClientName(argv[2]);
    con.setClientSecret(argv[3]);

    authdb::client::Client clt(con);
    if(clt.ClientAuth()){
@@ -41,6 +41,7 @@ int main(int argc, char *argv[]){
        return 0;
    }
    std::cout << "Failed login !" << std::endl;

    return -1;
}
+17 −21
Changes for src/api.cpp: 17 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ namespace authdb {


        const ClientConnections *ClientLogin(json_object *request,json_object *response){
            std::lock_guard<std::mutex> lock(AuthClientLock);
            std::lock_guard<std::mutex> lock(AuthSessionLock);
            json_object *cmd=json_object_object_get(request,"commands");

            if(!cmd || json_object_get_type(cmd)!=json_type::json_type_array)
@@ -227,20 +227,27 @@ namespace authdb {
                            json_object_object_foreach(val,okey,oval){
                                if(strcmp(okey,"type")==0){
                                    atype=json_object_get_string(oval);
                                    if( atype!="client"){
                                        name.clear();
                                        pw.clear();
                                        continue;
                                    }
                                }else if(strcmp(okey,"name")==0){
                                    name=json_object_get_string(oval);
                                }else if(strcmp(okey,"key")==0){
                                    pw=json_object_get_string(oval);
                                }
                                if(!pw.empty() && !name.empty() && atype=="client")
                                    break;
                            }
                        }

                        if(name.empty() || pw.empty() || atype!="client"){
                            name.clear();
                            pw.clear();
                            atype.clear();
                            continue;
                        }
                        std::cout << atype << name << pw << std::endl;

                        if(name.empty() || pw.empty())
                            return nullptr;



                        sha512 sha;
                        sha.hash(pw,pwsalt);
@@ -269,7 +276,6 @@ namespace authdb {
                                    }
                                    return nullptr;
                                }

                            }
                        }
                    }
@@ -485,7 +491,6 @@ namespace authdb {
            jresponse = json_object_new_array();

            const ClientConnections *curcon=nullptr;
            // const SessionData *sessiondat=nullptr;

          if(! (curcon=checkConnection(jrequest,jresponse)) ){
                curcon=ClientLogin(jrequest,jresponse);
@@ -495,22 +500,13 @@ namespace authdb {
                    _SessionData=userLogin(jrequest,jresponse);
            }

            if(!_SessionData){
                    const char *ret=json_object_to_json_string(jresponse);
                    rep.setState(HTTP401);
                    rep.setContentType("text/json");
                    rep.send(curreq,ret,strlen(ret));
                    json_object_put(jresponse) ;
                    json_object_put(jrequest) ;
                    return;
            }

            if(_SessionData){
                Connection(jrequest,jresponse);
                SessionInfo(jrequest,jresponse);
                remSession(jrequest,jresponse);
            }


            if(curcon){
            if(curcon && _SessionData){
                changeUserPw(jrequest,jresponse);
                checkGPO(jrequest,jresponse);
            }