Ejemplo n.º 1
0
def login():
    login_user = usersCollection.find_one({'email': request.json['email']})
    if login_user:
        if bcrypt.checkpw(request.json['password'].encode('utf-8'),
                          login_user['password']):
            token = secrets.token_hex(20)
            tokensCollection.delete_one({'email': request.json['email']})
            tokensCollection.insert({
                'token':
                token,
                'email':
                request.json['email'],
                'expiry':
                (datetime.now() +
                 timedelta(hours=1)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
            })
            response = {
                'email': login_user['email'],
                'firstName': login_user['firstName'],
                'token': token,
                'permission': login_user['permission']
            }
            return mongo.prepareResponse(response)
    raise exceptionHandler.InvalidUsage('Invalid email/password combination',
                                        status_code=420)
Ejemplo n.º 2
0
def register():
    if request.method == 'POST':
        existing_user = usersCollection.find_one(
            {'email': request.json['email']})
        if existing_user is None:
            hashpass = bcrypt.hashpw(request.json['password'].encode('utf-8'),
                                     bcrypt.gensalt())
            usersCollection.insert({
                'firstName': request.json['firstName'],
                'lastNname': request.json['lastName'],
                'email': request.json['email'],
                'empId': request.json['empId'],
                'password': hashpass,
                'industry': request.json['industry'],
                'serviceLine': request.json['serviceLine'],
                'serviceArea': request.json['serviceArea'],
                'designation': request.json['designation'],
                'location': request.json['location'],
                'mobileNo': request.json['mobileNo'],
                'permission': 'guest'
            })
            newUser = usersCollection.find({'email': request.json['email']},
                                           {'password': 0})
            return mongo.prepareResponse(newUser)
        else:
            raise exceptionHandler.InvalidUsage('User already exists',
                                                status_code=420)
Ejemplo n.º 3
0
def users():
    if request.method == 'GET':
        existing_users = usersCollection.find({'permission' : 'guest'}, {'password': 0})
        if existing_users:
            return mongo.prepareResponse(existing_users)
        else:
            raise exceptionHandler.InvalidUsage('No Users', status_code=420)
Ejemplo n.º 4
0
def upload_file():
    if request.method == 'POST':
        #  file = request.files['file']
        #     if file and allowed_file(file.filename):
        #         filename = secure_filename(file.filename)
        #         file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        #         ## snippet to read code below
        #         file.stream.seek(0) # seek to the beginning of file
        #         myfile = file.file # will point to tempfile itself
        #         dataframe = pd.read_csv(myfile)
        #         ## end snippet
        user = auth.getLoggedInUser(request.headers['Authorization'])
        # check if the post request has the file part
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No file part')
            return exceptionHandler.InvalidUsage('Invalid Recording',
                                                 status_code=420)
        if file and allowed_file(
                file.filename) and not mongo.existInDatabase(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            response = mongo.pushToDatabase(filename, user['email'],
                                            user['permission'])
            return mongo.prepareResponse(response)
    return '''
Ejemplo n.º 5
0
def upload_file():
    if request.method == 'POST':
        #  file = request.files['file']
        #     if file and allowed_file(file.filename):
        #         filename = secure_filename(file.filename)
        #         file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        #         ## snippet to read code below
        #         file.stream.seek(0) # seek to the beginning of file
        #         myfile = file.file # will point to tempfile itself
        #         dataframe = pd.read_csv(myfile)
        #         ## end snippet
        user = auth.getLoggedInUser(request.headers['Authorization'])
        # check if the post request has the file part
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No file part')
            return exceptionHandler.InvalidUsage('Invalid Recording', status_code=420)
        if file and allowed_file(file.filename) and not mongo.existInDatabase(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            response = mongo.pushToDatabase(filename, user['email'], user['permission'])
            return mongo.prepareResponse(response)
    return '''
Ejemplo n.º 6
0
def users():
    if request.method == 'GET':
        existing_users = usersCollection.find({'permission': 'guest'},
                                              {'password': 0})
        if existing_users:
            return mongo.prepareResponse(existing_users)
        else:
            raise exceptionHandler.InvalidUsage('No Users', status_code=420)
Ejemplo n.º 7
0
def login():
    login_user = usersCollection.find_one({'email' : request.json['email']})
    if login_user:
        if bcrypt.checkpw(request.json['password'].encode('utf-8'), login_user['password']):
            token = secrets.token_hex(20)
            tokensCollection.delete_one({ 'email' : request.json['email']})
            tokensCollection.insert({
                'token': token,
                'email': request.json['email'],
                'expiry': (datetime.now() + timedelta(hours=1)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
            })
            response = { 'email': login_user['email'], 'firstName': login_user['firstName'], 'token': token, 'permission': login_user['permission'] }
            return mongo.prepareResponse(response)
    raise exceptionHandler.InvalidUsage('Invalid email/password combination', status_code=420)
Ejemplo n.º 8
0
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(
                file.filename) and not mongo.existInDatabase(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            response = mongo.pushToDatabase(filename)
            return mongo.prepareResponse(response)
    return '''
Ejemplo n.º 9
0
def register():
    if request.method == 'POST':
        existing_user = usersCollection.find_one({'email' : request.json['email']})
        if existing_user is None:
            hashpass = bcrypt.hashpw(request.json['password'].encode('utf-8'), bcrypt.gensalt())
            usersCollection.insert({
                'firstName' : request.json['firstName'], 
                'lastNname' : request.json['lastName'], 
                'email' : request.json['email'], 
                'empId' : request.json['empId'], 
                'password' : hashpass,
                'industry' : request.json['industry'], 
                'serviceLine' : request.json['serviceLine'], 
                'serviceArea' : request.json['serviceArea'], 
                'designation' : request.json['designation'], 
                'location' : request.json['location'], 
                'mobileNo' : request.json['mobileNo'],
                'permission': 'guest'
                })
            newUser = usersCollection.find({'email' : request.json['email']}, {'password': 0})
            return mongo.prepareResponse(newUser)
        else:
            raise exceptionHandler.InvalidUsage('User already exists', status_code=420)