Пример #1
0
def debt_create(user_id):
    """
    GET - Renders a debt form.
    POST - Validates the debt form and check if the values are right. If they pass the informations is stored in
    the database and the debt is registrated. The tenant is redirected to the user page.
    If they fail the debt form is rendered with error messages.

    :param user_id:
    :type user_id: integer
    :return: Redirect to edit user page
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            dcl = debt_client.DebtSqlClient()
            user = cl.get_users(user_id)[0]
            form = NewDebt()

            if form.validate_on_submit():
                debt = sql_debt.SQLDebt(form.amount.data, user.id, form.product.data, None, None)
                dcl.add_dept(debt.dict())
                flash('Debt added for %s' % (user.firstname + " " + user.lastname))
                return redirect("/user_page/" + user_id)

            return render_template('debt_create.html',
                                   title='Debt Create',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating debt, please try again.')
        return redirect('/')
Пример #2
0
def all_users(filter=None):
    """
    Lists all members based on the filter.

    :param filter:
    :type filter: string
    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret, users = [], []

            cl = user_client.UsersSqlClient()
            users = cl.get_users(0)

            # List users depending on the membership
            if filter != 'all':
                users = [x for x in users if x.status == filter.title()]

            users = sorted(users, key=lambda user: user.firstname)
            for hit in users:
                js = hit.dict()
                ret.append(js)
            return render_template('all_users.html',
                                   title='All Users',
                                   hits=ret,
                                   filter=filter,
                                   count=len(users))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing all users, please try again.')
        return redirect('/')
Пример #3
0
def user_page(user_index=None):
    """
    Renders a template with user information on a specified user.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            debts, tagevents = [], []
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user Found"
            else:
                dbl = debt_client.DebtSqlClient()
                ret_depts = dbl.get_debt(user.id)
                if ret_depts is not []:
                    for debt in ret_depts:
                        js = debt.dict()
                        debts.append(js)
                tc = tag_client.TageventsSqlClient()
                tagevents = tc.get_detailed_tagevents(user_index, 20)
                return render_template('user_page.html',
                                       title='User Page',
                                       data=user.dict(),
                                       tags=tagevents,
                                       debts=debts)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing a user page, please try again.')
        return redirect('/')
Пример #4
0
def debt_delete(id):
    debts = Debt.query.filter_by(id=id).first()
    users = User.query.filter_by(index=debts.uid).first()
    db.session.delete(debts)
    db.session.commit()
    flash('Deleted debt: %s from member %s' % (debts.amount, users.name))
    return redirect("/user_page/" + str(users.index))
Пример #5
0
def add_new_user():
    form = NewUser()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_usr = User(form.name.data, form.email.data, form.phone.data,
                       form.address.data, form.address2.data, form.city.data,
                       form.zip_code.data, form.tag_id.data,
                       form.fortnox_id.data, form.expiry_date.data,
                       form.birth_date.data, form.gender.data)
        db.session.add(tmp_usr)
        db.session.commit()
        flash('Created new user: %s with id: %s' %
              (form.name.data, tmp_usr.index))
        tagevent = get_last_tag_event()
        fortnox_data = Fortnox()
        fortnox_data.insert_customer(tmp_usr)
        msg = None
        if tagevent is None:
            msg = None
        else:
            msg = (tmp_usr.index, tagevent.tag_id)
        form = NewUser()
        return render_template('new_user.html',
                               title='New User',
                               form=form,
                               message=msg)
    return render_template('new_user.html', title='New User', form=form)
Пример #6
0
def add_new_user():
    form = NewUser()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_usr = User(form.name.data, form.email.data, form.phone.data,
                       form.address.data, form.address2.data, form.city.data,
                       form.zip_code.data, form.tag_id.data, form.fortnox_id.data,
                       form.expiry_date.data, form.birth_date.data,
                       form.gender.data)
        db.session.add(tmp_usr)
        db.session.commit()
        flash('Created new user: %s with id: %s' % (form.name.data,
                                                    tmp_usr.index))
        tagevent = get_last_tag_event()
        fortnox_data = Fortnox()
        fortnox_data.insert_customer(tmp_usr)
        msg = None
        if tagevent is None:
            msg = None
        else:
            msg = (tmp_usr.index, tagevent.tag_id)
        form = NewUser()
        return render_template('new_user.html',
                               title='New User',
                               form=form,
                               message=msg)
    return render_template('new_user.html',
                           title='New User',
                           form=form)
Пример #7
0
def tagin_user():
    form = NewTag(csrf_enabled=False)
    now = datetime.now()
    currenthour = now.hour
    nowtostring = str(now)
    timestampquery = nowtostring[:10]
    print(str(form.validate_on_submit()))
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_tag = Tagevent.query.filter(
            Tagevent.timestamp.contains(timestampquery)).filter(
                Tagevent.clockstamp.contains(currenthour)).first()
        user = User.query.filter(User.tag_id == form.tag_id.data).first()
        detailedtag = DetailedTagevent(form.tag_id.data)
        db.session.add(detailedtag)
        if user is not None:
            user.tagcounter += 1
            user.last_tag_timestamp = now
            if tmp_tag is None or tmp_tag == None:
                tmp_tag = Tagevent()
                tmp_tag.amount = 1
                db.session.add(tmp_tag)
            else:
                tmp_tag.amount += 1
        db.session.commit()
        flash('New tag created')
        return render_template('tagin_user.html', title='New tag', form=form)
    return render_template('tagin_user.html', title='New tag', form=form)
Пример #8
0
def user_page(user_index=None):
    """
    Renders a template with user information on a specified user.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            debts, tagevents = [], []
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user Found"
            else:
                dbl = debt_client.DebtSqlClient()
                ret_depts = dbl.get_debt(user.id)
                if ret_depts is not []:
                    for debt in ret_depts:
                        js = debt.dict()
                        debts.append(js)
                tc = tag_client.TageventsSqlClient()
                tagevents = tc.get_detailed_tagevents(user_index, 20)
                return render_template('user_page.html',
                                       title='User Page',
                                       data=user.dict(),
                                       tags=tagevents,
                                       debts=debts)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing a user page, please try again.')
        return redirect('/')
Пример #9
0
def search_user():
    """
    GET - Renders a search user form.
    POST - Takes the value from the form and pass it to the database. Retrieves a list of user/users based on
    the information that was passed.

    :return: Renders template with the search result
    """
    try:
        if check_session():
            form = SearchUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data, form.lastname.data, form.email.data, None, None, None,
                                  form.city.data, None, None, None, None, None, None, None, None, None)

                users = mc.search_user(tmp_usr.dict())

                return render_template('search_user.html',
                                       title='Search User',
                                       form=form,
                                       hits=users)
            return render_template('search_user.html',
                                   title='Search User',
                                   form=form)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Searching for a user, please try again.')
        return redirect('/')
Пример #10
0
def tagin_user():
    form = NewTag(csrf_enabled=False)
    now = datetime.now()
    currenthour = now.hour
    nowtostring = str(now)
    timestampquery = nowtostring[:10]
    print(str(form.validate_on_submit()))
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_tag = Tagevent.query.filter(Tagevent.timestamp.contains(timestampquery)).filter(Tagevent.clockstamp.contains(currenthour)).first()
        user = User.query.filter(User.tag_id == form.tag_id.data).first()
        detailedtag = DetailedTagevent(form.tag_id.data)
        db.session.add(detailedtag)
        if user is not None:
            user.tagcounter += 1
            user.last_tag_timestamp = now
            if tmp_tag is None or tmp_tag == None:
                tmp_tag = Tagevent()
                tmp_tag.amount = 1
                db.session.add(tmp_tag)
            else:
                tmp_tag.amount += 1
        db.session.commit()
        flash('New tag created')
        return render_template('tagin_user.html',
                               title='New tag',
                               form=form)
    return render_template('tagin_user.html', title='New tag', form=form)
Пример #11
0
def debt_create(user_id):
    """
    GET - Renders a debt form.
    POST - Validates the debt form and check if the values are right. If they pass the informations is stored in
    the database and the debt is registrated. The tenant is redirected to the user page.
    If they fail the debt form is rendered with error messages.

    :param user_id:
    :type user_id: integer
    :return: Redirect to edit user page
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            dcl = debt_client.DebtSqlClient()
            user = cl.get_users(user_id)[0]
            form = NewDebt()

            if form.validate_on_submit():
                debt = sql_debt.SQLDebt(form.amount.data, user.id,
                                        form.product.data, None, None)
                dcl.add_dept(debt.dict())
                flash('Debt added for %s' %
                      (user.firstname + " " + user.lastname))
                return redirect("/user_page/" + user_id)

            return render_template('debt_create.html',
                                   title='Debt Create',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating debt, please try again.')
        return redirect('/')
Пример #12
0
def all_users(filter=None):
    """
    Lists all members based on the filter.

    :param filter:
    :type filter: string
    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret, users = [], []

            cl = user_client.UsersSqlClient()
            users = cl.get_users(0)

            # List users depending on the membership
            if filter != 'all':
                users = [x for x in users if x.status == filter.title()]

            users = sorted(users, key=lambda user: user.firstname)
            for hit in users:
                js = hit.dict()
                ret.append(js)
            return render_template('all_users.html',
                                   title='All Users',
                                   hits=ret,
                                   filter=filter,
                                   count=len(users))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing all users, please try again.')
        return redirect('/')
Пример #13
0
def sync_from_fortnox():
    try:
        fortnox_data = Fortnox()
        customers = fortnox_data.get_all_customers()
        ret = []

        for element in customers:
            for customer in element:

                cust = {'FortnoxID': customer["CustomerNumber"],
                        'OrganisationNumber': customer['OrganisationNumber'],
                        'Name': customer["Name"],
                        'Email': customer['Email'],
                        'Phone': customer['Phone'],
                        'Address1': customer['Address1'],
                        'Address2': customer['Address2'],
                        'City': customer['City'],
                        'Zipcode': customer['ZipCode']}

                ret.append(cust)

        for customer in ret:
            if User.query.filter_by(fortnox_id=customer['FortnoxID']).first() is not None:
                update_user_in_local_db_from_fortnox(customer)
            else:
                add_user_to_local_db_from_fortnox(customer)

        flash("Members from Fortnox is added to the database!")
    except:
        flash("Error retriving from Fortnox, Wrong credentials?")
Пример #14
0
def link_user_to_last_tag(user_id):
    """
    Links the user to the last tag. Grabs the last tag stored in the database and binds it to the specified member.
    Grabs only a tag that doesnt belong to another member.

    :param user_id:
    :type user_id: integer
    :return: Redirect to edit user page
    """
    try:
        if check_session():
            try:
                tc = tag_client.TageventsSqlClient()
                tagevent = tc.get_detailed_tagevents(0, 1)[0]

                cl = user_client.UsersSqlClient()
                user = cl.get_users(user_id)[0]

                if user is None:
                    return "No user have this ID"

                user.tag_id = tagevent.tag_id
                cl.update_user(user.dict())

                return redirect("/edit_user/" + str(user_id))
            except:
                flash("No tagging has happened")
                return redirect("/edit_user/" + str(user_id))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error linking user to last tag, please try again.')
        return redirect('/')
Пример #15
0
def search_user():
    """
    GET - Renders a search user form.
    POST - Takes the value from the form and pass it to the database. Retrieves a list of user/users based on
    the information that was passed.

    :return: Renders template with the search result
    """
    try:
        if check_session():
            form = SearchUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data,
                                  form.lastname.data, form.email.data, None,
                                  None, None, form.city.data, None, None, None,
                                  None, None, None, None, None, None)

                users = mc.search_user(tmp_usr.dict())

                return render_template('search_user.html',
                                       title='Search User',
                                       form=form,
                                       hits=users)
            return render_template('search_user.html',
                                   title='Search User',
                                   form=form)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Searching for a user, please try again.')
        return redirect('/')
Пример #16
0
def add_new_user():
    """
    GET - Renders a new user form.
    POST - Validates the user form and check if the values are right. If they pass the informations is stored in
    the database and the user is registrated. The tenant is redirected to the user page.
    If they fail the user form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = NewUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data,
                                  form.lastname.data, form.email.data,
                                  form.phone.data, form.address.data,
                                  form.address2.data, form.city.data,
                                  form.zip_code.data, None, form.gender.data,
                                  form.ssn.data, form.expiry_date.data, None,
                                  form.status.data, None, None)
                user_id = mc.add_user(tmp_usr.dict())
                return redirect('/user_page/' + str(user_id))

            return render_template('new_user.html',
                                   title='New User',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating a new user, please try again.')
        return redirect('/')
Пример #17
0
def add_new_user():
    """
    GET - Renders a new user form.
    POST - Validates the user form and check if the values are right. If they pass the informations is stored in
    the database and the user is registrated. The tenant is redirected to the user page.
    If they fail the user form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = NewUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data, form.lastname.data, form.email.data, form.phone.data,
                               form.address.data, form.address2.data, form.city.data,
                               form.zip_code.data, None, form.gender.data, form.ssn.data, form.expiry_date.data,
                               None, form.status.data, None, None)
                user_id = mc.add_user(tmp_usr.dict())
                return redirect('/user_page/' + str(user_id))

            return render_template('new_user.html',
                                   title='New User',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating a new user, please try again.')
        return redirect('/')
Пример #18
0
def sync_from_fortnox():
    try:
        fortnox_data = Fortnox()
        customers = fortnox_data.get_all_customers()
        ret = []

        for element in customers:
            for customer in element:

                cust = {
                    'FortnoxID': customer["CustomerNumber"],
                    'OrganisationNumber': customer['OrganisationNumber'],
                    'Name': customer["Name"],
                    'Email': customer['Email'],
                    'Phone': customer['Phone'],
                    'Address1': customer['Address1'],
                    'Address2': customer['Address2'],
                    'City': customer['City'],
                    'Zipcode': customer['ZipCode']
                }

                ret.append(cust)

        for customer in ret:
            if User.query.filter_by(
                    fortnox_id=customer['FortnoxID']).first() is not None:
                update_user_in_local_db_from_fortnox(customer)
            else:
                add_user_to_local_db_from_fortnox(customer)

        flash("Members from Fortnox is added to the database!")
    except:
        flash("Error retriving from Fortnox, Wrong credentials?")
Пример #19
0
def debt_delete(id):
    debts = Debt.query.filter_by(id=id).first()
    users = User.query.filter_by(index=debts.uid).first()
    db.session.delete(debts)
    db.session.commit()
    flash('Deleted debt: %s from member %s' % (debts.amount,
                                               users.name))
    return redirect("/user_page/"+str(users.index))
Пример #20
0
def redirect_not_logged_in():
    """
    Redirect the page if the tenant is not logged in and is trying to reach a page without permission

    :return: redirect to front page
    """
    flash('You need to login before entering the application')
    return redirect('/')
Пример #21
0
def redirect_not_logged_in():
    """
    Redirect the page if the tenant is not logged in and is trying to reach a page without permission

    :return: redirect to front page
    """
    flash('You need to login before entering the application')
    return redirect('/')
Пример #22
0
def statistics_by_date(_month, _day, _year):
    """
    Renders statistic from the database on the specified date from the params.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :param _month:
    :param _day:
    :param _year:
    :type _month: string
    :type _day: string
    :type _year: string
    :return: Render template for statistic
    """
    try:
        if check_session():
            chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()

            default_date = datetime.now()
            selected_date = default_date.replace(day=int(_day),
                                                 month=int(_month),
                                                 year=int(_year))
            week_day_name = selected_date.strftime('%A')
            month_name = selected_date.strftime('%B')
            custom_date_day = {
                'weekday':
                week_day_name + ' ' + str(selected_date.day) + '/' +
                str(selected_date.month) + '/' + str(selected_date.year)
            }

            custom_date_month = {
                'month': month_name + ' ' + str(selected_date.year)
            }
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, chosen_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
Пример #23
0
def edit_user(user_index=None):
    """
    GET - Renders a edit user form.
    POST - Validates the user form and check if the values are right. If they pass the information is stored in
    the database and the user is updated. The tenant is redirected to the user page.
    If they fail the edit user form is rendered with error messages.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user have this ID"

            form = EditUser(obj=user)
            if form.validate_on_submit():
                user.firstname = form.firstname.data
                user.lastname = form.lastname.data
                user.email = form.email.data
                user.phone = form.phone.data
                user.address = form.address.data
                user.address2 = form.address2.data
                user.city = form.city.data
                user.zip_code = form.zip_code.data
                user.tag_id = form.tag_id.data
                user.gender = form.gender.data
                user.expiry_date = form.expiry_date.data
                user.status = form.status.data

                cl.update_user(user.dict())
                # Not in use at this point. Will be a future feature..
                # If we successfully edited the user, redirect back to userpage.
                # fortnox_data = Fortnox()
                # fortnox_data.update_customer(user)
                return redirect("/user_page/"+str(user.id))

            if user:
                return render_template('edit_user.html',
                                       title='Edit User',
                                       form=form,
                                       data=user.dict(),
                                       error=form.errors)
            else:
                return "she wrote upon it; no such number, no such zone"
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Editing a user, please try again.')
        return redirect('/')
Пример #24
0
def link_user_to_last_tag(user_id):
    try:
        tagevent = get_last_tag_event()
        user = User.query.filter_by(index=user_id).first()
        user.tag_id = tagevent.tag_id
        db.session.commit()
        return redirect("/edit_user/" + str(user.index))
    except:
        flash("No tagging has happened")
        user = User.query.filter_by(index=user_id).first()
        return redirect("/edit_user/" + str(user.index))
Пример #25
0
def link_user_to_last_tag(user_id):
    try:
        tagevent = get_last_tag_event()
        user = User.query.filter_by(index=user_id).first()
        user.tag_id = tagevent.tag_id
        db.session.commit()
        return redirect("/edit_user/"+str(user.index))
    except:
        flash("No tagging has happened")
        user = User.query.filter_by(index=user_id).first()
        return redirect("/edit_user/"+str(user.index))
Пример #26
0
def edit_user(user_index=None):
    """
    GET - Renders a edit user form.
    POST - Validates the user form and check if the values are right. If they pass the information is stored in
    the database and the user is updated. The tenant is redirected to the user page.
    If they fail the edit user form is rendered with error messages.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user have this ID"

            form = EditUser(obj=user)
            if form.validate_on_submit():
                user.firstname = form.firstname.data
                user.lastname = form.lastname.data
                user.email = form.email.data
                user.phone = form.phone.data
                user.address = form.address.data
                user.address2 = form.address2.data
                user.city = form.city.data
                user.zip_code = form.zip_code.data
                user.tag_id = form.tag_id.data
                user.gender = form.gender.data
                user.expiry_date = form.expiry_date.data
                user.status = form.status.data

                cl.update_user(user.dict())
                # Not in use at this point. Will be a future feature..
                # If we successfully edited the user, redirect back to userpage.
                # fortnox_data = Fortnox()
                # fortnox_data.update_customer(user)
                return redirect("/user_page/" + str(user.id))

            if user:
                return render_template('edit_user.html',
                                       title='Edit User',
                                       form=form,
                                       data=user.dict(),
                                       error=form.errors)
            else:
                return "she wrote upon it; no such number, no such zone"
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Editing a user, please try again.')
        return redirect('/')
Пример #27
0
def login():
    """
    GET - Renders a login template for the tenant
    POST - Validates the login form and check if the values are right. If they pass the tenant is logged in and redirected
    to the front page again, if not the login templated is rendered with an message.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Login()
            if form.validate_on_submit():
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(form.username.data.title())
                if stored_hash is not None:
                    if bcrypt.hashpw(form.password.data,
                                     stored_hash) == stored_hash:
                        # Use above to match passwords
                        session['loggedIn'] = True
                        session['username'] = form.username.data.title()
                        flash('Welcome %s' % form.username.data.title())
                        return redirect('/')
                    else:
                        flash('Wrong username or password')
                else:
                    flash('Wrong username')

            return render_template('login.html', title='Login', form=form)
        else:
            return redirect('/')
    except:
        flash('Error Trying to login, please try again.')
        return redirect('/')
Пример #28
0
def registration():
    """
    GET - Renders a registration form.
    POST - Validates the login form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is registrated and is redirected to the front page.
    If they fail the registration form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Register()
            if form.validate_on_submit():
                # TODO: Remove temporally disabled registration, 2 lines below
                flash('Registration is temporarily disabled.')
                return redirect('/')
                '''
                # 1 Get password from form
                password = form.password.data.encode('utf-8')
                # 2 Hash the password
                hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
                # 3 Save the Tenant in the db
                registered_tenant = {'username': form.username.data.title(),
                                     'password': hashed_password,
                                     'active_fortnox': form.active_fortnox.data,
                                     'gym_name': form.gym_name.data,
                                     'address': form.address.data,
                                     'phone': form.phone.data,
                                     'zip_code': form.zip_code.data,
                                     'city': form.city.data,
                                     'email': form.email.data,
                                     'pass': registration_client.cfg.TENANT_PASSWORD + form.username.data.title()}

                cl = registration_client.RegisterLoginSqlClient()
                if cl.do_registration(registered_tenant):
                    flash('Registration done, you can now log in')
                    return redirect('/')
                else:
                    flash('Username already exists')
                '''

            return render_template('register.html',
                                   title='Register new Tenant',
                                   form=form,
                                   errors=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error when trying to register, please try again.')
        return redirect('/')
Пример #29
0
def login():
    """
    GET - Renders a login template for the tenant
    POST - Validates the login form and check if the values are right. If they pass the tenant is logged in and redirected
    to the front page again, if not the login templated is rendered with an message.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Login()
            if form.validate_on_submit():
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(form.username.data.title())
                if stored_hash is not None:
                    if bcrypt.hashpw(form.password.data, stored_hash) == stored_hash:
                        # Use above to match passwords
                        session['loggedIn'] = True
                        session['username'] = form.username.data.title()
                        flash('Welcome %s' % form.username.data.title())
                        return redirect('/')
                    else:
                        flash('Wrong username or password')
                else:
                    flash('Wrong username')

            return render_template('login.html', title='Login', form=form)
        else:
            return redirect('/')
    except:
        flash('Error Trying to login, please try again.')
        return redirect('/')
Пример #30
0
def statistics_by_date(_month, _day, _year):
    """
    Renders statistic from the database on the specified date from the params.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :param _month:
    :param _day:
    :param _year:
    :type _month: string
    :type _day: string
    :type _year: string
    :return: Render template for statistic
    """
    try:
        if check_session():
            chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()

            default_date = datetime.now()
            selected_date = default_date.replace(day=int(_day), month=int(_month), year=int(_year))
            week_day_name = selected_date.strftime('%A')
            month_name = selected_date.strftime('%B')
            custom_date_day = {'weekday': week_day_name + ' ' + str(selected_date.day)
                                          + '/' + str(selected_date.month)
                                          + '/' + str(selected_date.year)}

            custom_date_month = {'month': month_name + ' ' + str(selected_date.year)}
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, chosen_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
Пример #31
0
def statistics():
    """
    Renders statistic from the database on todays date.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :return: Render template for statistic
    """
    try:
        if check_session():
            default_date = datetime.now()
            default_date_array = {
                'year': str(default_date.year),
                'month': str(default_date.strftime('%m')),
                'day': str(default_date.strftime('%d'))
            }
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()
            week_day_name = default_date.strftime('%A')
            month_name = default_date.strftime('%B')
            custom_date_day = {
                'weekday':
                week_day_name + ' ' + str(default_date.day) + '/' +
                str(default_date.month) + '/' + str(default_date.year)
            }
            custom_date_month = {
                'month': month_name + ' ' + str(default_date.year)
            }
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, default_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
Пример #32
0
def fortnox_users():
    """
    Syncs the database with users from fortnox database.
    Add or updates the users.

    :return: Redirect to front page
    """
    try:
        if check_session():
            sync_from_fortnox()
            return redirect("/")
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Syncing from fortnox, please try again.')
        return redirect('/')
Пример #33
0
def debt_create(id_test):
    user = User.query.filter_by(index=id_test).first()
    form = NewDebt()
    test = datetime.now()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_debt = Debt(form.amount.data, user.index, form.product.data, test)
        db.session.add(tmp_debt)
        db.session.commit()
        flash('Created new debt: %s for member %s' %
              (form.amount.data, user.name))
        return redirect("/user_page/" + id_test)
    return render_template('debt_create.html',
                           title='Debt Create',
                           form=form,
                           error=form.errors)
Пример #34
0
def fortnox_users():
    """
    Syncs the database with users from fortnox database.
    Add or updates the users.

    :return: Redirect to front page
    """
    try:
        if check_session():
            sync_from_fortnox()
            return redirect("/")
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Syncing from fortnox, please try again.')
        return redirect('/')
Пример #35
0
def debt_create(id_test):
    user = User.query.filter_by(index=id_test).first()
    form = NewDebt()
    test = datetime.now()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_debt = Debt(form.amount.data, user.index, form.product.data, test)
        db.session.add(tmp_debt)
        db.session.commit()
        flash('Created new debt: %s for member %s' % (form.amount.data,
                                                      user.name))
        return redirect("/user_page/"+id_test)
    return render_template('debt_create.html',
                           title='Debt Create',
                           form=form,
                           error=form.errors)
Пример #36
0
def registration():
    """
    GET - Renders a registration form.
    POST - Validates the login form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is registrated and is redirected to the front page.
    If they fail the registration form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Register()
            if form.validate_on_submit():
                # TODO: Remove temporally disabled registration, 2 lines below
                flash('Registration is temporarily disabled.')
                return redirect('/')
                '''
                # 1 Get password from form
                password = form.password.data.encode('utf-8')
                # 2 Hash the password
                hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
                # 3 Save the Tenant in the db
                registered_tenant = {'username': form.username.data.title(),
                                     'password': hashed_password,
                                     'active_fortnox': form.active_fortnox.data,
                                     'gym_name': form.gym_name.data,
                                     'address': form.address.data,
                                     'phone': form.phone.data,
                                     'zip_code': form.zip_code.data,
                                     'city': form.city.data,
                                     'email': form.email.data,
                                     'pass': registration_client.cfg.TENANT_PASSWORD + form.username.data.title()}

                cl = registration_client.RegisterLoginSqlClient()
                if cl.do_registration(registered_tenant):
                    flash('Registration done, you can now log in')
                    return redirect('/')
                else:
                    flash('Username already exists')
                '''

            return render_template('register.html', title='Register new Tenant', form=form, errors=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error when trying to register, please try again.')
        return redirect('/')
Пример #37
0
def remove_user(user_id):
    """
    Deletes a user from the database.

    :param user_id:
    :type user_id: integer
    :return: Redirect
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            cl.remove_user(user_id)
            flash('Member was removed!')
            return redirect("/all_users/all")
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Removing a user, please try again.')
        return redirect('/')
Пример #38
0
def last_tagins():
    """
    Lists the last tagins. At the moment ( 2016-05-19 ) it is the last 10 tags, but this will be changeable

    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret = []
            cl = tag_client.TageventsSqlClient()
            detailed_tagevents = cl.get_detailed_tagevents(0, 10)
            return render_template('last_tagevents.html',
                                   title='Last Tagins',
                                   hits=detailed_tagevents)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing last tagins, please try again.')
        return redirect('/')
Пример #39
0
def remove_user(user_id):
    """
    Deletes a user from the database.

    :param user_id:
    :type user_id: integer
    :return: Redirect
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            cl.remove_user(user_id)
            flash('Member was removed!')
            return redirect("/all_users/all")
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Removing a user, please try again.')
        return redirect('/')
Пример #40
0
def last_tagins():
    """
    Lists the last tagins. At the moment ( 2016-05-19 ) it is the last 10 tags, but this will be changeable

    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret = []
            cl = tag_client.TageventsSqlClient()
            detailed_tagevents = cl.get_detailed_tagevents(0, 10)
            return render_template('last_tagevents.html',
                                   title='Last Tagins',
                                   hits=detailed_tagevents)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing last tagins, please try again.')
        return redirect('/')
Пример #41
0
def debt_check():
    """
    Renders a template with a list of all users with debts

    :return: Renders template with a list of users
    """
    try:
        if check_session():
            dcl = debt_client.DebtSqlClient()
            debt_array = dcl.get_debt()

            return render_template('debt_check.html',
                                   title='Check',
                                   hits=debt_array)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing debt, please try again.')
        return redirect('/')
Пример #42
0
def debt_check():
    """
    Renders a template with a list of all users with debts

    :return: Renders template with a list of users
    """
    try:
        if check_session():
            dcl = debt_client.DebtSqlClient()
            debt_array = dcl.get_debt()

            return render_template('debt_check.html',
                                   title='Check',
                                   hits=debt_array)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing debt, please try again.')
        return redirect('/')
Пример #43
0
def inactive_check():
    """
    Renders a template with a list of all users that have not tagged in for the last 2 weeks

    :return: Renders template with a user list
    """
    try:
        if check_session():
            ret = []
            mc = user_client.UsersSqlClient()
            users = mc.get_inactive_users()

            return render_template('inactive_check.html',
                                   title='Inactive Members',
                                   hits=users)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing Inactive Users, please try again.')
        return redirect('/')
Пример #44
0
def statistics():
    """
    Renders statistic from the database on todays date.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :return: Render template for statistic
    """
    try:
        if check_session():
            default_date = datetime.now()
            default_date_array = {'year': str(default_date.year),
                                  'month': str(default_date.strftime('%m')),
                                  'day':str(default_date.strftime('%d'))}
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()
            week_day_name = default_date.strftime('%A')
            month_name = default_date.strftime('%B')
            custom_date_day = {'weekday': week_day_name + ' ' + str(default_date.day) + '/' + str(default_date.month) + '/' +
                               str(default_date.year)}
            custom_date_month = {'month': month_name + ' ' + str(default_date.year)}
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, default_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
Пример #45
0
def inactive_check():
    """
    Renders a template with a list of all users that have not tagged in for the last 2 weeks

    :return: Renders template with a user list
    """
    try:
        if check_session():
            ret = []
            mc = user_client.UsersSqlClient()
            users = mc.get_inactive_users()


            return render_template('inactive_check.html',
                                   title='Inactive Members',
                                   hits=users)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing Inactive Users, please try again.')
        return redirect('/')
Пример #46
0
def debt_delete(debt_id, user_id):
    """
    Deletes a debt from a user and redirect back to the userpage

    :param debt_id:
    :param user_id:
    :type debt_id: integer
    :type user_id: integer
    :return: Redirect to user page
    """
    try:
        if check_session():
            dcl = debt_client.DebtSqlClient()
            dcl.remove_debt(debt_id)
            flash('Debt was deleted!')
            return redirect("/user_page/"+str(user_id))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Deleting debt, please try again.')
        return redirect('/')
Пример #47
0
def fortnox_information():
    """
    GET - Renders a settings form for fortnox information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = EditFortnoxInformation()
            return render_template('fortnox_information.html', title='Settings Tab',
                                   form=form,
                                   data='',
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating fortnox information, please try again.')
        return redirect('/')
Пример #48
0
def debt_delete(debt_id, user_id):
    """
    Deletes a debt from a user and redirect back to the userpage

    :param debt_id:
    :param user_id:
    :type debt_id: integer
    :type user_id: integer
    :return: Redirect to user page
    """
    try:
        if check_session():
            dcl = debt_client.DebtSqlClient()
            dcl.remove_debt(debt_id)
            flash('Debt was deleted!')
            return redirect("/user_page/" + str(user_id))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Deleting debt, please try again.')
        return redirect('/')
Пример #49
0
def fortnox_information():
    """
    GET - Renders a settings form for fortnox information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = EditFortnoxInformation()
            return render_template('fortnox_information.html',
                                   title='Settings Tab',
                                   form=form,
                                   data='',
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating fortnox information, please try again.')
        return redirect('/')
Пример #50
0
def sync_from_fortnox():
    """
    Helper script to sync the local database with the content of the database on fortnox.
    Either updates an existing customer or creates a new.
    """
    try:
        fortnox_data = Fortnox()
        customers = fortnox_data.get_all_customers()
        ret = []
        for element in customers:
            for customer in element:
                # Split firstname and lastname
                name = customer['Name'].split()
                # If the user only got a firstname, add blank to the lastname
                if len(name) < 2:
                    name.append('')

                cust = sql_user.SQLUser(None, customer['CustomerNumber'],
                                        name[0], name[1], customer['Email'],
                                        customer['Phone'], customer['Address1'],
                                        customer['Address2'], customer['City'],
                                        customer['ZipCode'], None,
                                        get_gender_from_ssn(customer),
                                        customer['OrganisationNumber'][:-5], None, None, None,
                                        None, None)
                ret.append(cust.dict())

        cl = client.UsersSqlClient()
        # If the user from Fortnox all ready exists in the database, update it. If it doesn't exist, create a new.
        for customer in ret:
            if cl.does_user_exist(customer['fortnox_id']):
                cl.add_user(customer)
            else:
                cl.update_user(customer)

        flash("Members from Fortnox is added/updated to the database!")
    except:
        flash("Something happend while adding/updating from fortnox")
Пример #51
0
def settings():
    """
    GET - Renders a settings form with tenant information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditTenant(obj=current_tenant)
            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data,
                                                stored_hash)
                    if hashed_pass == stored_hash:
                        # Saves new pass from form
                        hashed_new_pass = form.new_password.data
                        # if the new pass is not empty, hash it
                        if hashed_new_pass is not '':
                            hashed_new_pass = bcrypt.hashpw(
                                hashed_new_pass, bcrypt.gensalt())

                        tenant = {
                            'id': current_tenant.id,
                            'password': hashed_pass,
                            'new_password': hashed_new_pass,
                            'active_fortnox': form.active_fortnox.data,
                            'image': form.image.data,
                            'background_color': form.background_color.data
                        }
                        clt.update_tenant_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('settings.html',
                                   title='Settings Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating information, please try again.')
        return redirect('/')
Пример #52
0
def general_information():
    """
    GET - Renders a settings form with general information.
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditGeneralInformation(obj=current_tenant)

            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data,
                                                stored_hash)
                    if hashed_pass == stored_hash:
                        tenant = {
                            'id': current_tenant.id,
                            'password': hashed_pass,
                            'gym_name': form.gym_name.data,
                            'address': form.address.data,
                            'phone': form.phone.data,
                            'zip_code': form.zip_code.data,
                            'city': form.city.data,
                            'email': form.email.data
                        }
                        clt.update_tenant_general_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('general_information.html',
                                   title='General Information Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating general information, please try again.')
        return redirect('/')
Пример #53
0
def settings():
    """
    GET - Renders a settings form with tenant information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditTenant(obj=current_tenant)
            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data, stored_hash)
                    if hashed_pass == stored_hash:
                        # Saves new pass from form
                        hashed_new_pass = form.new_password.data
                        # if the new pass is not empty, hash it
                        if hashed_new_pass is not '':
                            hashed_new_pass = bcrypt.hashpw(hashed_new_pass, bcrypt.gensalt())

                        tenant = {'id': current_tenant.id,
                                  'password': hashed_pass,
                                  'new_password': hashed_new_pass,
                                  'active_fortnox': form.active_fortnox.data,
                                  'image': form.image.data,
                                  'background_color': form.background_color.data}
                        clt.update_tenant_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('settings.html', title='Settings Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating information, please try again.')
        return redirect('/')
Пример #54
0
def general_information():
    """
    GET - Renders a settings form with general information.
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditGeneralInformation(obj=current_tenant)

            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data, stored_hash)
                    if hashed_pass == stored_hash:
                        tenant = {'id': current_tenant.id,
                                  'password': hashed_pass,
                                  'gym_name': form.gym_name.data,
                                  'address': form.address.data,
                                  'phone': form.phone.data,
                                  'zip_code': form.zip_code.data,
                                  'city': form.city.data,
                                  'email': form.email.data}
                        clt.update_tenant_general_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('general_information.html', title='General Information Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating general information, please try again.')
        return redirect('/')
Пример #55
-1
def link_user_to_last_tag(user_id):
    """
    Links the user to the last tag. Grabs the last tag stored in the database and binds it to the specified member.
    Grabs only a tag that doesnt belong to another member.

    :param user_id:
    :type user_id: integer
    :return: Redirect to edit user page
    """
    try:
        if check_session():
            try:
                tc = tag_client.TageventsSqlClient()
                tagevent = tc.get_detailed_tagevents(0, 1)[0]

                cl = user_client.UsersSqlClient()
                user = cl.get_users(user_id)[0]

                if user is None:
                    return "No user have this ID"

                user.tag_id = tagevent.tag_id
                cl.update_user(user.dict())

                return redirect("/edit_user/"+str(user_id))
            except:
                flash("No tagging has happened")
                return redirect("/edit_user/"+str(user_id))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error linking user to last tag, please try again.')
        return redirect('/')