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

added sessioninfo

parent ec355eb6
Loading
Loading
Loading
Loading
Loading
+12 −3
Changes for client/client.h: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -26,8 +26,9 @@
 *******************************************************************************/

#include <string>
#include "uuid.h"
#include "session.h"
#include <uuid.h>
#include <session.h>
#include <user.h>

#include <httppp/http.h>

@@ -75,11 +76,19 @@ namespace authdb {
                bool check(const std::string &clientname);
            } CCon;

            class Session {
                void info(class SessionData &sdat);
            };

            class GPO {
            public:
                bool check(uuid gpoid,const SessionData &sdat);
                bool check(class uuid gpoid);
            } CGPO;

            class User {
                void info(class UserData &udat);
            };

        private:
            ClientConnection &_Con;
        };
+37 −0
Changes for src/api.cpp: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -338,6 +338,32 @@ namespace authdb {
            }
        }

        void SessionInfo(json_object *request,json_object *response){
            std::lock_guard<std::mutex> lock(AuthClientLock);
            json_object *cmd=json_object_object_get(request,"commands");

            if(!cmd || json_object_get_type(cmd)!=json_type::json_type_array)
                throw(AuthBackendError("Invalid Api Commands"));

            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) {
                    if(strcmp(key,"sessioninfo")==0){
                        uuid tmp;
                        json_object *respid=json_object_new_object();
                        json_object_object_add(respid,"username", json_object_new_string(_SessionData->getUsername()));
                        _SessionData->getUid(tmp);
                        json_object_object_add(respid,"userid", json_object_new_string(tmp.c_str()));
                        _SessionData->getSid(tmp);
                        json_object_object_add(respid,"sessionid", json_object_new_string(tmp.c_str()));
                        _SessionData->getDid(tmp);
                        json_object_object_add(respid,"domainid", json_object_new_string(tmp.c_str()));
                        json_object_object_add(response,"sessioninfo",respid);
                    }
                }
            }
        }

        Api(AuthBackend &admin,class uuid did, libhttppp::HttpRequest* curreq, const int tid, ULONG_PTR args) : _Backend(admin), _Did(did){

            _SessionData=nullptr;
@@ -377,7 +403,18 @@ namespace authdb {
                    _SessionData=userLogin(jrequest,jresponse);
            }

            if(_SessionData->empty()){
                    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;
            }

            Connection(jrequest,jresponse);
            SessionInfo(jrequest,jresponse);

            if(! (curcon=checkConnection(jrequest,jresponse)) ){
                if(! (curcon=ClientLogin(jrequest,jresponse)) ){