def post(self):
        ''' Sign In API '''
        try:
            code = 400
            req = request.json
            chkKey = ['token', 'account']
            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            chkKey = ['email', 'password']
            if not Utils.isDicHasKey(req['account'], chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req['account'], chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            if req['token'] != config.TOKEN:
                res = {'msg': ReqMsg.NOT_TOKEN, 'code': ReqCode.NOT_TOKEN}
                return res, code

            account = Account()
            reqAccount = req['account']
            userInfo = account.getAccountInfo(reqAccount)
            if not userInfo['result']:
                res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
                return res, code
            if userInfo['data'] is None:
                res = {
                    'msg': ReqMsg.SIGNIN_NOT_EMAIL,
                    'code': ReqCode.SIGNIN_NOT_EMAIL
                }
                return res, code

            if not Encryption().checkBcrypt(userInfo['data']['password'],
                                            reqAccount['password']):
                res = {
                    'msg': ReqMsg.SIGNIN_NOT_MATCH,
                    'code': ReqCode.SIGNIN_NOT_MATCH
                }
                return res, code
            else:
                user = json.dumps({'email': userInfo['data']['email']})
                userSession = Session().createSession(user,
                                                      config.DUPLICATE_LOGIN)
                res = {'session': userSession}
                code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return res, code
    def post(self):
        """ User sign in API """
        rv, code = {}, 201
        try:
            req = request.json
            hasKey = ["token", "jobName", "param"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            isNullKey = Utils.isDicKeyValueNull(req, hasKey)
            if not isNullKey:
                return ReqCode.keyValNull.value, 400
            hasKey = ["email", "password"]
            isKey = Utils.isDicHasKey(req["account"], hasKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            isNullKey = Utils.isDicKeyValueNull(req["account"], hasKey)
            if not isNullKey:
                return ReqCode.keyValNull.value, 400

            # Import user information from MariaDB
            account = req["account"]
            userInfo = MariaUserSql().getAccountInfo(account)
            if not userInfo['result']:
                rv = CommonCode.UnknownError.value
                rv = userInfo['msg']
                return rv, 400

            if userInfo['data'] is None:
                return SignCode.SignFail.value, 400

            # if userInfo[''] is null:
            pwdChk = Encryption().checkBcrypt(userInfo["data"]["password"],
                                              account["password"])

            # Create session if passwords match
            if pwdChk:
                session = RedisSession().createSession(
                    userInfo["data"]["email"])
                rv = copy.deepcopy(CommonCode.Success.value)
                rv["data"] = {"session": session}
            else:
                rv, code = SignCode.SignFail.value, 400
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
 def post(self):
     """ User sign in API """
     rv, code = {"result": False}, 400
     try:
         # 값 존재 여부 확인
         req = request.json
         rvKey = ['ip', 'data']
         isKey, isVal = Utils.isDicHasKey(req,
                                          rvKey), Utils.isDicKeyValueNull(
                                              req, rvKey)
         if not (isKey and isVal):
             return rv, code
         webUrl = Init.getWebPath()
         apiPath = Init.getApiPath()
         # Client 정보 최신화
         res = Utils.requestUrl(method="POST",
                                url=webUrl + "/worker/client/sync/device")
         url = Init.getApiPath() + "/worker/client/sync/clients/device"
         j = req
         res = Utils.requestUrl(method="POST", url=url, json=j)
         rv["result"], code = True, 200
     except Exception as ex:
         rv["msg"] = str(ex)
         code = 400
     return rv, code  # ,header{"hi": "hello"}
    def post(self):
        """ Check for duplicate emails in API """
        code = 200
        try:
            req = request.json
            # Checking the existence of email in DB (MariaDB)
            rvKey = ['token']
            isKey, isVal = Utils.isDicHasKey(req,
                                             rvKey), Utils.isDicKeyValueNull(
                                                 req, rvKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            if not isVal:
                return ReqCode.keyValNull.value, 400

            ip = request.environ
            if 'HTTP_X_FORWARDED_FOR' in request.environ:
                a = request.environ['HTTP_X_FORWARDED_FOR']
                ip = request.environ['HTTP_X_FORWARDED_FOR'].split(',')[0]
            if 'REMOTE_ADDR' in request.environ:
                ip = request.list_storage_class(
                    [request.environ['REMOTE_ADDR']])[0]

            commandRedis = CommandRedis()
            commandRedis.registCommand(ip, req["token"])
            rv = CommonCode.Success.value
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
Beispiel #5
0
    def post(self):
        """Session Expiration Check API"""
        rv, code = {}, 200
        try:
            req = request.json
            hasKey = ["session"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            isNullKey = Utils.isDicKeyValueNull(req, hasKey)
            if not isNullKey:
                return ReqCode.keyValNull.value, 400

            session = req.get("session")
            # Session validity check
            redisSesson = RedisSession();
            check = redisSesson.checkSession(session)
            if check:
                data = redisSesson.getSession(session)
                rv = {"result":True, "data": json.loads(data)}
            else:
                code = 400
                rv = CommonCode.Fail.value
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
        return rv, code #, {"hi": "hello"}
Beispiel #6
0
    def post(self):
        ''' Register Worker TCP Server '''
        code = 400
        try:
            req = request.json
            chkKey = ['token', 'uid']

            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            if 'HTTP_X_FORWARDED_FOR' in request.environ:
                ip = request.environ['HTTP_X_FORWARDED_FOR'].split(',')[0]
            elif 'REMOTE_ADDR' in request.environ:
                ip = request.list_storage_class(
                    [request.environ['REMOTE_ADDR']])[0]

            result = Server().check(ip, req['uid'])
            res = {'result': result}
            code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return res, code
Beispiel #7
0
    def post(self):
        """ User sign in API """
        rv, code = {"result": False}, 400
        try:
            req = request.json
            hasKey = ["token"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return rv, code

            if not req["token"] == Init.getToken():
                return rv, code
            else:
                tcpServer = TCPServer()
                clients = tcpServer.getClients()

                data = []
                for client in clients:
                    data.append(client)

                url = Init.getApiPath() + "/worker/client/sync/clients"
                j = {"data": data}
                res = Utils.requestUrl(method="POST", url=url, json=j)
                rv["result"], code = True, 200
        except Exception as ex:
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
    def post(self):
        ''' Session Expiration Check API '''
        code = 400
        try:
            req = request.json
            chkKey = ['token', 'session']
            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return ReqCode.keyValNull.value, 400

            if req['token'] != config.TOKEN:
                res = {'msg': ReqMsg.NOT_TOKEN, 'code': ReqCode.NOT_TOKEN}
                return res, code

            reqSession = req.get('session')
            session = Session()
            check = session.checkSession(reqSession)
            if not check:
                rv = {'result': False, 'user': {}}
            else:
                data = session.getSession(reqSession)
                rv = {'result': True, 'user': json.loads(data)}
            code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return rv, code
    def post(self):
        ''' Sign out API '''
        try:
            code = 400
            req = request.json
            chkKey = ['token', 'session']
            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            if req['token'] != config.TOKEN:
                res = {'msg': ReqMsg.NOT_TOKEN, 'code': ReqCode.NOT_TOKEN}
                return res, code

            reqSession = req.get("session")
            Session().deleteSession(reqSession)
            res = {'result': True}
            code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return res, code
    def post(self):
        """ Check for duplicate emails in API """
        code = 400
        try:
            req = request.json
            chkKey = ['token', 'session']
            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            reqSession = req.get('session')
            session = Session()
            account = session.getSession(reqSession)

            if not account:
                res = {'msg': ReqMsg.DISABLE_SESSION, 'code': ReqCode.DISABLE_SESSION}
                return res, code

            account = json.loads(account)

            rvMenu = Menu().getMainMenuList(account)
            if rvMenu['result']:
                res = {"data": rvMenu['data']}
            else:
                res = {}
            code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return res, code
Beispiel #11
0
    def post(self):
        """ Check for duplicate emails in API """
        code = 200
        try:
            req = request.json
            rvKey = ['data']
            isKey = Utils.isDicHasKey(req, rvKey)
            if not isKey:
                return ReqCode.notKey.value, 400

            commandIp = request.environ.get('HTTP_X_REAL_IP',
                                            request.remote_addr)
            clientRedis = ClientRedis()

            clients = clientRedis.getClient()
            connectList = []
            for client in clients:
                if clients[client] == commandIp:
                    connectList.append(client)

            for conncetIp in connectList:
                if conncetIp not in req['data']:
                    clientRedis.deleteClient(conncetIp)

            for clientIp in req['data']:
                clientRedis.registClient(commandIp, clientIp)
            rv = {"result": True}
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
    def post(self):
        """ Check for duplicate emails in API """
        code = 200
        try:
            req = request.json
            # Checking the existence of email in DB (MariaDB)
            rvKey = ['ip']
            isKey, isVal = Utils.isDicHasKey(req,
                                             rvKey), Utils.isDicKeyValueNull(
                                                 req, rvKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            if not isVal:
                return ReqCode.keyValNull.value, 400
            commandRedis = CommandRedis()
            for ip in req['ip']:
                commandRedis.deleteCommand(ip)

            clientRedis = ClientRedis
            clients = ClientRedis.getClient()
            for client in clients:
                if clients[client] in req['ip']:
                    clientRedis.deleteClient(client)

            rv = CommonCode.Success.value
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
Beispiel #13
0
    def post(self):
        """ User registration API """
        try:
            # Request data check
            req = request.json
            rvKey, rvAccountKey  = ['token', 'account'], ['email', 'nickName', 'password', 'firstName', 'lastName', 'authority']
            isKey, isVal = Utils.isDicHasKey(req, rvKey), Utils.isDicKeyValueNull(req, rvKey)
            if isKey and isVal:
                isKey, isVal = Utils.isDicHasKey(req['account'], rvAccountKey), Utils.isDicKeyValueNull(req['account'], rvAccountKey)

            if not isKey:
                return ReqCode.notKey.value, 400
            if not isVal:
                return ReqCode.keyValNull.value, 400

            account = req['account']
            mariaUserSql = MariaUserSql()

            # Check if it's an email or not
            chkEmail = Utils.isEmail(account['email']);
            if not chkEmail:
                return SignCode.NotEmail.value, 400

            # Check for duplicate emails
            chkEmail = mariaUserSql.isEmail(account)
            if not chkEmail['result']:
                return SignCode.ExistEmail.value, 400

            # Check for duplicate nickname
            chkNickName = mariaUserSql.isNickName(account)
            if not chkNickName['result']:
                return SignCode.ExistNickName.value, 400

            account['password'] = Encryption().changeBcrypt(account['password']).decode('ascii')
            # Checking the existence of nickname in DB (MariaDB)
            chk = mariaUserSql.setAccountRegist(req['account'])
            if chk['result']:
                rv = CommonCode.Success.value
                code = 200
            else:
                rv = copy.deepcopy(CommonCode.UnknownError.value)
                rv['msg'] = chk['msg']
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
Beispiel #14
0
    def post(self):
        """ Connected Client IP Information """
        code = 400
        try:
            req = request.json
            chkKey = ['token']
            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            res = Client().list()
            code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return res, code  # ,header{"hi": "hello"}
Beispiel #15
0
    def post(self):
        """ User sign in API """
        rv, code = {"result": False}, 400
        try:
            req = request.json
            hasKey = ["token"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return rv, code

            if not req["token"] == Init.getToken():
                return rv, code
            else:
                msg = {'job': 'sync_system_status'}
                tcpServer = TCPServer()
                tcpServer.sendMessageToAll(json.dumps(msg))
                rv["result"], code = True, 200
        except Exception as ex:
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
Beispiel #16
0
    def post(self):
        """ Remove Registered TCP Server """
        code = 400
        try:
            req = request.json
            chkKey = ['token', 'ip']

            if not Utils.isDicHasKey(req, chkKey):
                res = {'msg': ReqMsg.NOT_KEY, 'code': ReqCode.NOT_KEY}
                return res, code

            if not Utils.isDicKeyValueNull(req, chkKey):
                res = {'msg': ReqMsg.NOT_VALUE, 'code': ReqCode.NOT_VALUE}
                return res, code

            result = Server().delete(req['ip'])
            res = {'result': result}
            code = 200
        except Exception as ex:
            res = {'msg': ReqMsg.UNKNOWN, 'code': ReqCode.UNKNOWN}
        return res, code  # ,header{"hi": "hello"}
Beispiel #17
0
    def post(self):
        """User sign out API"""
        code = 200
        try:
            req = request.json
            hasKey = ["token", "session"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            isNullKey = Utils.isDicKeyValueNull(req, hasKey)
            if not isNullKey:
                return ReqCode.keyValNull.value, 400

            session = req.get("session")
            # Session removal
            RedisSession().deleteSession(session)
            rv = CommonCode.Success.value
        except Exception as ex:
            code = 400
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
        return rv, code #, {"hi": "hello"}
Beispiel #18
0
    def post(self):
        """ Check for duplicate emails in API """
        code = 200
        try:
            # 값 존재 여부 확인
            req = request.json
            rvKey = ['ip', 'data']
            isKey, isVal = Utils.isDicHasKey(req,
                                             rvKey), Utils.isDicKeyValueNull(
                                                 req, rvKey)
            if not isKey:
                return ReqCode.notKey.value, 400
            if not isVal:
                return ReqCode.keyValNull.value, 400

            clientRedis = ClientRedis()
            clientRedis.registClientDevice(req['ip'], req['data'])
            rv = CommonCode.Success.value
        except Exception as ex:
            rv = copy.deepcopy(CommonCode.UnknownError.value)
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}