示例#1
0
def post_circles():
    if request.method == 'POST':
        data = request.get_json(force=True)
        user = Users.query.filter_by(
            cyphered_email=data['publisher_id']).first()
        if user is not None:
            pics = data['images']
            paths = []
            uid = user.id
            circle = Circle(uid, data['title'], data['content'])
            circle.location = data['location']
            circle.time = data['time']
            db.session.add(circle)
            db.session.commit()
            for i in range(len(pics)):
                img = base64.b64decode(pics[i])
                print(len(img))
                print(circle.id)
                with open(
                        "/root/work/back_end/static/pic/" + str(circle.id) +
                        "_" + str(i) + ".jpg", 'wb') as file:
                    file.write(img)
                paths.append(
                    url_for("static",
                            filename="pic/" + str(circle.id) + "_" + str(i) +
                            ".jpg"))
            circle.imgs = ",".join(paths)
            db.session.add(circle)
            db.session.commit()

        return jsonify(status=1)
 def setUp(self):
     neo_config.load_config()
     neo_config.set_project_variables()
     neo = NeoAPI(neo_config)
     self.api = neo.activate_testing()
     self.user1 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user1 is None:
         self.user1 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1995-12-12")
     self.user2 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user2 is None:
         self.user2 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1111-11-11")
     self.circle = Circle(name="Mamie")
     self.circle2 = Circle(name="test")
     self.linkCircle = UserToCircle(user=self.user1,
                                    circle=self.circle,
                                    privilege="ADMIN")
     self.linkCircle2 = UserToCircle(user=self.user2, circle=self.circle)
     self.conversation = Conversation("test")
     self.conversation.circle = self.circle
     self.conversation.device_access = True
     self.device = Device(name="Papie")
     self.device2 = Device(name="test")
     self.device2.circle = self.circle2
     self.device2_password = self.device2.get_pre_activation_password()
     self.device2.activate(self.device2.key)
     self.device.circle = self.circle
     self.device_password = self.device.get_pre_activation_password()
     self.device.activate(self.device.key)
     self.message = Message(is_user=False)
     self.message.conversation = self.conversation
     self.message.device = self.device
     db.session.commit()
     self.token1 = authenticate_user(self.api, self.user1, "test")
     self.token2 = authenticate_user(self.api, self.user2, "test")
     self.device_token = authenticate_device(self.api, self.device,
                                             self.device_password)
     self.device2_token = authenticate_device(self.api, self.device2,
                                              self.device2_password)
     self.tokenAdmin = authenticate_user(self.api,
                                         "*****@*****.**",
                                         "PapieNeo2019")
示例#3
0
 def setUp(self):
     neo_config.load_config()
     neo_config.set_project_variables()
     neo = NeoAPI(neo_config)
     self.api = neo.activate_testing()
     self.user1 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user1 is None:
         self.user1 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1995-12-12")
     self.user2 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user2 is None:
         self.user2 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1111-11-11")
     self.circle = Circle(name="Mamie")
     self.linkCircle = UserToCircle(user=self.user1, circle=self.circle)
     self.linkCircle2 = UserToCircle(user=self.user2, circle=self.circle)
     db.session.commit()
     self.token1 = authenticate_user(self.api, self.user1, "test")
     self.token2 = authenticate_user(self.api, self.user2, "test")
     self.tokenAdmin = authenticate_user(self.api,
                                         "*****@*****.**",
                                         "PapieNeo2019")
示例#4
0
 def setUp(self):
     neo_config.load_config()
     neo_config.set_project_variables()
     self.neo = NeoAPI(neo_config)
     self.api = self.neo.activate_testing()
     self.client = SocketIOTestClient(self.neo.app, socketio)
     self.client.disconnect()
     self.user1 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first()
     if self.user1 is None:
         self.user1 = UserModel(email="*****@*****.**", password="******", first_name="firstname",
                                last_name="lastname", birthday="1995-12-12")
     self.user2 = db.session.query(UserModel).filter(UserModel.email == "*****@*****.**").first()
     if self.user2 is None:
         self.user2 = UserModel(email="*****@*****.**", password="******", first_name="firstname",
                                last_name="lastname", birthday="1995-12-12")
     self.circle = Circle(name="Mamie")
     self.linkCircle = UserToCircle(user=self.user1, circle=self.circle, privilege="ADMIN")
     self.conversation = Conversation("test", device_access=True)
     self.conversation.device_access = True
     self.conversation.circle = self.circle
     self.link2 = UserToConversation(user=self.user2, conversation=self.conversation)
     self.device = Device(name="Papie")
     self.device.circle = self.circle
     self.device_password = self.device.get_pre_activation_password()
     self.device.activate(self.device.key)
     db.session.commit()
     self.circle_id = self.circle.id
     self.conversation_id = self.conversation.id
     self.token1 = authenticate_user(self.api, self.user1, "test")
     self.token2 = authenticate_user(self.api, self.user2, "test")
     self.device_token = authenticate_device(self.api, self.device, self.device_password)
     self.tokenAdmin = authenticate_user(self.api, "*****@*****.**", "PapieNeo2019")
示例#5
0
 def setUp(self):
     neo_config.load_config()
     neo_config.set_project_variables()
     neo = NeoAPI(neo_config)
     self.api = neo.activate_testing()
     self.user1 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user1 is None:
         self.user1 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1995-12-12")
     self.user2 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user2 is None:
         self.user2 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1111-11-11")
     self.circle1 = Circle(name="TestPaymentCircle")
     self.link1 = UserToCircle()
     self.link1.user = self.user1
     self.link1.circle = self.circle1
     db.session.commit()
     self.token1 = authenticate_user(self.api, self.user1, "test")
     self.token2 = authenticate_user(self.api, self.user2, "test")
示例#6
0
 def create_circle(self):
     self.circle = Circle("TESTCONVLIST")
     self.circle2 = Circle("TESTCONVLIST2")
     self.link1 = UserToCircle()
     self.link2 = UserToCircle()
     self.link3 = UserToCircle()
     self.link4 = UserToCircle()
     self.link1.user = self.user1
     self.link1.circle = self.circle
     self.link2.user = self.user2
     self.link2.circle = self.circle
     self.link3.user = self.user3
     self.link3.circle = self.circle2
     self.link4.user = self.user2
     self.link4.circle = self.circle2
     db.session.commit()
示例#7
0
def create(name, user):
    try:
        circle = Circle(name)
        link = UserToCircle(privilege="REGULAR")
        link.circle = circle
        link.user = user
        db.session.commit()
        response = {
            "data": {
                "success": True,
                "content": circle.get_simple_content()
            },
            "status_code": 200
        }
    except e_circle.CircleException as exception:
        response = {
            "data": {
                "success": False,
                "message": exception.message
            },
            "status_code": exception.status_code
        }
    return response
示例#8
0
 def setUp(self):
     neo_config.load_config()
     neo_config.set_project_variables()
     neo = NeoAPI(neo_config)
     self.api = neo.activate_testing()
     self.user1 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user1 is None:
         self.user1 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1995-12-12")
     self.user2 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user2 is None:
         self.user2 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1111-11-11")
     self.user3 = db.session.query(UserModel).filter(
         UserModel.email == "*****@*****.**").first()
     if self.user3 is None:
         self.user3 = UserModel(email="*****@*****.**",
                                password="******",
                                first_name="firstname",
                                last_name="lastname",
                                birthday="1111-11-11")
     self.circle = Circle(name="TestConversationinvite")
     self.link = UserToCircle()
     self.link.user = self.user1
     self.link.circle = self.circle
     self.link2 = UserToCircle()
     self.link2.user = self.user2
     self.link2.circle = self.circle
     self.conv = Conversation()
     self.conv.circle = self.circle
     self.utc1 = UserToConversation(privilege="ADMIN")
     self.utc1.user = self.user1
     self.utc1.conversation = self.conv
     self.utc2 = UserToConversation(privilege="STANDARD")
     self.utc2.user = self.user2
     self.utc2.conversation = self.conv
     db.session.commit()
     self.token1 = authenticate_user(self.api, self.user1, "test")
     self.token2 = authenticate_user(self.api, self.user2, "test")
     self.token3 = authenticate_user(self.api, self.user3, "test")
示例#9
0
 def create_circle(self):
     self.circle = Circle("TESTDELETION")
     self.link = UserToCircle()
     self.link.user = self.user1
     self.link.circle = self.circle
     db.session.commit()
示例#10
0
 def create_circle(self, name):
     self.circle = Circle(name)
     self.link = UserToCircle()
     self.link.user = self.user1
     self.link.circle = self.circle
     db.session.commit()
示例#11
0
def init_default_content(p1, p2):
    user = db.session.query(User).filter(
        User.email == "*****@*****.**").first()
    user2 = db.session.query(User).filter(
        User.email == "*****@*****.**").first()
    if user is None and user2 is None:
        user = User(email="*****@*****.**",
                    password=p1,
                    first_name="user1",
                    last_name="beta",
                    birthday="2019-09-05")
        user2 = User(email="*****@*****.**",
                     password=p2,
                     first_name="user2",
                     last_name="beta",
                     birthday="2019-09-05")
        circle = Circle("Cercle Beta 1")
        db.session.commit()
        UserToCircle(user=user, circle=circle, privilege="ADMIN")
        UserToCircle(user=user2, circle=circle)
        db.session.commit()
        device = db.session.query(Device).filter(
            Device.username == "device1").first()
        if device is None:
            device = Device(name="Device beta 1")
            device.circle = circle
            device.username = "******"
            device.set_password("test")
            device.activate(device.key)
            db.session.commit()
        if len(circle.conversations) == 0:
            conversation = Conversation(device_access=True,
                                        name="Conversation avec device",
                                        circle=circle)
            conversation2 = Conversation(device_access=False,
                                         name="Conversation sans device",
                                         circle=circle)
            db.session.commit()
            if len(user.conversation_links) == 0:
                cl1 = UserToConversation(privilege="ADMIN",
                                         user=user,
                                         conversation=conversation)
                cl2 = UserToConversation(user=user2, conversation=conversation)
                db.session.commit()
                Message(content="Message conversation avec device from user1",
                        link=cl1,
                        conversation=conversation)
                Message(content="Message conversation avec device from user2",
                        link=cl2,
                        conversation=conversation)
                message3 = Message(
                    content="Message conversation avec device from device",
                    is_user=False,
                    conversation=conversation)
                message3.device = device
                db.session.commit()
            if len(user2.conversation_links) == 0:
                cl3 = UserToConversation(privilege="ADMIN",
                                         user=user,
                                         conversation=conversation2)
                cl4 = UserToConversation(user=user2,
                                         conversation=conversation2)
                db.session.commit()
                Message(content="Message conversation sans device from user1",
                        link=cl3,
                        conversation=conversation2)
                Message(content="Message conversation sans device from user2",
                        link=cl4,
                        conversation=conversation2)
        db.session.commit()
示例#12
0
 def create_circle(self):
     self.circle = Circle("TESTCONVUPDATE")
     self.link = UserToCircle()
     self.link.user = self.user1
     self.link.circle = self.circle
     db.session.commit()