Commit 8d794fe0 authored by jan.koester's avatar jan.koester
Browse files

fixed

parent a3bee197
Loading
Loading
Loading
Loading
Loading
+21 −4
Changes for client/client.cpp: 21 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -316,16 +316,33 @@ bool authdb::client::Client::remSession(){
    json_tokener_free(jtok);
    return false;
}

void authdb::client::Client::changeUserPw(const std::string& pw){
#include <iostream>
void authdb::client::Client::changeUserPw(const std::string& oldpw,const std::string& newpw){
    json_object *jresponse = json_object_new_object();
    json_object *cmd=json_object_new_array();
    json_object *obj=json_object_new_object();
    json_object *pchange=json_object_new_object();

    json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str()));
    json_object_object_add(obj,"remsession",json_object_new_string(_Con.getSessionID().c_str()));

    json_object_array_add(cmd,obj);
    json_object_set_string(pchange,"changeuserpw");
    json_object_object_add(pchange,"oldpw",json_object_new_string(oldpw.c_str()));
    json_object_object_add(pchange,"newpw",json_object_new_string(newpw.c_str()));

    json_object_array_add(cmd,obj);
    json_object_array_add(cmd,pchange);
    json_object_object_add(jresponse,"commands",cmd);

    size_t outsize=0;
    std::vector<char> out;

    const char *tmp=json_object_to_json_string_length(jresponse,0,&outsize);

    std::copy(tmp,tmp+outsize,std::back_inserter(out));

    std::vector<char> resp(_Con._Client->Post(_Con._Url.getPath(),"text/json",out));

    resp.push_back('\0');

    std::cout << resp.data() << std::endl;
}
+1 −1
Changes for client/client.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ namespace authdb {
            bool GPOcheck(class uuid gpoid);

            void UserInfo(class UserData &udat);
            void changeUserPw(const std::string &pw);
            void changeUserPw(const std::string& oldpw,const std::string& newpw);
        private:
            ClientConnection &_Con;
            friend class Session;
+5 −8
Changes for src/api.cpp: 5 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -94,8 +94,6 @@ namespace authdb {
            if(!cmd || json_object_get_type(cmd)!=json_type::json_type_array)
                throw(AuthBackendError("Invalid Api Commands"));

            _SessionData=nullptr;

            int fcount = json_object_array_length(cmd);
            for(int i =0; i<fcount; ++i) {
                json_object_object_foreach(json_object_array_get_idx(cmd,i), key, val) {
@@ -104,8 +102,7 @@ namespace authdb {
                            uuid cid;
                            if(cid.parse(id)!=0)
                                return nullptr;
                            _SessionData=AuthSession.getSession(cid);
                            return _SessionData;
                            return  AuthSession.getSession(cid);
                    }
                }
            }
@@ -194,13 +191,13 @@ namespace authdb {

                                            if(name==udat.getUsername()){
                                                if(pwsalt==udat.getPwHash()){
                                                    _SessionData=AuthSession.addSession(_Backend,_Did.value,cur.uuid);
                                                    const SessionData *sdat=AuthSession.addSession(_Backend,_Did.value,cur.uuid);
                                                    json_object *respid=json_object_new_object();
                                                    uuid sessid;
                                                    _SessionData->getSid(sessid);
                                                    sdat->getSid(sessid);
                                                    json_object_object_add(respid,"sessionid",json_object_new_string(sessid.c_str()));
                                                    json_object_array_add(response,respid);
                                                    return _SessionData;
                                                    return sdat;
                                                }
                                                return nullptr;
                                            }
@@ -435,7 +432,7 @@ namespace authdb {
                        size_t ustart=0;
                        user.info(_Backend,udat,ustart);

                        if(newhash!=oldhash || oldhash != udat.getPwHash() ){
                        if(newhash!=oldhash || oldhash == udat.getPwHash() ){
                            json_object *slogoff=json_object_new_object();
                            json_object_object_add(slogoff,"changeuserpw", json_object_new_boolean(false));
                            json_object_array_add(response,slogoff);