Beispiel #1
0
def reset_password():
    post_data = request.get_json()
    response_object = {'status': 'fail', 'message': 'Invalid Information'}
    if not post_data:
        return jsonify(response_object), 400
    email = post_data.get('email')

    try:
        user = User.query.filter_by(email=email).first()
        if not user:
            response_object['status'] = 'Fail'
            response_object['message'] = 'User not found'
            return jsonify(response_object), 400
        else:
            token = encode_token(user.email, 'password-reset-salt')
            password_reset_url = generate_url('auth.update_password', token)
            body = render_template('email_password_reset.txt',
                                   password_reset_url=password_reset_url,
                                   email=user.email,
                                   firstname=user.firstname,
                                   lastname=user.lastname)
            subject = 'ITPACS. Reset your password'
            celery.send_task('send_async_email',
                             args=[user.email, body, subject])

            response_object['status'] = 'success'
            response_object[
                'message'] = 'Password reset instructions sent to your email. Check your email.'
            return jsonify(response_object), 201
    except (exc.IntegrityError, ValueError) as e:
        return jsonify(response_object), 400
Beispiel #2
0
def deleteProfileImageS3(prevImageName):

    destinationFileName = prevImageName
    data = {
        "S3_BUCKET": current_app.config["S3_BUCKET"],
        'S3_KEY': current_app.config['S3_KEY'],
        'S3_SECRET': current_app.config['S3_SECRET'],
        'S3_UPLOAD_DIRECTORY': current_app.config['S3_UPLOAD_DIRECTORY'],
        "destinationFileName": destinationFileName
    }

    celery.send_task('s3_delete_image', args=[data])
Beispiel #3
0
def uploadImageToS3(resp):

    userId = resp
    post_data = request.get_json()
    imageStr = post_data.get('imageData')
    imgType = post_data.get('imageType')
    imgBorder = post_data.get('imageBorder')
    prevImage = post_data.get('previousImg')
    prevImageName = post_data.get('fileName')

    # create new file name
    destination_filename = uuid4().hex + '.' + imgType

    data = {
        'acl': 'public-read',
        'S3_LOCATION': current_app.config['S3_LOCATION'],
        "S3_BUCKET": current_app.config["S3_BUCKET"],
        'S3_KEY': current_app.config['S3_KEY'],
        'S3_SECRET': current_app.config['S3_SECRET'],
        'S3_UPLOAD_DIRECTORY': current_app.config['S3_UPLOAD_DIRECTORY'],
        'UPLOAD_FOLDER': current_app.config['UPLOAD_FOLDER'],
        'Image_String': imageStr,
        "destinationFileName": destination_filename
    }

    celery.send_task('s3_upload_image', args=[data])
    object_url = "https://s3-{0}.amazonaws.com/{1}/{2}/{3}".format(
        data["S3_LOCATION"], data["S3_BUCKET"], data["S3_UPLOAD_DIRECTORY"],
        data["destinationFileName"])

    # Insert user image details into postgres and mongo database
    imgData = {
        'userId': userId,
        'imageUrl': object_url,
        'borderRadius': imgBorder,
        'prevImageName': prevImageName
    }
    userImageDetails(imgData)
    # End Insert user image details into postgres and mongo database

    time.sleep(2)

    return jsonify({'status': 'success', 'url': object_url})
Beispiel #4
0
def add(param1, param2):

    # task = celery.send_task('users.add', args=[10, 20], kwargs={})
    # task = dividing(10, 5)

    task = celery.send_task('add', args=[param1, param2], kwargs={})

    # task = add.delay(queue='default', args=[param1, param2])
    # task = add.delay(param1, param2)

    return "<a href='{url}'>check status of {id} </a>".format(
        id=task.id,
        url=url_for('users.check_task', id=task.id, _external=True))
Beispiel #5
0
def register_user():

    post_data = request.get_json()
    response_object = {'status': 'fail', 'message': 'Invalid Payload'}
    if not post_data:
        return jsonify(response_object), 400

    firstname = post_data.get('firstname')
    lastname = post_data.get('lastname')
    email = post_data.get('email')
    password = post_data.get('password')

    try:
        user = User.query.filter_by(email=email).first()
        if not user:
            new_user = User(firstname=firstname,
                            lastname=lastname,
                            email=email,
                            password=password)
            db.session.add(new_user)
            db.session.commit()

            #Saving user data to mongoDb
            new_userM = User_M(user_id=new_user.id,
                               firstname=new_user.firstname,
                               lastname=new_user.lastname,
                               email=new_user.email,
                               password=new_user.password)
            new_userM.save()

            #Email confirmation steps
            token = encode_token(new_user.email, 'email-confirm-salt')
            confirm_url = generate_url('auth.confirm_email', token)
            body = render_template('email.txt',
                                   confirm_url=confirm_url,
                                   email=new_user.email,
                                   firstname=new_user.firstname,
                                   lastname=new_user.lastname)
            subject = 'ITPACS. Confirm your email'

            #Using celery.....
            # send_async_email.delay(new_user.email, body, subject)
            # celery_app.send_task('send_async_email', args=[new_user.email, body, subject])

            celery.send_task('send_async_email',
                             args=[new_user.email, body, subject])
            # send_mail(new_user.email, body, subject)
            new_user.email_sent = True
            db.session.commit()

            # redis_url = current_app.config.get('REDIS_URL')
            # with Connection(redis.from_url(redis_url)):
            # 	q = Queue()
            # 	q.enqueue(send_email, new_user.email, body, subject)

            #Generate Auth Token
            auth_token = new_user.encode_auth_token(new_user.id)

            response_object['status'] = 'success'
            response_object['message'] = 'Successfully registered.'
            response_object['auth_token'] = auth_token.decode()
            return jsonify(response_object), 201
        else:
            response_object['message'] = 'Sorry. That user already exists'

            return jsonify(response_object), 400
    except (exc.IntegrityError, ValueError) as e:
        db.session.rollback()

        return jsonify(response_object), 400