Пример #1
0
    def authenticate(self, environ, identity):
        """
        Check the given auth details and if its ok return the
        userid for the given details.

        See: (IAuthenticatorPlugin)
            http://docs.repoze.org/who/narr.html#writing-an-authenticator-plugin

        :returns: None indicated auth failure.

        """
        self.log.info("authenticate: %r" % identity)
        returned = None

        login = identity['login']
        password = identity['password']

        self.log.info("authenticate: looking for user <%r>" % login)
        u = user.find(username=login)
        if u:
            self.log.info("authenticate: validating password for <%r>" % login)
            #print "user '%s' hpw '%s'" % (user,user['password'])
            if u[0].validate_password(password):
                returned = u[0].username
                self.log.info("authenticate: validated OK <%r>" % returned)
            else:
                self.log.info("authenticate: FAILED")

        else:
            self.log.info("authenticate: no mathcing user")

        return returned
Пример #2
0
def checkFind():
    global _book_catalog, _author_lst

    size = len(_author_lst)
    while True:
        author_num = randint(0, size - 1)
        author = _author_lst[author_num]

        books = list(_book_catalog[author])
        books_num = len(books)
        if books_num == 0:
            continue

        book_num = randint(0, books_num - 1)
        title = books[book_num]

        t = time.time()
        user_find = user.find(author, title)
        t1 = time.time()
        dt = t1 - t
        dt *= 100000

        if user_find and dt < 800:
            return True
        return False
Пример #3
0
def post_edit():
  session = get_session()
  if not session: bottle.redirect('/')
  luser = user.find(session['uid'])
  if not luser: bottle.redirect('/logout')
  data = user.get_data(session['uid'])
  cold = bottle.request.POST['cold']
  hot = bottle.request.POST['hot']
  counters.update(data[0],data[1],cold,hot,datetime.date.today(),session['uid'])
  return bottle.redirect('/report')
def alert_admins_pending(pending_conversation):
    print('Alerting Admins of new message')
    if len(pending_conversation['owners']) == 0:
        agents = [u['id'] for u in user.find(user_type='agent')]
    else:
        agents = pending_conversation['owners']
    for agent in agents:
        text = pending_conversations_agent_indicator(agent)
        message = {'text': text, 'user_id': agent}
        chat_api.reply(text, message)
    return None
Пример #5
0
def current_user():
    """
    If there is a user logged in during this session, then this function will
    return the object representing that user. If not, `None` is returned.
    """

    if not 'user_id' in session:
        return None
    else:
        user_id = session['user_id']
        user = user_lib.find(unique=int(user_id))
        return user
Пример #6
0
    def add_metadata(self, environ, identity):
        """
        Add the firstname, lastname, name to the identity from
        the user details we recovered from the CSV data.

        See: (IMetadataProvider)
            http://docs.repoze.org/who/narr.html#writing-a-metadata-provider-plugin

        """
        userid = identity.get('repoze.who.userid')
        u = user.find(username=userid)
        if u[0]:
            identity.update(u[0].to_dict())
Пример #7
0
def logic(interaction, message):
  user_id = message['user_id']
  chat_api.reply(interaction['text'], message)
  users_owned = user.find(owner=user_id) #message['user_id']
  for user_owned in users_owned:
      for thread_owned in user_owned['threads']:
          user_name = user_owned['name']
          user_phone = user_owned['phone']
          thread_label = thread.printable_label(thread_owned['label'])
          thread_status = thread.printable_status(thread_owned['label'])
          last_message = conversation.get_canonical_message(user_owned['id'],thread_owned['last_canonical_message_id'])
          text_message = f"👤{user_name}\n☎️{user_phone}\n⚠️{thread_label}/{thread_status}\n🗣️Último mensaje:('{last_message['text']}')"
          chat_api.reply(text_message, message)
  return True
Пример #8
0
def logic(interaction, message):
    user_id = message['user_id']
    text = message['text']

    users_list = list(user.users.find({'type': 'agent'})) #message['user_id']
    if len(users_list) == 0:
        chat_api.reply("No hay agentes dados de alta", message)
        return True

    agent_uuid = text.split(' ')[0].lower()
    agent_data_uuid = user.find(uuid = agent_uuid)

    if len(agent_data_uuid) == 0:
        r_text = 'No se encontro ningún agente con dicho identificador'
        chat_api.reply(r_text, message)
        return True

    agent_data = agent_data_uuid[0]
    user_context = conversation.context(user_id)
    redirect_user_id = user_context.get('redirect_user')

    if redirect_user_id is None:
        r_text = 'No tienes ninguna conversación seleccionada'
        chat_api.reply(r_text, message)
        return True

    user_data = user.get(redirect_user_id)
    current_p_results = pending_conversations.find(user_id = redirect_user_id, closed = False)
    current_p = current_p_results[0].get('id') if len(current_p_results)>0 else None

    if current_p is None:
        pending_conversations.create(redirect_user_id, [agent_uuid])
        current_p_results = pending_conversations.find(user_id = redirect_user_id, closed = False)
        current_p = current_p_results[0].get('id') if len(current_p_results)>0 else None
    else:
        pending_conversations.switch_owner(current_p, user_id, agent_uuid)

    conversation.update_context(user_id, 'redirect_user', None)
    conversation.update_context(user_id, 'redirect_name', None)
    conversation.update_context(user_id, 'redirect_phone', None)
    conversation.update_context(user_id, 'conversational_level', 'user')
    conversation.update_context(user_id, 'current_pending_conversation', None)

    r_text = f"{agent_uuid} ha recibido al usuario {user_data['uuid']}"
    chat_api.reply(r_text, message)

    a_text = f"Has recibido al usuario {user_data['uuid']} de {user_id}"
    chat_api.reply(a_text, {'user_id': agent_uuid, 'text': a_text})
    return True
Пример #9
0
def logic(interaction, message):

    user_id = message['user_id']
    # We can also use the command number detected before
    redirect_user_number = message['text'].split(' ')[0].lower()
    users_uuid = user.find(uuid=redirect_user_number)
    try:
        user_found = users_uuid[0]
    except:
        user_found = None

    if user_found is not None:
        conversation.update_context(user_id, 'redirect_user', user_found['id'])
        conversation.update_context(user_id, 'redirect_name',
                                    user_found['name'])
        conversation.update_context(user_id, 'redirect_phone',
                                    user_found['phone'])
        conversation.update_context(user_id, 'conversational_level', 'user')

        if user_found.get('owner') is None:
            user.update(user_found['id'], {'owner': user_id})

        current_p_results = pending_conversations.find(
            user_id=user_found['id'], closed=False)
        current_p = current_p_results[0].get(
            'id') if len(current_p_results) > 0 else None
        if current_p is None:
            pending_conversations.create(user_found['id'], owners=[user_id])
            current_p_results = pending_conversations.find(
                user_id=user_found['id'], closed=False)
            current_p = current_p_results[0].get(
                'id') if len(current_p_results) > 0 else None

        conversation.update_context(user_id, 'current_pending_conversation',
                                    current_p)
        pending_conversations.add_owner(current_p, user_id)
        pending_conversations.remove_new_messages(current_p)

        s_msg = "Haz selecionado al " + user_found['uuid'] + " " + user_found[
            'name']
        chat_api.reply(s_msg, message)

        s_msg = "Con la conversacion pendiente " + str(current_p)
        chat_api.reply(s_msg, message)

    else:
        list_users.logic()
    return True
Пример #10
0
def checkFindDeleted():
    global _book_catalog, _author_lst, _deleted

    size = len(_deleted)
    if size == 0:
        return True

    num = randint(0, size - 1)
    (author, title) = list(_deleted)[num]

    t = time.time()
    user_find = user.find(author, title)
    t1 = time.time()
    dt = t1 - t
    dt *= 100000

    if not user_find and dt < 1000:
        return True
    return False
Пример #11
0
def restoreDeleted():
    global _book_catalog, _deleted

    size = len(_deleted)

    num = randint(0, size - 1)
    pair = list(_deleted)[num]
    _deleted.remove(pair)
    __add(*pair)

    t = time.time()
    user_find = user.find(*pair)
    t1 = time.time()
    dt = t1 - t
    dt *= 100000

    if user_find and dt < 800:
        return True
    return False
Пример #12
0
def login():
    # Get the data provided by the user
    username = request.form["username"]
    password = request.form["password"]

    # Hash the password
    hasher = hashlib.sha1()
    hasher.update(password)
    password_hash = hasher.hexdigest()

    # Get user with matching username
    user = user_lib.find(username=username)
    if user == None:
        return "No such user"
    elif user.password_hash != password_hash:
        return "Wrong password"
    else:
        session["user_id"] = user.unique
        return "success"
Пример #13
0
def check(test_cases_num):
    global dictionary, eng_lst

    size = len(eng_lst)
    errors = 0
    for i in range(test_cases_num):
        num = randint(0, size - 1)
        eng = eng_lst[num]

        t = time.time()
        user_search = user.find(eng)
        t1 = time.time()
        dt = t1 - t
        dt *= 100000
        # print('eng = %s, user_search = %s,  find time: %d ms' % (eng, user_search, dt))
        # print('find time: %d ms' % dt)
        if user_search != dictionary[eng] or dt > 100:
            errors += 1

    return errors
Пример #14
0
def checkInvalid(test_cases_num):
    global dictionary, eng_lst, invalid_eng

    size = len(invalid_eng)
    errors = 0
    for i in range(test_cases_num):
        num = randint(0, size - 1)
        eng = invalid_eng[num]
        if eng in dictionary:
            continue

        t = time.time()
        user_search = user.find(eng)
        t1 = time.time()
        dt = t1 - t
        dt *= 100000
        # print('eng = %s, user_search = %s,  find time: %d ms' % (eng, user_search, dt))
        # print('find time: %d ms' % dt)
        if user_search != "" or dt > 100:
            errors += 1

    return errors
Пример #15
0
def logic(interaction, message):
    user_id = message['user_id']
    user_context = conversation.context(user_id)
    name = user_context.get('new_user_info_name')
    phone = user_context.get('new_user_info_phone')
    country = user_context.get('new_user_info_country')
    conversation.update_context(user_id, 'new_user_info_name', None)
    conversation.update_context(user_id, 'new_user_info_phone', None)
    conversation.update_context(user_id, 'new_user_info_country', None)

    id_create_user = user.phone_to_id(phone)

    users_by_name = user.find(name=name)
    user_same_name = users_by_name[0] if len(users_by_name) > 0 else None

    users_by_phone = user.find(phone=phone)
    user_same_phone = users_by_phone[0] if len(users_by_phone) > 0 else None

    no_change = False
    if user.get(
            id_create_user
    ) is None and user_same_phone is None and user_same_name is None:

        user_data = {
            'name': name,
            'phone': phone,
            'country': country,
            'owner': user_id,
        }

        user.create(id_create_user, user_data, 'outbound')

        message_start = {
            'user_id': id_create_user,
            'text': '***Inicio Conversacion Outbound'
        }
        pending_conversations.create(id_create_user, [user_id])
        conversation.update_context(id_create_user, 'last_reply',
                                    datetime.now())

        user_register = f"Haz registrado a un nuevo usuario. {name} ({phone})"
        chat_api.reply(user_register, message)

    elif user_same_phone is not None:
        if user_same_phone['name'] != name:
            user.update(user_same_phone['id'], {'name': name})
            name_change = f"Haz cambiado el nombre del usuario con nombre de {name}"
            chat_api.reply(name_change, message)
        else:
            no_change = True

    elif user_same_name is not None:
        if user_same_name['phone'] != phone:
            user.update(user_same_name['id'], {'phone': phone})
            phone_change = f"Haz cambiado el telefono del usuario con nombre de {name}"
            chat_api.reply(phone_change, message)
        else:
            no_change = True

    if no_change == True:
        chat_api.reply('El usuario no sufrio cambios', message)

    return True
Пример #16
0
def report():
  session = get_session()
  if not session: bottle.redirect('/')
  luser = user.find(session['uid'])
  if not luser: bottle.redirect('/logout')
  return bottle.template('report',List=0,home=False)
Пример #17
0
def edit():
  session = get_session()
  if not session: bottle.redirect('/')
  luser = user.find(session['uid'])
  if not luser: bottle.redirect('/logout')
  return bottle.template('edit')