Ejemplo n.º 1
0
def store_user():
    print(request)
    print(request.content_type)
    # if request.content_type != JSON_MIME_TYPE:
    #     return onerror_response('Invalid Content Type')

    data = request.json
    if not all([data.get('name')]):
        return onerror_response('Missing field/s (name) (fcm_token)')

    params = {
        'name': data['name'],
        'email': data['email'],
        'username': data['username'],
        'password': data['password'],
        'phone': data['phone'],
        'fcm': data['fcm']
    }

    query = 'INSERT INTO user ("name", "email","username", "password", "phone",  "fcm") ' \
            'VALUES (:name,  :email, :username, :password, :phone, :fcm);'

    try:
        g.db.execute(query, params)
    except sqlite3.IntegrityError as s:
        stringer = str(s)
        data = [{'exception': stringer}]
        return onerror_response(data)
        pass

    g.db.commit()

    return user_details_resp()
Ejemplo n.º 2
0
def update_token(user_id):
    # if request.content_type != JSON_MIME_TYPE:
    #     return onerror_response('Invalid Content Type')

    data = request.json
    if not all([data.get('fcm_token')]):
        return onerror_response('Missing field/s (fcm_token)')

    params = {'id': user_id}
    query = 'SELECT * FROM user WHERE user.id = :id'

    cursor = g.db.execute(query, params)
    if is_data_not_exist(cursor):
        return onerror_response("No User exist")

    # Update it
    token = data.get('fcm_token')
    g.db.execute('''UPDATE user SET fcm_token = ? WHERE id = ?''',
                 (token, user_id))
    g.db.commit()

    params = {'id': user_id}
    query = 'SELECT * FROM user WHERE user.id = :id'
    cursor = g.db.execute(query, params)

    user = [{
        'id': row[0],
        'name': row[1],
        'fcm_token': row[2]
    } for row in cursor.fetchall()]

    return onsuccess_response(user)
Ejemplo n.º 3
0
def query_all_stories():
    try:
        cursor = g.db.execute(
            'SELECT id, story_art, story_title, story_body, elapsed, author, category, likes, dislikes, comments FROM story;'
        )

    except Exception as e:
        print(e)
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    stories = [{
        'id': row[0],
        'story_art': row[1],
        'story_title': row[2],
        'story_body': row[3],
        'elapsed': row[4],
        'author': row[5],
        'category': row[6],
        'likes': row[7],
        'dislikes': row[8],
        'comments': row[9]
    } for row in cursor.fetchall()]

    return onsuccess_response(stories)
Ejemplo n.º 4
0
def user_login():
    data = request.json
    username = data.get('username')
    password = data.get('password')
    params = {'uname': username, 'pword': password}
    query = 'SELECT * FROM user where username = :uname AND password = :pword'
    try:
        cursor = g.db.execute(query, params)
    except sqlite3.IntegrityError as s:
        print(s)

    user = [{
        'name': row[1],
        'email': row[2],
        'username': row[3],
        'password': row[4],
        'phone': row[5]
    } for row in cursor.fetchall()]

    print(user)

    if is_data_exist(user):
        return onsuccess_response(user)
    else:
        failed = [{'login': '******'}]
        return onerror_response(failed)
Ejemplo n.º 5
0
def get_users():
    try:
        cursor = g.db.execute('SELECT fcm_token FROM user;')
    except:
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    user = [{'fcm_token': row[0]} for row in cursor.fetchall()]

    fcm_reg_list = []
    for chunks in user:
        for attribute, value in chunks.items():
            fcm_reg_list.append('device ' + value)
    return fcm_reg_list
Ejemplo n.º 6
0
def user():
    try:
        cursor = g.db.execute('SELECT id, name, fcm_token FROM user;')
    except:
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    user = [{
        'id': row[0],
        'name': row[1],
        'fcm_token': row[2]
    } for row in cursor.fetchall()]

    return onsuccess_response(user)
Ejemplo n.º 7
0
def user_details_resp():
    try:
        cursor = g.db.execute('SELECT * FROM user ORDER BY id DESC LIMIT 1;')
    except:
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    user = [{
        'id': row[0],
        'name': row[1],
        'fcm_token': row[2]
    } for row in cursor.fetchall()]

    data = [{'registration': "ok"}]

    return onsuccess_response(data)
Ejemplo n.º 8
0
def notification_id_for_push():
    try:
        cursor = g.db.execute('SELECT * FROM notifications ORDER BY id DESC LIMIT 1;')
    except:
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    notifications = [{
        'id': row[0],
        'notification_id': row[1],
        'name': row[2],
        'priority': row[3],
        'count': row[4]
    } for row in cursor.fetchall()]

    return notifications
Ejemplo n.º 9
0
def query_notiication_list():
    try:
        cursor = g.db.execute('SELECT id, notification_id, name, priority, count FROM notifications;')
    except:
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    notifications = [{
        'id': row[0],
        'notification_id': row[1],
        'name': row[2],
        'priority': row[3],
        'count': row[4]
    } for row in cursor.fetchall()]

    return onsuccess_response(notifications)
Ejemplo n.º 10
0
def store_user():
    print(request)
    print(request.content_type)
    # if request.content_type != JSON_MIME_TYPE:
    #     return onerror_response('Invalid Content Type')

    data = request.json
    if not all([data.get('name')]):
        return onerror_response('Missing field/s (name) (fcm_token)')

    query = ('INSERT INTO user ("name", "fcm_token") '
             'VALUES (:name, :fcm_token);')

    params = {'name': data['name'], 'fcm_token': ''}
    g.db.execute(query, params)
    g.db.commit()

    return user_details_resp()
Ejemplo n.º 11
0
def store_notification():
    print(request)
    print(request.content_type)
    # if request.content_type != JSON_MIME_TYPE:
    #     return onerror_response('Invalid Content Type')

    data = request.json
    if not all([data.get('notification_id'), data.get('name'), data.get('priority'), data.get('count')]):
        error = json.dumps({'error': 'Missing field/s (notification_id, name, priority, count)'})
        return json_response(error, 400)

    query = ('INSERT INTO notifications ("notification_id", "name", "priority", "count") ' 'VALUES (:notification_id, :name, :priority, :count);')

    params = {
        'notification_id': data['notification_id'],
        'name': data['name'],
        'priority': data['priority'],
        'count': data['count']
    }
    g.db.execute(query, params)
    g.db.commit()

    try:
        cursor = g.db.execute('SELECT id, notification_id, name, priority, count FROM notifications;')
    except:
        if request.content_type != JSON_MIME_TYPE:
            return onerror_response('No data available')

    notifications = [{
        'id': row[0],
        'notification_id': row[1],
        'name': row[2],
        'priority': row[3],
        'count': row[4]
    } for row in cursor.fetchall()]

    forward_push(get_users(), notification_id_for_push())
    return onsuccess_response(notifications)