Beispiel #1
0
def do_login_google(token):
    status = {}
    try:
        idInformation = id_token.verify_oauth2_token(
            token, requests.Request(),
            f'''%s.apps.googleusercontent.com''' % conf.google_token)
        logger.info(idInformation)

        if idInformation['iss'] not in [
                'accounts.google.com', 'https://accounts.google.com'
        ]:
            status[ok_login] = False
            return status

        # Get principalId from idInformation
        status[ok_login] = True
        #  google_login = idInformation['sub']
        #  google_login = idInformation['name']
        google_login = idInformation['email']
        if (not db_queries.login_exist(google_login)):
            db_queries.add_user(google_login, 'SecretGooglePassword')
        status[cookie] = db_queries.add_cookie(google_login)
        return status

    except ValueError as err:
        status[ok_login] = False
        return status
def verify_user(connection, user_id, message):
    user = db_queries.get_user(connection, user_id)
    if not user:
        db_queries.add_user(connection, message)
        user = db_queries.get_user(connection, user_id)

    return get_user_dict(user)
Beispiel #3
0
def second():
    # need refactor dbwrapper calls
    dbwrapper = db_queries.DBWrapper(DEFFAULT_DEVICE_TYPE)
    # getting computers id:
    if "type" in request.args.keys():
        session["type"] = request.args["type"]
        dbwrapper = db_queries.DBWrapper(request.args["type"])
        devices_id, devices_dss, dss_dict = filtered_devices_id(FILTERS[dbwrapper.device], request.args, dbwrapper)
        if "user_id" in session:
            db_queries.delete_user(session["user_id"])
            del session["user_id"]
        user_id = db_queries.add_user(devices_id, devices_dss)
        session["user_id"] = user_id
    else:
        # first page (without_question)
        devices_id, devices_dss, dss_dict = None, None, {}  # nothing to return
        return render_template(
            "QandA.html",
            computers=[],
            filters=FILTERS[u"all"],
            pagination_pages=[],
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=True,
            prom=PROM,
        )

    if devices_id:
        last_page = int(round(float(len(devices_id)) / COMPUTERS_ON_PAGE + 0.49))
        first_comp_index = 0
        last_comp_index = min(COMPUTERS_ON_PAGE, len(devices_id))
        devices_id_on_page = devices_id[first_comp_index:last_comp_index]
        devices_dss_on_page = devices_dss[first_comp_index:last_comp_index]
        pretty_devices = pretty_data.small_devices(devices_id_on_page, devices_dss_on_page, dbwrapper)
        return render_template(
            "QandA.html",
            computers=pretty_devices,
            filters=FILTERS[u"all"],
            pagination_pages=pretty_data.pagination_pages(last_page),
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=False,
            prom=PROM,
        )
    else:
        return render_template(
            "QandA.html",
            computers=[],
            filters=FILTERS[u"all"],
            pagination_pages=[],
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=False,
            prom=PROM,
        )
Beispiel #4
0
def second():
    #need refactor dbwrapper calls
    dbwrapper = db_queries.DBWrapper(DEFFAULT_DEVICE_TYPE)
    #getting computers id:
    if 'type' in request.args.keys():
        session['type'] = request.args['type']
        dbwrapper = db_queries.DBWrapper(request.args['type'])
        devices_id, devices_dss, dss_dict = filtered_devices_id(
            FILTERS[dbwrapper.device], request.args, dbwrapper)
        if 'user_id' in session:
            db_queries.delete_user(session['user_id'])
            del session['user_id']
        user_id = db_queries.add_user(devices_id, devices_dss)
        session['user_id'] = user_id
    else:
        # first page (without_question)
        devices_id, devices_dss, dss_dict = None, None, {}  # nothing to return
        return render_template('QandA.html',
                               computers=[],
                               filters=FILTERS[u'all'],
                               pagination_pages=[],
                               dss_dict=dss_dict,
                               tooltips=TOOLTIPS_DICT,
                               without_question=True,
                               prom=PROM)

    if devices_id:
        last_page = int(
            round(float(len(devices_id)) / COMPUTERS_ON_PAGE + 0.49))
        first_comp_index = 0
        last_comp_index = min(COMPUTERS_ON_PAGE, len(devices_id))
        devices_id_on_page = devices_id[first_comp_index:last_comp_index]
        devices_dss_on_page = devices_dss[first_comp_index:last_comp_index]
        pretty_devices = pretty_data.small_devices(devices_id_on_page,
                                                   devices_dss_on_page,
                                                   dbwrapper)
        return render_template(
            'QandA.html',
            computers=pretty_devices,
            filters=FILTERS[u'all'],
            pagination_pages=pretty_data.pagination_pages(last_page),
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=False,
            prom=PROM)
    else:
        return render_template('QandA.html',
                               computers=[],
                               filters=FILTERS[u'all'],
                               pagination_pages=[],
                               dss_dict=dss_dict,
                               tooltips=TOOLTIPS_DICT,
                               without_question=False,
                               prom=PROM)
Beispiel #5
0
 def test_add_user(self):
     with mock.patch("db_queries.generate_random_user_id", mocked_generate_user_id):
         self.assertEqual(self.TEST_ID, db_queries.add_user(self.TEST_USER))
         self.assertEqual(
             self.TEST_USER["name"],
             db.session.query(models.Users).get(self.TEST_ID).name,
         )
         self.assertEqual(
             self.TEST_USER["email"],
             db.session.query(models.Users).get(self.TEST_ID).email,
         )
         self.assertEqual(
             self.TEST_USER["imageURL"],
             db.session.query(models.Users).get(self.TEST_ID).profile_pic,
         )
Beispiel #6
0
def on_new_google_user(data):
    """
    login using google
    """
    print("Got an event for new google user input with data:", data)
    user = db_queries.add_user(data)
    print("USER IS: " + str(user))
    user_obj = db_queries.get_user(user)
    username = user_obj['name']
    user_email = user_obj['email']
    shopping_list = db_queries.get_shopping_list(user_obj["id"])
    cart_num_items = len(shopping_list)
    print("THIS IS " + str(username))
    socketio.emit(
        'logged in', {
            'username': username,
            'email': user_email,
            'cartNumItems': cart_num_items,
        })
Beispiel #7
0
def on_new_google_user(data):
    """
    login using google
    """
    user = db_queries.add_user(data)
    user_obj = db_queries.get_user(user)
    username = user_obj["name"]
    user_email = user_obj["email"]
    client_id = flask.request.sid
    shopping_list = db_queries.get_shopping_list(user_obj["id"])
    cart_num_items = len(shopping_list)
    socketio.emit(
        "logged in",
        {
            "userId": user,
            "username": username,
            "email": user_email,
            "cartNumItems": cart_num_items,
        },
        room=client_id,
    )
Beispiel #8
0
def do_signup(login, password):
    status = db_queries.add_user(login, password)
    return status