Exemplo n.º 1
0
def update_contact(user_id, contact_id):
    user = database.get_user_by_id(user_id)
    ping(user)
    contact = database.get_contact_by_id(contact_id)
    try:
        if request.form['Update_button'] is not None:
            values = (contact_id, request.form['Name'], request.form['Number'],
                      request.form['Note'], user.get_id())
            database.update_contact(Contact(*values))
    except KeyError:
        app.logger.info(
            'KeyError exception encountered when updating contact.')
        try:
            if request.form['Delete_button'] is not None:
                database.delete_contact(database.get_contact_by_id(contact_id))
        except KeyError:
            app.logger.error(
                'KeyError exception encountered when deleting contact.')
        except:
            app.logger.error(
                'Unidentified exception encountered when deleting contact.')
    except:
        app.logger.info(
            'Unidentified exception encountered when updating contact.')
    return redirect(url_for('display_contacts', user_id=user.get_id()))
Exemplo n.º 2
0
def create_contact_post(user_id):
    user = database.get_user_by_id(user_id)
    ping(user)
    values = (None, request.form['Name'], request.form['Number'],
              request.form['Note'], user.get_id())
    if database.create_contact(Contact(*values)) is True:
        return redirect(url_for('display_contacts', user_id=user.get_id()))
    else:
        return 'Could not create contact. Does this contact exist already?'
Exemplo n.º 3
0
def display_contact(user_id, contact_id):
    user = database.get_user_by_id(user_id)
    ping(user)
    contact = database.get_contact_by_id(contact_id)
    if contact is None:
        app.logger.error('No contact with this id.')
    return render_template('contact.html',
                           user_id=user.get_id(),
                           contact=contact)
Exemplo n.º 4
0
def display_user_profile(user_id):
    user = database.get_user_by_id(user_id)
    if user is None or False:
        return 'Error displaying user profile'
    username = user.get_name()
    number = user.get_number()
    return render_template('user_info.html',
                           user=user,
                           username=username,
                           number=number)
Exemplo n.º 5
0
def display_contacts(user_id):
    user = database.get_user_by_id(user_id)
    ping(user)
    contacts = database.get_contacts_by_user_id(user)

    if contacts is None:
        app.logger.info('No contacts with this user id')
        return render_template('contacts.html', user_id=user.get_id())
    elif contacts is False:
        app.logger.error('Error getting contact by user id')
        return 'Error getting contact by user id'
    app.logger.info('At least 1 contact with this user id exists')
    return render_template('contacts.html',
                           contacts=contacts,
                           user_id=user.get_id())
Exemplo n.º 6
0
def create_contact_get(user_id):
    user = database.get_user_by_id(user_id)
    ping(user)
    return render_template('create_contact.html', user_id=user.get_id())
Exemplo n.º 7
0
def action_change_secret(request):
    token = jwt.decode(request['token'], 'secret', algorithm='HS256')
    database.change_secret(token['id'], request['secret'])
    user = database.get_user_by_id(token['id'])
    response = {'user': user}
    sock.sendto(bytearray(str(response), 'utf-8'), ('', int(token['port'])))