예제 #1
0
def change_issue_status():
    if 'authorized' in session and session['authorized'] is True:
        id = request.form.get('uid')
        status = request.form.get('status_row')
        DataBaseManager.update_issue_status(id, status)

    return ('', 204)
예제 #2
0
def change_pwd(token):
    dbm = DataBaseManager()
    user_email = dbm.verify_token(token)
    field = validate.regex()
    password = field.validate(field.password_pattern,
                              request.form.get("password"))
    password_conf = password == request.form.get("password_conf")

    err_msg = field.compose_error_message(password, password_conf)

    if user_email is None:
        return render_template("NewPwd.html", session=True)
    else:
        if err_msg is not None:
            return render_template("NewPwd.html",
                                   session=False,
                                   token=token,
                                   error=err_msg)

    pwd_manager = Hash()
    salt, hashpwd = pwd_manager.get_salt_hash(password)
    stored_pwd = "$" + salt + "$" + hashpwd.decode("utf-8")

    dbm.update_new_password(stored_pwd, user_email)

    return redirect(url_for('render_gallery'))
예제 #3
0
def test_upload():
    userID = request.form.get("userID")
    password = request.form.get("password")
    file = extract_photo_from_request()

    pwd_manager = Hash()
    if not pwd_manager.check_password(userID, password):
        return Response(status=401)

    file_manager = FileManager()
    if not file or not file_manager.save_file(file):
        return Response(status=400)

    saved_files = ImageTransform.make_transformations(
        file_manager.last_saved_full_path)
    saved_files["original"] = FileManager.extract_filename(
        file_manager.last_saved_full_path)

    dbm = DataBaseManager()
    db_success = dbm.add_photos(userID, "Auto Uploaded", "#test_image",
                                saved_files)

    if db_success:
        return Response(status=200)
    else:
        return Response(status=500)
예제 #4
0
def render_gallery():
    if 'authorized' in session and session['authorized'] is True:
        dbm = DataBaseManager()
        f_mgr = FileManager()
        photos = dbm.get_user_thumbs(session['user'], f_mgr)
        img_urls = f_mgr.get_s3_url(photos)

        return render_template('gallery.html', username=session['user'], photos=img_urls)

    return redirect(url_for('index'))
예제 #5
0
    def check_password(username, password):
        dbm = DataBaseManager()
        db_salt, db_pw_hash = dbm.get_user_pwd_hash(username)

        pw_hash = Hash.get_salt_hash(password, db_salt)[1]

        if db_pw_hash == pw_hash.decode("utf-8"):
            return True

        return False
예제 #6
0
def photo_upload():
    if 'authorized' in session and session['authorized'] is True:
        input_title = request.form.get("title")
        input_hashtag = request.form.get("hashtag")

        field = validate.regex()
        owner = session["user"]
        title = field.validate(field.photo_title_pattern, input_title)
        hashtag = field.validate(field.photo_hashtag_pattern, input_hashtag)

        if not title:
            return render_template(
                "uploadphoto.html",
                up_error=
                "Invalid title. Hover cursor over field for requirements.",
                title=input_title,
                hashtags=input_hashtag)

        if not hashtag:
            return render_template(
                "uploadphoto.html",
                up_error=
                "Invalid hashtags. Hover cursor over fields for requirements.",
                title=input_title,
                hashtags=input_hashtag)

        file_manager = FileManager()
        file = extract_photo_from_request()

        if not file or not file_manager.save_file(file):
            return render_template("uploadphoto.html",
                                   up_error="Please select a valid file.",
                                   title=input_title,
                                   hashtags=input_hashtag)

        saved_files = ImageTransform.make_transformations(
            file_manager.last_saved_full_path)
        saved_files["original"] = FileManager.extract_filename(
            file_manager.last_saved_full_path)

        file_manager.save_to_s3(saved_files)
        file_manager.delete_file_list(saved_files)

        dbm = DataBaseManager()
        db_success = dbm.add_photos(owner, title, hashtag, saved_files)

        if not db_success:
            return render_template(
                "uploadphoto.html",
                up_error="There was an error. Please try again.",
                title=input_title,
                hashtags=input_hashtag)

        return redirect(url_for('render_gallery'))
    return redirect(url_for('index'))
예제 #7
0
def create_session_for(username, password):
    pwd_manager = Hash()
    if pwd_manager.check_password(username, password):
        session['user'] = username
        session['authorized'] = True

        dbm = DataBaseManager()
        session['type'] = dbm.get_user_type(username)

        return True
    return False
예제 #8
0
def delete_all():
    if 'authorized' in session and session[
            'authorized'] is True and 'type' in session and session[
                'type'] == 'admin':
        f_mgr = FileManager()
        f_mgr.delete_all_from_s3_bucket()
        dbm = DataBaseManager()
        dbm.reset_database()

        return redirect(url_for('admin_main_landing'))

    return redirect(url_for('index'))
예제 #9
0
def render_light_box(id):
    if 'authorized' in session and session['authorized'] is True:
        dbm = DataBaseManager()
        f_mgr = FileManager()
        photos = dbm.get_user_full_sizes_url(session['user'], id, f_mgr)

        if photos:
            return render_template('lightbox.html',
                                   username=session['user'],
                                   photos=photos)

    return redirect(url_for('index'))
예제 #10
0
def add_worker():
    if 'authorized' in session and session[
            'authorized'] is True and 'type' in session and session[
                'type'] == 'admin':
        ScalingTool.spawn_one_instance()
        dbm = DataBaseManager()
        uth, dth, ex_ratio, s_ratio, mode = dbm.get_scaling_settings()
        mode = 'manual'
        dbm.scaling(str(int(uth)), str(int(dth)), str(int(ex_ratio)),
                    str(int(s_ratio)), mode)
        return redirect(url_for('admin_main_landing'))

    return redirect(url_for('index'))
예제 #11
0
def reset_token(token):
    if 'authorized' in session and session['authorized'] is True:
        return redirect(url_for("welcome"))
    user_email = DataBaseManager.verify_token(token)
    if user_email is None:
        return render_template("NewPwd.html", session=True)
    return render_template("NewPwd.html", session=False, token=token)
예제 #12
0
def admin_main_landing():
    if 'authorized' in session and session[
            'authorized'] is True and 'type' in session and session[
                'type'] == 'admin':
        cpu_stats, instances, _x = ScalingTool.get_instances_load()
        instance_list = [dict['InstanceId'] for dict in instances]
        length = len(cpu_stats)
        dbm = DataBaseManager()
        uth, dth, ex_ratio, s_ratio, mode = dbm.get_scaling_settings()
        return render_template('adminhome.html',
                               length=length,
                               instance_list=instance_list,
                               cpu_stats=cpu_stats,
                               ex_ratio=ex_ratio,
                               s_ratio=s_ratio,
                               uth=uth,
                               dth=dth,
                               mode=mode)

    return redirect(url_for('index'))
예제 #13
0
def recovery_submit():
    recipient = request.form.get("email")
    dbm = DataBaseManager()
    email_success = dbm.email_already_exists(recipient)

    if email_success:

        token = DataBaseManager.get_token(recipient, 60)
        Email.send(
            "*****@*****.**", recipient,
            "Password Recovery", '''Hi,\n\n
                       visit the following link to reset your password -
                       {}'''.format(
                url_for('reset_token', token=token,
                        _external=True)), "smtp.gmail.com", 587,
            "ece1779.project.fall.2018", "wmbuvijletllgypz")
        #"aSd123qWe456zxc"

        return render_template("index.html")
    else:
        email_not_reg = True
        return render_template("forgotpwd.html", error_value=email_not_reg)
예제 #14
0
def render_main_issue_list():
    if 'authorized' in session and session['authorized'] is True:
        documents = list()
        status_input = parse_string(request.form.get('status'))
        project_input = parse_string(request.form.get('project'))
        discipline_input = parse_string(request.form.get('discipline'))
        sentiment_input = parse_string(request.form.get('sentiment'))
        document_input = parse_string(request.form.get('document'))
        last_key = parse_string(request.form.get('db_key'))
        first_page = parse_string(request.form.get('first_page'))
        filter = parse_string(request.form.get('filter'))
        next_b = parse_string(request.form.get('next_b'))

        if not filter and not first_page and not next_b:
            first_page = 'first_page'

        if project_input:
            documents = DataBaseManager.get_documents_for(project_input)

        if last_key:
            last_key_dict = eval(last_key)
        else:
            last_key_dict = None

        issues, last_key = Pagination.page_data(last_key_dict, project_input, document_input, discipline_input,
                                                          sentiment_input, status_input)
        projects = DataBaseManager.get_projects()
        disciplines = DataBaseManager.get_disciplines()
        lists = ['Open', 'Closed']
        lists2 = ['Closed', 'Open']

        return render_template("issue.html", issues=issues, projects=projects, documents=documents,
                               disciplines=disciplines, lists=lists, lists2=lists2, selected_status=status_input,
                               selected_project=project_input, selected_document=document_input,
                               selected_discipline=discipline_input, selected_sentiment=sentiment_input,
                               last_key=last_key, first_page=first_page)

    return redirect(url_for("index"))
예제 #15
0
def new_issue_landing():
    if 'authorized' in session and session['authorized'] is True:
        projects = DataBaseManager.get_projects()
        documents = list()
        disciplines = list()

        db_success = True

        selected_project = request.form.get('project')
        selected_document = request.form.get('document')
        selected_discipline = request.form.get('discipline')
        current_issue = request.form.get('issue')
        issues_so_far = request.form.get('issues_so_far')

        if selected_project:
            DataBaseManager.add_project(selected_project)
            documents = DataBaseManager.get_documents_for(selected_project)

        if selected_project and selected_document:
            DataBaseManager.add_document(selected_project, selected_document)
            disciplines = DataBaseManager.get_disciplines()

        if issues_so_far == 'None' or issues_so_far == '[]':
            issues_so_far = ''

        if selected_project and selected_document and selected_discipline and current_issue:
            id_builder = hashlib.sha1()
            id_builder.update(str(time.time()).encode('utf-8'))
            id_builder.hexdigest()
            identifier = id_builder.hexdigest()[:5]

            sentiment = TextAi.get_sentiment(current_issue).get('Sentiment')
            voice = Voice.synthesize(current_issue)

            db_success = DataBaseManager.add_issue(selected_project, selected_document, selected_discipline,
                                                   current_issue, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                                                   identifier, sentiment, voice, session['user'])

            if db_success:
                issues_so_far = selected_project + " :: " + selected_document + " :: " + selected_discipline + \
                                "\n" + current_issue.rstrip() + "\n\n" + issues_so_far

        return render_template("newissue.html", projects=projects, selected_project=selected_project,
                               documents=documents, selected_document=selected_document, disciplines=disciplines,
                               selected_discipline=selected_discipline, issues_so_far=issues_so_far,
                               db_success=db_success)

    return redirect(url_for("index"))
예제 #16
0
def face_unlock():
    username = request.form.get('var2')
    picture = request.form.get('var1')

    if username is not "":
        user = DataBaseManager.check_existing_user_name(username)
        if user:
            FaceUnlock.upload_s3(picture, username)
            key1 = username + '_master.jpg'
            key2 = username + '.jpg'
            response = FaceUnlock.face_match(key1, key2)
            if create_face_session_for(response, username):
                return redirect(url_for('render_main_issue_list'))

    return render_template("index.html", error=True, username=username)
예제 #17
0
import time
from app.tools.scalingTools import ScalingTool
from app.tools.dbTools import DataBaseManager


print('Scaling application has started...')

while True:
    time.sleep(10)
    # Get database scaling settings
    dbm = DataBaseManager(False)
    instance_start_load, instance_termination_load, up_scale_factor, down_scale_factor, mode = dbm.get_scaling_settings()

    if mode != 'auto':
        continue

    # Get number of instances in service on load balancer
    total_running_instances = ScalingTool.get_number_of_in_service_instances_in_load_balancer()

    # Read load balancer average instance loads
    avg_load = ScalingTool.get_load_balancer_instances_avg_load()
    print('Avg. CPU load = {}'.format(avg_load))

    # Should instances be terminated?
    if avg_load < instance_termination_load:
        n_instances_to_terminate = total_running_instances - total_running_instances // down_scale_factor
        expected_n_instances = total_running_instances - n_instances_to_terminate

        if expected_n_instances <= 1:
            print('Expected number of instances limited to 1')
            n_instances_to_terminate = total_running_instances - 1
예제 #18
0
def create_user():
    if 'authorized' in session and session['authorized'] is True:
        return redirect(url_for("render_gallery"))

    input_username = request.form.get("username")
    input_first_name = request.form.get("first_name")
    input_last_name = request.form.get("last_name")
    input_email = request.form.get("email")
    input_password = request.form.get("password")
    input_password_conf = request.form.get("password_conf")

    field = validate.regex()
    username = field.validate(field.user_name_pattern, input_username)
    first_name = field.validate(field.first_name_pattern, input_first_name)
    last_name = field.validate(field.last_name_pattern, input_last_name)
    email = field.validate(field.email_pattern, input_email)
    password = field.validate(field.password_pattern, input_password)
    password_conf = password == input_password_conf

    err_msg = compose_error_message(username, first_name, last_name, email,
                                    password, password_conf)

    if err_msg is not None:
        return render_template("newuser.html",
                               error=err_msg,
                               username=input_username,
                               first_name=input_first_name,
                               last_name=input_last_name,
                               email=input_email,
                               password=input_password,
                               password_conf=input_password_conf)

    pwd_manager = Hash()
    salt, hashpwd = pwd_manager.get_salt_hash(password)
    stored_pwd = "$" + salt + "$" + hashpwd.decode("utf-8")

    dbm = DataBaseManager()
    email_already_registered = dbm.email_already_exists(email)

    if not email_already_registered:
        db_success = dbm.add_user(username, first_name, last_name, email,
                                  stored_pwd)

        if db_success:
            session['user'] = username
            session['authorized'] = True

            return redirect(url_for('render_gallery'))
        else:
            # Getting here means that either there was a database  error or the username is already taken.
            # Since the user will have to retry anyways, we might as well say there was an error with the
            # chosen username
            err_msg = ["Username is unavailable."]
            return render_template("newuser.html",
                                   error=err_msg,
                                   username=input_username,
                                   first_name=input_first_name,
                                   last_name=input_last_name,
                                   email=input_email,
                                   password=input_password,
                                   password_conf=input_password_conf)
    else:
        err_msg = ["An account already exists with this Email"]
        return render_template("newuser.html",
                               error=err_msg,
                               username=username,
                               first_name=first_name,
                               last_name=last_name,
                               email=email,
                               password=password,
                               password_conf=password_conf)
예제 #19
0
def size_scaling():
    if 'authorized' in session and session[
            'authorized'] is True and 'type' in session and session[
                'type'] == 'admin':
        scale_up_load = request.form.get('uth')
        scale_down_load = request.form.get('dth')
        expand_ratio = request.form.get('ex_ratio')
        shrink_ratio = request.form.get('s_ratio')
        scale_mode = 'auto'

        err_msg = []
        dbm = DataBaseManager()
        cpu_metrics = ScalingTool.get_instances_load()

        if scale_up_load == "" or scale_down_load == "" or expand_ratio == "" or shrink_ratio == "":
            msg = "Fields cannot be empty"
            err_msg.append(msg)
            return render_template('adminhome.html',
                                   cpu_metrics=cpu_metrics,
                                   err_msg=err_msg,
                                   uth=scale_up_load,
                                   dth=scale_down_load,
                                   ex_ratio=expand_ratio,
                                   s_ratio=shrink_ratio)

        else:

            if float(scale_up_load) < 0:
                msg = 'Scale Up Load Should be Greater than 0'
                err_msg.append(msg)

            if float(scale_down_load) < 0:
                msg = 'Scale Down Load Should be Greater than 0'
                err_msg.append(msg)

            if float(scale_up_load) < float(scale_down_load):
                msg = 'Scale Up Load should be Greater than Scale Down Load'
                err_msg.append(msg)

            if float(expand_ratio) <= 1:
                msg = 'Expand Ratio should be Greater than 1'
                err_msg.append(msg)

            if float(shrink_ratio) <= 1:
                msg = 'Shrink Ratio should be Greater than 1'
                err_msg.append(msg)

            if not err_msg:
                dbm.scaling(scale_up_load, scale_down_load, expand_ratio,
                            shrink_ratio, scale_mode)

                return redirect(url_for('admin_main_landing'))

        return render_template('adminhome.html',
                               cpu_metrics=cpu_metrics,
                               error=err_msg,
                               uth=scale_up_load,
                               dth=scale_down_load,
                               ex_ratio=expand_ratio,
                               s_ratio=shrink_ratio)

    return redirect(url_for('index'))