Example #1
0
def get_user_data_by_token(token):
    if database_helper.get_logged_in(token):
        data = database_helper.get_user_data_by_token(token)
        if data is not None:
            return json.dumps({"success": True, "message": "User data retrieved.", "data": data})
        return json.dumps({"success": False, "message": "No such user."})
    return json.dumps({"success": False, "message": "You are not signed in."})
Example #2
0
def change_password():
    token = request.headers.get('Token')
    data = request.get_json()
    if 'oldpassword' in data and 'newpassword' in data:
        if 5 <= len(data['newpassword']) <= 30:
            user_email = database_helper.get_user_data_by_token(
                token)[0]['email']
            user = find_user(user_email).get_json()[0]
            new_pw_hashed = bcrypt.generate_password_hash(data['newpassword'])
            if bcrypt.check_password_hash(user['password'],
                                          data['oldpassword']):
                result = database_helper.change_password(
                    token, user['password'], new_pw_hashed)
                print(result)
                if result:
                    return json.dumps({
                        "success": "true",
                        "message": "Password changed!"
                    }), 200
                else:
                    return json.dumps({
                        "success": "false",
                        "message": "Something went wrong!"
                    }), 500
        else:
            return '', 400
    else:
        return '', 400
Example #3
0
def get_user_data_by_token():
    # Gets the parsed contents of query string
    token = request.args.get('token')
    user_data = database_helper.get_user_data_by_token(token)

    if user_data is None:
        return jsonify(success=False, message="No such user!")

    media = []
    try:
        path = user_data['profile_pic']
        media_extension = path.rsplit('.', 1)[1]
        with open(path) as m:
            media.append([base64.b64encode(m.read()), media_extension])
    except IOError:
        # User deleted their profile picture, give them default
        path = app.config['DEFAULT_PIC']
        media_extension = path.rsplit('.', 1)[1]
        with open(path) as m:
            media.append([base64.b64encode(m.read()), media_extension])
        # Reset their profile picture
        print "Resetting their profile picture"
        database_helper.reset_profile_pic(path, user_data['email'])

    user_data['profile_pic'] = media
    return jsonify(success=True, message="User data retrieved!", data=user_data)
Example #4
0
def get_user_data_by_token():
    token1 = request.args.get('token')
    user = dh.get_user_data_by_token(token1)
    if user == "None":
        return 'No such user'
    else:
        return ",".join(user)
Example #5
0
def get_user_data_by_token():
    try:
        token = request.headers.get('token')
    except:
        return jsonify({
            "success": False,
            "message": "Could not get JSON-Input"
        })
    try:
        user = database_helper.get_user_data_by_token(token)
    except:
        return jsonify({"success": False, "message": user})

    if (user["success"]):
        #print (user)
        return jsonify({
            "success": True,
            "Message": "User data retrieved",
            "email": user["email"],
            "first_name": user["first_name"],
            "family_name": user["family_name"],
            "gender": user["gender"],
            "city": user["city"],
            "country": user["country"]
        })
    else:
        return jsonify({"success": False, "message": "Could not find user"})
Example #6
0
def get_user_data_by_token():
    """Get user data by token
        Given a token, returns corresponding user data
    """
    hashed_token = request.headers.get('token')
    data = request.get_json()

    email = data['email']
    url = '/get_user_data_by_token'
    token = database_helper.get_token_from_email(email)
    server_hash = sha256((token[0] + email + url).encode('utf-8')).hexdigest()

    userData = database_helper.get_user_data_by_token(token[0])
    print('GETUSERDATABYTOKEN: server_hash is:', server_hash,
          ' and hashed_token is: ', hashed_token)
    if userData != None and server_hash == hashed_token:
        res = jsonify({
            'success': True,
            'email': userData[0],
            'firstName': userData[1],
            'familyName': userData[2],
            'gender': userData[3],
            'city': userData[4],
            'country': userData[5]
        })
    else:
        res = jsonify({'success': False, 'message': 'Something went wrong!'})
    return res
Example #7
0
def get_user_data_by_token():
	token=request.args.get("token")
	if request.method == 'GET':
		if dh.is_user_logged_in_token(token)==True:	
			data=dh.get_user_data_by_token(token)
			data.pop(1)
			return json.dumps([{'success': True, 'message': "Success",'data': tuple(data)}])
		return json.dumps([{'success': False, 'message': "User not signed in"}])
Example #8
0
def get_user_data_by_token():
    token = request.form.get('token')
    user = dh.get_user_data_by_token(token)
    if user is None:
        error = 'error'
        return json.dumps({"success": "false", "message":"No such user."})
    else:
        u = ",".join(user)
        return json.dumps({"success": "true", "message": "User data retrieved.", "data": u})
Example #9
0
def get_user_data_by_token():
    token = request.args.get('token', '')

    logged = database_helper.user_logged_by_token(token=token)
    if logged:
        transfereddata = database_helper.get_user_data_by_token(token=token)
        transfereddata = json.loads(transfereddata)
        userdata = transfereddata['data']
        send_notification()
        return json.dumps({'success': True, 'message': 'Data transfered', 'data': userdata})
    else:
        return json.dumps({'success': False, 'message': 'User not logged', 'data': []})
Example #10
0
def get_user_data_by_token():
    """Get user data by token
	Given a token, returns corresponding user data
    """
    token = request.headers.get('token')
    data = database_helper.get_user_data_by_token(token)
    if data != None:
        res = jsonify({'success': True, 'email': data[0], 'firstName': data[1],
                       'familyName': data[2], 'gender': data[3], 'city': data[4], 'country': data[5]})
        return res
    res = jsonify({'success': False, 'message': 'Something went wrong!'})
    return res
Example #11
0
def getusertoken(token):
    if request.method=='GET':
        user_data = database_helper.get_user_data_by_token(token=token)
        if user_data is not False:
            return str(user_data)
        else:
            data = {}
            data['success'] = False
            data['message'] = 'Unsuccessful'
            json_token = json.dumps(data)
            return  json_token

    return
Example #12
0
def get_user_data_by_token():
    token = request.form.get('token')
    user = dh.get_user_data_by_token(token)
    if user is None:
        error = 'error'
        return json.dumps({"success": "false", "message": "No such user."})
    else:
        u = ",".join(user)
        return json.dumps({
            "success": "true",
            "message": "User data retrieved.",
            "data": u
        })
Example #13
0
def get_user_data_by_token():
    # Gets the parsed contents of query string
    token = request.args.get('token')
    user_data = database_helper.get_user_data_by_token(token)
    if user_data is None:
        return jsonify(success=False, message="Failed to retrieve user data!")
    data = {
        'email': user_data[0],
        'firstname': user_data[1],
        'familyname': user_data[2],
        'gender': user_data[3],
        'city': user_data[4],
        'country': user_data[5]
    }
    return jsonify(success="true", message="User data retrieved!", data=data)
def get_user_data_by_token():
    data = request.get_json()
    token = data['token']
    if token != None:
        result = database_helper.get_user_data_by_token(token)
        if result == None:
            return jsonify({
                'success': False,
                'message': "No data with requested token"
            })
        return jsonify(result)
    else:
        return jsonify({
            'success': False,
            'message': "Token has to be provided"
        })
Example #15
0
def get_user_data_by_token():
    token = request.headers.get('Token')
    if token is not None:
        result = database_helper.get_user_data_by_token(token)
        if result:
            return json.dumps({
                "success": "true",
                "message": "Requested user found!",
                "data": result[:]
            }), 200

        else:
            return json.dumps({
                "success": "false",
                "message": "Something went wrong!"
            }), 400
Example #16
0
def check_websocket():
    if request.environ.get('wsgi.websocket'):
        web_socket = request.environ['wsgi.websocket']
        message = json.loads(web_socket.receive())
        user = database_helper.get_user_data_by_token(
            message['token'])[0]['email']
        signed_in_users[user] = web_socket
        while not web_socket.closed:
            message = web_socket.receive()
            if message is not None:
                message = json.loads(message)
                message = {'message': 'Successfully logged in'}
                web_socket.send(json.dumps(message))
        try:
            del signed_in_users[user]
        except:
            pass
    return 'None'
Example #17
0
def get_user_data_by_token():
    data = request.get_json()
    token = data['token']
    if token != None:
        url = data['url']
        public_key = data['publicKey']
        authentication_data = database_helper.get_email_logged_user_new(
            public_key)
        stored_token = authentication_data['token']
        equal_hashed_token = False
        ########################## Token verification ##########################
        # 1. Recreate the blob using the stored token
        blob = ""
        i = 0
        while i < len(url):
            blob = blob + url[i]
            i = i + 3
        blob = stored_token + blob
        # 2. Hash it
        hash = hashlib.sha256(blob.encode()).hexdigest()
        # 3. Compare the two hashes
        if token == hash:
            equal_hashed_token = True
            print("Equal hashes get_users_data_by_token")
        ########################################################################
        if equal_hashed_token:
            result = database_helper.get_user_data_by_token(stored_token)
            if result == None:
                return jsonify({
                    'success': False,
                    'message': "No data with requested token"
                })
            return jsonify(result)
        else:
            return jsonify({
                'success': False,
                'message': "No equal hashes get_user_data_by_token"
            })
    else:
        return jsonify({
            'success': False,
            'message': "Token has to be provided"
        })
Example #18
0
def get_user_data_by_token():
    if request.method == 'POST':
        token = request.form['token']
        user_data = database_helper.get_user_data_by_token(token)
        if user_data != False:
            return json.dumps({
                'success': True,
                'message': "Userdata retrieved",
                'email': user_data[0],
                'firstname': user_data[1],
                'familyname': user_data[2],
                'gender': user_data[3],
                'city': user_data[4],
                'country': user_data[5]
            })
        return json.dumps({
            'success': False,
            'message': '''Token doesn't exist'''
        })
Example #19
0
def get_user_data_by_token():
    params = request.args
    return json.dumps(database_helper.get_user_data_by_token(params))
Example #20
0
def get_user_data_by_token():
    params = request.args
    return json.dumps(database_helper.get_user_data_by_token(params))
Example #21
0
def get_user_data_by_token(token):
    return jsonify(dh.get_user_data_by_token(token))