Ejemplo n.º 1
0
def links(user):

    try:

        if request.args.get('sort') == 'desc':

            # getting links for the user
            links = User.my_links(user)
            # keys = User.get_keys(user)
            links = dumps(links)
            links = json.loads(links)
        elif request.args.get('sort') == 'asc':
            # getting links for the user
            links = User.my_links_asc(user)
            # keys = User.get_keys(user)
            links = dumps(links)
            links = json.loads(links)
        else:
            # getting links for the user
            links = User.my_links(user)
            # keys = User.get_keys(user)
            links = dumps(links)
            links = json.loads(links)

        return jsonify({"status": True, "linkData": links})

    except:
        return jsonify({"status": False, "error": "UNKNOWN_ERROR"}), 400
Ejemplo n.º 2
0
def signup():

    # instantiationg the form
    form = RegistrationForm()

    # defining the site title
    site_title = "Abbrefy | Power With Every Link"

    # handling form validation
    if form.validate_on_submit():

        new_user = User(form.username.data, form.email.data,
                        form.password.data)

        response = new_user.signup()

        # sending flased message
        if response == True:
            flash("Welcome to Abbrefy", "success")
            return redirect(url_for('users.dashboard'))

        else:
            # sending flased message
            flash("Sign Up Failed. Please Try Again", "danger")

    return render_template('signup.html',
                           datetime=datetime,
                           form=form,
                           site_title=site_title)
Ejemplo n.º 3
0
def un(user):

    links = User.my_links(user)
    keys = User.get_keys(user)

    return render_template('dashboard.html',
                           datetime=datetime,
                           site_title=site_title,
                           links=links,
                           len=len,
                           keys=keys)
Ejemplo n.º 4
0
def dashboard(user):

    site_title = "Abbrefy | Grow As You Abbrefy"
    links = User.my_links(user['public_id'])
    keys = User.get_keys(user['public_id'])

    return render_template('dashboard.html',
                           datetime=datetime,
                           site_title=site_title,
                           links=links,
                           len=len,
                           keys=keys)
Ejemplo n.º 5
0
def signin():

    # instantiationg the form
    form = LoginForm()
    # defining the site title
    site_title = "Abbrefy | Power With Every Link"

    # handling form validation
    if form.validate_on_submit():
        data = {
            "identifier": form.identifier.data,
            "password": form.password.data
        }
        user = User().signin(data)

        if user == False:
            flash('Invalid Signin Details', "danger")

        else:
            username = user['username']
            flash(f'Welcome back {username}', "success")
            return redirect(url_for('users.dashboard'))

    return render_template('signin.html',
                           datetime=datetime,
                           site_title=site_title,
                           form=form)
Ejemplo n.º 6
0
def reset():
    # instantiationg the form
    form = ResetPassword()
    # defining the site title
    site_title = "Abbrefy | You're Almost In"
    # getting the finder query parameter
    finder = request.args.get('finder')
    # checking if the query parameter was passed
    if not finder:
        flash('Your reset link is invalid', 'danger')
        return redirect(url_for('users.forgot'))
    # checking if the query parameter matches any user
    user = find_user(finder)
    if not user:
        flash('Your reset link is invalid', 'danger')
        return redirect(url_for('users.forgot'))
    # handling form validation
    if form.validate_on_submit():
        password = form.password.data
        status = User().update_password(user, password)
        if status:
            return redirect(url_for('users.signin'))
        flash('Something went wrong', 'danger')
    return render_template('reset.html',
                           site_title=site_title,
                           form=form,
                           datetime=datetime)
Ejemplo n.º 7
0
def profile(user):
    try:

        # getting the request data
        data = request.get_json()
        # validating the data was sent
        if not data:
            return jsonify({"status": False, "error": "DATA_ERROR"}), 400
        # validating the username character context
        if not validate_username(data['usernameData']):
            return jsonify({
                "status": False,
                "error": "DATA_VALIDATION_ERROR"
            }), 400
        # validating the username length
        if len(data['usernameData']) > 10 or len(data['usernameData']) < 3:
            return jsonify({
                "status": False,
                "error": "CHARACTER_LIMIT_ERROR"
            }), 400

        # creating the URL object and abbrefying it
        if not "current_user" in session:
            return jsonify({
                "status": False,
                "error": "AUTHORIZATION_ERROR"
            }), 401

        user = session['current_user']['public_id']
        response = User().update_profile(user, data)

        if response == False:
            return jsonify({
                "status": False,
                "error": "PASSWORD_MATCH_ERROR"
            }), 400

        if response == True:
            return jsonify({
                "status": False,
                "error": "SECURE_PASSWORD_ERROR"
            }), 400

        if response['status'] == False:
            return jsonify({"status": False, "error": "UNKNOWN_ERROR"}), 400

        return jsonify({
            "status": True,
            "message": "UPDATE_SUCCESS",
            "data": response
        }), 200

    # handling errors
    except KeyError:
        return jsonify({"status": False, "error": "DATA_ERROR"}), 400

    except:
        return jsonify({"status": False, "error": "UNKNOWN_ERROR"}), 400
Ejemplo n.º 8
0
def bulk_abbrefy():

    # getting the request data
    data = request.form
    csvFile = request.files

    # validating a file was uploaded
    if not csvFile or not 'csv' in csvFile:
        return jsonify({"status": False, "error": "FILE_ERROR"}), 400

    # validating that the file was sent with the right identifier
    if csvFile['csv'].filename.split('.')[-1] != 'csv':
        return jsonify({"status": False, "error": "FILE_TYPE_ERROR"}), 400

    if not "current_user" in session:
        return jsonify({"status": False, "error": "AUTHORIZATION_ERROR"}), 401

    author = session['current_user']['public_id']

    # collecting the user's apiKey
    key = User.get_key(author)

    # generating a new file name for the uploaded file
    to = str(floor(time() * 1000)) + uuid4().hex[0:7] + '.csv'

    # saving the csv file to firebase and disk storage
    if csvFile['csv'].filename == '':
        return jsonify({"status": False, "error": "FILE_ERROR"}), 400

    diskLoc = os.path.join(current_app.root_path, 'static/csv',
                           str(floor(time())) + csvFile['csv'].filename)

    csvFile['csv'].save(diskLoc)

    origin, fileName = upload_file(diskLoc, to, download=True)

    if data and 'type' in data and data['type'] == 'unordered':

        # running an unordered bulk abbrefy based on user request.
        status = q.enqueue(unordered_bulk_abbrefy, fileName, key)
        # unordered_bulk_abbrefy(fileName, key)

        return jsonify({'status': True, 'message': 'Bulk Abbrefy Initiated'})

    # running an ordered bulk abbrefy based on user request.
    status = q.enqueue(ordered_bulk_abbrefy, fileName, author, origin)

    # uploading the newly created csv to firebase
    # slug, _ = upload_file(path, name)

    # # saving the information to the database
    # new_link = Link(author=author)
    # response = new_link.bulk_abbrefy(location=slug, origin=origin)
    return jsonify({'status': True, 'message': 'Bulk Abbrefy Initiated'})
Ejemplo n.º 9
0
    def decorated(*args, **kwargs):
        if not "apiKey" in request.headers:
            return f(None, *args, **kwargs)

        apiKey = request.headers.get('apiKey')

        user = User.get_key_owner(apiKey)

        if not user:
            return jsonify({"status": False, "error": "Invalid API key provided."})

        return f(user, *args, **kwargs)
Ejemplo n.º 10
0
def forgot():
    # instantiationg the form
    form = ForgotPassword()
    # defining the site title
    site_title = "Abbrefy | Let's Get You Back In"

    # handling form validation
    if form.validate_on_submit():

        email = form.email.data

        User().reset_password(email)
        flash('Please Check Your Mail to Finish Your Password Reset',
              'success')
        return redirect(url_for('users.signin'))

    return render_template('forgot.html',
                           site_title=site_title,
                           form=form,
                           datetime=datetime)
Ejemplo n.º 11
0
def create(user):
    try:

        # getting the request data
        data = request.get_json()
        # validating the data was sent
        if not data:
            return jsonify({"status": False, "error": "DATA_ERROR"}), 400

        # creating the URL object and abbrefying it
        if not "current_user" in session:
            return jsonify({
                "status": False,
                "error": "AUTHORIZATION_ERROR"
            }), 401

        user = user['public_id']
        response = User().generate_api_key(user)

        if response == False:
            return jsonify({
                "status": False,
                "error": "KEY_LIMIT_EXCEEDED"
            }), 400

        if response['status'] == False:
            return jsonify({"status": False, "error": "UNKNOWN_ERROR"}), 400

        return jsonify({
            "status": True,
            "message": "CREATE_SUCCESS",
            "data": response
        }), 200

    # handling errors
    except KeyError:
        return jsonify({"status": False, "error": "DATA_ERROR"}), 400

    except:
        return jsonify({"status": False, "error": "UNKNOWN_ERROR"}), 400
Ejemplo n.º 12
0
def signout(user):
    response = User.signout()
    if response:
        return redirect(url_for('main.home'))
Ejemplo n.º 13
0
 def validate_email(self, email):
     if not User.check_email(email.data):
         raise ValidationError('No Account Exists for that Email')
Ejemplo n.º 14
0
 def validate_email(self, email):
     if User.check_email(email.data):
         raise ValidationError('That Email Has Been Taken')
Ejemplo n.º 15
0
 def validate_username(self, username):
     if User.check_username(username.data):
         raise ValidationError('That Username Has Been Taken')