Beispiel #1
0
def get_data(sql):
    config = ReadConfig()
    data = config.get_section('db')
    con = Db(
        host=data['host'],
        port=data['port'],
        user=data['user'],
        password=data['password'],
        db=data['db']
    )
    return con.get_df(sql)
Beispiel #2
0
 def add(self, dict):
     with Db.get() as self._db:
         dict["date"] = datetime.now()
         message = Message.add(self._db, dict)
         self._db.commit()
         self._db.refresh(message)
         return message
Beispiel #3
0
 def add(self, dict):
     with Db.get() as self._db:
         if "password" in dict:
             dict["password"] = hashpw(dict["password"].encode('utf8'), gensalt())
         user = User.add(self._db,dict)
         self._db.commit()
         self._db.refresh(user)
         return user
Beispiel #4
0
    def login(self, dict):
        with Db.get() as self._db:
            user = User.get_by_email(self._db, dict["email"])
            user_dict = user[0].to_json_dict(include=['password'])

            if hashpw(dict['password'].encode('utf-8'), user_dict['password'].encode('utf-8')).decode('utf-8') == user_dict['password']:
                login_user(user[0])
                return user
            else:
                return {'message':'Incorrect Password'}
Beispiel #5
0
 def add_user_message_mapping(self, dict, placeholder_name):
     with Db.get() as self._db:
         placeholder = Placeholder.get_by_name(self._db, placeholder_name)
         mapping_dict = {
             "user_id": dict["user_id"],
             "placeholder_id": placeholder.id,
             "message_id": dict["message_id"]
         }
         user_message_mapping = UserMessageMapping.add_mapping(self._db, mapping_dict)
         self._db.commit()
         self._db.refresh(user_message_mapping)
         return user_message_mapping
Beispiel #6
0
    def save_to_drafts(self, dict):
        with Db.get() as self._db:
            sender = UserService().get_by_email(dict['sender_email'])
            dict['creator_id'] = sender['id']

            #add message
            message_dict = MessageService().convert_to_message_dict(dict)
            message_object = MessageService().add(message_dict)

            dict['message_id'] = message_object.id

            #add mapping of sender with placeholder as Sent Mail
            dict['user_id'] = sender["id"]
            MessageService().add_user_message_mapping(dict, 'drafts')

            return message_dict
Beispiel #7
0
    def get_user_message_mapping(self, user_id, placeholder_name=None):
        with Db.get() as self._db:
            placeholder = Placeholder.get_by_name(self._db, placeholder_name)
            user = User.get(self._db, user_id)

            if len(user):
                user_dict = user[0].to_json_dict()
                user_message_mappings = UserMessageMapping.get_mapping(self._db, user_id)

                mapping_arr = []
                for umm in user_message_mappings:
                    if umm.placeholder_id == placeholder.id:
                        message = Message.get(self._db, umm.message_id)
                        umm_dict = umm.to_json_dict()
                        umm_dict["message"] = message.to_json_dict()
                        mapping_arr.append(umm_dict)

                user_dict['mp'] = mapping_arr

                return user_dict
Beispiel #8
0
    def compose(self, dict):
        with Db.get() as self._db:

            sender = UserService().get_by_email(dict['sender_email'])
            dict['creator_id'] = sender['id']

            #add message
            message_dict = MessageService().convert_to_message_dict(dict)
            message_object = MessageService().add(message_dict)

            dict['message_id'] = message_object.id

            #add mapping of sender with placeholder as Sent Mail
            dict['user_id'] = sender["id"]
            MessageService().add_user_message_mapping(dict, 'sent_mail')

            #add mapping of recipient with placeholder as Inbox
            to_emails = dict['recipient_email'].split(',')
            for email in to_emails:
                recipient = UserService().get_by_email(email.strip())
                dict['user_id'] = recipient["id"]
                MessageService().add_user_message_mapping(dict, 'inbox')

            return message_object
Beispiel #9
0
import os

from flask import Flask

from common.conf import Conf

from common.database import Db, EventDb
from common.decorator import Controller, Permissions, Security

from flask_cors import CORS

flask = Flask(__name__, template_folder="templates", static_folder="../static")
CORS(flask)

Conf.get_instance().init(os.path.dirname(os.path.realpath(__file__)))
Db.get_instance().init()

controller = Controller.get_instance()
# permissions = Permissions.get_instance()
security = Security.get_instance()


Beispiel #10
0
 def get(self, message_id, include):
     with Db.get() as self._db:
         return Message.get(self._db, message_id, include)
Beispiel #11
0
 def update_message(self, id, dict):
     with Db.get() as self._db:
         Message.update(self._db, id, dict)
         self._db.commit()
         return dict
Beispiel #12
0
 def update_user_message_mapping(self, mapping_id, dict):
     with Db.get() as self._db:
         UserMessageMapping.update(self._db, mapping_id, dict)
         self._db.commit()
         return dict
Beispiel #13
0
 def delete(self, mapping_id):
     with Db.get() as self._db:
         #update the user message mapping by updating the placeholder as trash
         placeholder = Placeholder.get_by_name(self._db, 'trash')
         return MessageService().update_user_message_mapping(
             mapping_id, {'placeholder_id': placeholder.id})
Beispiel #14
0
 def forward(self, dict):
     with Db.get() as self._db:
         message = self.compose(dict)
         MessageService().update_message(dict['child_message_id'],
                                         {'parent_message_id': message.id})
         return
Beispiel #15
0
 def get_placeholder_mails(self, user_id, placeholder_name):
     with Db.get() as self._db:
         return MessageService().get_user_message_mapping(user_id, placeholder_name)
Beispiel #16
0
 def get_by_email(self, email):
     with Db.get() as self._db:
         user = User.get_by_email(self._db, email)
         return user[0].to_json_dict()