def connect_with_admin(self, data):
     data = dict(json.loads(data))
     if not hf.check_session_id(data): return '310'
     else:
         hf.send_email(data['theme'], '*****@*****.**',
                       'Письмо от ' + data['email'] + '. ' + data['text'])
         return jsonify("send_email")
 def send_message(self, data):
     if not hf.check_session_id(data): return
     chat = chat_fund.find_one({
         'user_id': data['user_id'],
         'user_f_id': data['user_f_id'],
         'num': data['num'],
     })
     mes = {
         'mes': data['mes'],
         'from': data['from'],
         'id': len(chat['messages']),
         'time': datetime.utcnow().isoformat(),
         'is_readed': False
     }
     chat['messages'].append(mes)
     chat_fund.find_and_modify(
         query={
             'user_id': data['user_id'],
             'user_f_id': data['user_f_id'],
             'num': data['num']
         },
         update={"$set": {
             "messages": chat['messages']
         }})
     fund_sid = users.find_one({
         'user_id': data['user_f_id'],
     })
     business_sid = users.find_one({
         'user_id': data['user_id'],
     })
     emit('new_message', mes, room=fund_sid['sid'])
     emit('new_message', mes, room=business_sid['sid'])
 def get_chat(self, data):
     if not hf.check_session_id(data): return
     chat = chat_fund.find_one({
         'user_id': data['user_id'],
         'user_f_id': data['user_f_id'],
         'num': data['num'],
     })
     del chat['_id']
     emit('get_chat', chat)
 def get_my_now_projects(self, data):
     data = dict(json.loads(data))
     if not hf.check_session_id(data): return '310'
     else:
         res = []
         user = users.find_one({"email": data['email']})
         if user['role'] == 'fund':
             for project in user['projects']['now']:
                 res.append(user['projects']['now'][project])
         return jsonify(res)
 def get_information(self, data):
     data = dict(json.loads(data))
     if not hf.check_session_id(data): return '310'
     else:
         user = users.find_one({"email": data['email']})
         del user['_id']
         del user['password']
         del user['banned']
         del user['ban_time']
         del user['ban_reason']
         del user['session_id']
         return jsonify(user)
 def add_project(self, data):
     data = dict(json.loads(data))
     if not hf.check_session_id(data): return '310'
     else:
         user = users.find_one({"email": data['email']})
         if user['role'] != 'fund': return 310
         else:
             id = self.make_session_id()
             user['projects']['now'][id] = {
                 'num': id,
                 'user_id': data['user_id'],
                 'category': data['category'],
                 'type_help': data['type_help'],
                 'image': data['image'],
                 'city': data['city'],
                 'title': data['title'],
                 'help': data['help'],
                 'money': data['money'],
                 'fund': data['fund'],
                 'chats': [],
                 'helpers': [],
             }
             users.update_one({"email": data['email']},
                              {"$set": {
                                  "projects": user['projects']
                              }})
             projects.insert_one({
                 'author': data['email'],
                 'num': id,
                 'user_id': data['user_id'],
                 'category': data['category'],
                 'type_help': data['type_help'],
                 'image': data['image'],
                 'city': data['city'],
                 'title': data['title'],
                 'help': data['help'],
                 'money': data['money'],
                 'fund': data['fund'],
             })
             if data['city'] not in cities:
                 cities[data['city']] = 1
             else:
                 cities[data['city']] += 1
             return jsonify('OK')
 def create_chat(self, data):
     if not hf.check_session_id(data): return
     chat = chat_fund.find_one({
         'user_id': data['user_id'],
         'user_f_id': data['user_f_id'],
         'num': data['num'],
     })
     if chat == None:
         chat_fund.insert_one({
             'user_id': data['user_id'],
             'user_f_id': data['user_f_id'],
             'num': data['num'],
             'fund': data['fund'],
             'business': data['business'],
             'messages': [],
         })
         user = users.find_one({
             {
                 "user_id": data['user_f_id']
             },
         })
         user['projects']['now'][data['num']]['chats'].append({
             'business':
             data['business'],
             'user_id':
             data['user_id']
         })
         users.find_and_modify(
             query={"user_id": data['user_f_id']},
             update={"$set": {
                 "projects": user['projects']
             }})
     emit('create_chat', {
         'user_f_id': data['user_f_id'],
         'num': data['num']
     })
 def read_message(self, data):
     if not hf.check_session_id(data): return
 def new_sid(self, data):
     if not hf.check_session_id(data): return
     users.find_and_modify(query={"email": data['email']},
                           update={"$set": {
                               "sid": data['sid']
                           }})
 def delete_chat(self, data):
     if not hf.check_session_id(data): return