Example #1
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     access_token = data['access_token'][0]
     check = check_token(access_token)
     check_user = MyUsers.objects(email=check['email']).first()
     if check_user['permission'] == 'admin':
         users = MyUsers.objects()
         data = []
         for user in users:
             data.append({
                 'id': str(user.id),
                 'name': user.name,
                 'email': user.email,
                 'picture': user.picture,
                 'permission': user.permission,
                 'access_date': str(user.access_date),
                 'last_access': str(user.last_access)
             })
         data = {"data": data}
         encoded_jwt = jwt.encode(data,
                                  salt,
                                  algorithm='HS256',
                                  headers={'message': 'OK'})
         return {"test": encoded_jwt.decode("utf-8")}
     else:
         encoded_jwt = jwt.encode(data,
                                  salt,
                                  algorithm='HS256',
                                  headers={'message': 'OK'})
         return {"test": encoded_jwt.decode("utf-8")}
Example #2
0
 def post(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     users = MyUsers.objects(email=data['email']).first()
     if not users:
         user_add = MyUsers(name=data['name'],
                            email=data['email'],
                            picture=data['picture'])
         user_add.save()
         if user_add:
             return {'status': "200"}
         else:
             return {'status': "404"}
     return {'status': "200"}
Example #3
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     access_token = data['access_token'][0]
     check = check_token(access_token)
     check_user = MyUsers.objects(email=check['email']).first()
     if check_user['permission'] == 'admin':
         cameras = Cameras.objects()
         data = []
         for camera in cameras:
             data.append({
                 'id': str(camera.id),
                 'uri': camera.uri,
                 'owner': camera.owner,
                 'create_date': str(camera.create_date),
                 'name': camera.name,
                 'update_date': str(camera.update_date),
             })
         data = {"data": data}
         encoded_jwt = jwt.encode(data,
                                  salt,
                                  algorithm='HS256',
                                  headers={'message': 'OK'})
         return {"test": encoded_jwt.decode("utf-8")}
     else:
         encoded_jwt = jwt.encode(data,
                                  salt,
                                  algorithm='HS256',
                                  headers={'message': 'OK'})
         return {"test": encoded_jwt.decode("utf-8")}
Example #4
0
 def post(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     access_token = data['access_token'][0]
     check = check_token(access_token)
     check_user = MyUsers.objects(email=check['email']).first()
     print(data['user_permission'])
     if check_user['permission'] == 'admin':
         users = MyUsers.objects(id=data['user_id']).first()
         users.update(set__permission=data['user_permission'])
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     return {"test": encoded_jwt.decode("utf-8")}
Example #5
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     access_token = data['access_token'][0]
     check = check_token(access_token)
     check_user = MyUsers.objects(email=check['email']).first()
     if check_user['permission'] == 'admin':
         nodes = ComputeNodes.objects()
         c_node = []
         for c in nodes:
             c_node.append({
                 "name":
                 c.name,
                 "id":
                 str(c.id),
                 "online":
                 c.online,
                 "memory": {
                     "used": c.memory.used,
                     "free": c.memory.free,
                     "total": c.memory.total
                 },
                 "disk": {
                     "used": c.disk.used,
                     "free": c.disk.free,
                     "total": c.disk.total
                 },
                 "cpu": {
                     "used_per_cpu": c.cpu.used_per_cpu,
                     "used": c.cpu.used
                 },
                 "owner":
                 c.owner,
                 "create_date":
                 str(c.create_date),
                 "update_date":
                 str(c.update_date),
                 "memory_used_percent":
                 int(c.memory.used / c.memory.total * 100),
                 "disk_used_percent":
                 int(c.disk.used / c.disk.total * 100),
             })
         data = {"data": c_node}
         encoded_jwt = jwt.encode(data,
                                  salt,
                                  algorithm='HS256',
                                  headers={'message': 'OK'})
         return {"test": encoded_jwt.decode("utf-8")}
     else:
         encoded_jwt = jwt.encode(data,
                                  salt,
                                  algorithm='HS256',
                                  headers={'message': 'OK'})
         return {"test": encoded_jwt.decode("utf-8")}
Example #6
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     access_token = data['access_token'][0]
     user = check_token(access_token)
     shared_list = SharedCameras.objects(shared=user['email'])
     data_email = []
     count = 0
     for i in shared_list:
         camera = Cameras.objects(id=i.camera_id)
         if camera:
             for c in camera:
                 data_email.append({
                     'camera_id': str(c.id),
                     'name': c.name,
                     'owner': c.owner
                 })
     user = MyUsers.objects(email=user['email']).first()
     shared_list = SharedCameras.objects(shared=user['permission'])
     data_permission = []
     for i in shared_list:
         camera = Cameras.objects(id=i.camera_id)
         if camera:
             for c in camera:
                 data_permission.append({
                     'camera_id': str(c.id),
                     'name': c.name,
                     'owner': c.owner
                 })
     data = {
         "email": data_email,
         "count_email": len(data_email),
         "permission": data_permission,
         "count_permission": len(data_permission)
     }
     print(data)
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     return {"test": encoded_jwt.decode("utf-8")}
Example #7
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     access_token = data['access_token'][0]
     if len(access_token) < 5:
         access_token = data['access_token']
     user = check_token(access_token)
     user = MyUsers.objects(email=user['email']).first()
     try:
         nodes = ComputeNodes.objects(owner=user['email'])
         c_node = []
         for c in nodes:
             c_node.append({
                 "name": c.name,
                 "id": str(c.id),
                 "online": c.online,
                 "memory": {
                     "used": c.memory.used,
                     "free": c.memory.free,
                     "total": c.memory.total
                 },
                 "disk": {
                     "used": c.disk.used,
                     "free": c.disk.free,
                     "total": c.disk.total
                 },
                 "cpu": {
                     "used_per_cpu": c.cpu.used_per_cpu,
                     "used": c.cpu.used
                 },
                 "update_date": str(c.update_date),
             })
         data = {"compute_node": c_node}
     except:
         data = {"processors": " ", "compute_node": " "}
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     return {"test": encoded_jwt.decode("utf-8")}
Example #8
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     users = MyUsers.objects(email=data['email']).first()
     users.update(set__last_access=datetime.now())
     if users:
         data = {
             'id': str(users.id),
             'name': users.name,
             'email': users.email,
             'picture': users.picture,
             'permission': users.permission,
             'last_access': str(users.last_access),
         }
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     return {"test": encoded_jwt.decode("utf-8")}
Example #9
0
 def get(self):
     p = request.form['data']
     data = p.encode('utf8')
     data = jwt.decode(data, salt, algorithms=['HS256'])
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     access_token = data['access_token'][0]
     if len(access_token) < 5:
         access_token = data['access_token']
     user = check_token(access_token)
     user = MyUsers.objects(email=user['email']).first()
     # if user['permission'] == 'admin':
     #     nk = nokkhum_client()
     #     processors = nk.admin.processors.list()
     #     compute_nodes = nk.admin.compute_nodes.list()
     #     nodes = []
     #     for c in compute_nodes:
     #         nodes.append(nk.admin.compute_nodes.get(c.id))
     #     ps = []
     #     for p in processors:
     #         ps.append({
     #             "name":p.name,
     #             "id":p.id,
     #             "compute_id":p.processor_operating['compute_node']['id']
     #         })
     #     processors = Cameras.objects(owner=user['email'])
     #     for p in processors:
     #         ps.append({
     #             "name":p.name,
     #             "id":str(p.id),
     #             "compute_id":p.compute_id,
     #             "group_name":p.group_name
     #         })
     #     c_node = []
     #     for c in nodes:
     #         c_node.append({
     #             "name": c.name,
     #             "id": c.id,
     #             "online":c.online,
     #             "memory":{
     #                 "used":c.memory.used,
     #                 "free":c.memory.free,
     #                 "total":c.memory.total
     #             },
     #             "disk":{
     #                 "used":c.disk.used,
     #                 "free":c.disk.free,
     #                 "total":c.disk.total
     #             },
     #             "cpu":{
     #                 "used_per_cpu":c.cpu.used_per_cpu,
     #                 "used":c.cpu.used
     #             }
     #         })
     #     nodes = ComputeNodes.objects(owner=user['email'])
     #     for c in nodes:
     #         c_node.append({
     #             "name": c.name,
     #             "id": str(c.id),
     #             "online":c.online,
     #             "memory":{
     #                 "used":c.memory.used,
     #                 "free":c.memory.free,
     #                 "total":c.memory.total
     #             },
     #             "disk":{
     #                 "used":c.disk.used,
     #                 "free":c.disk.free,
     #                 "total":c.disk.total
     #             },
     #             "cpu":{
     #                 "used_per_cpu":c.cpu.used_per_cpu,
     #                 "used":c.cpu.used
     #             }
     #         })
     #     data = {
     #         "processors": ps,
     #         "compute_node": c_node
     #     }
     # else:
     try:
         processors = Cameras.objects(owner=user['email'])
         ps = []
         for p in processors:
             ps.append({
                 "name": p.name,
                 "id": str(p.id),
                 "compute_id": p.compute_id,
                 "group_name": p.group_name,
             })
         nodes = ComputeNodes.objects(owner=user['email'])
         c_node = []
         for c in nodes:
             c_node.append({
                 "name": c.name,
                 "id": str(c.id),
                 "online": c.online,
                 "key": c.key,
                 "memory": {
                     "used": c.memory.used,
                     "free": c.memory.free,
                     "total": c.memory.total
                 },
                 "disk": {
                     "used": c.disk.used,
                     "free": c.disk.free,
                     "total": c.disk.total
                 },
                 "cpu": {
                     "used_per_cpu": c.cpu.used_per_cpu,
                     "used": c.cpu.used
                 }
             })
         data = {"processors": ps, "compute_node": c_node}
     except:
         data = {"processors": " ", "compute_node": " "}
     encoded_jwt = jwt.encode(data,
                              salt,
                              algorithm='HS256',
                              headers={'message': 'OK'})
     return {"test": encoded_jwt.decode("utf-8")}