Beispiel #1
0
def child_login():
    if request.method == 'POST':
        child_username = request.form['child_username']
        child_password = request.form['child_password']
        db = get_db()

        error = None
        child = db.execute('SELECT * FROM child WHERE child_username =?',
                           (child_username, )).fetchone()

        if child is None:
            error = 'Incorrect username.'
        elif not check_password_hash(child['child_password'], child_password):
            error = "incorret password"

        if error is None:
            session.clear()
            session['child_id'] = child['child_id']

            return redirect(url_for('goal.account'))

        flash(error)

    return render_template('auth/child_login.html')
Beispiel #2
0
def child_register():
    if request.method == "POST":
        child_username = request.form['child_username']
        parent_email = request.form['parent_email']
        child_password = request.form['child_password']
        db = get_db()
        error = None

        parent = db.execute('SELECT * FROM parent WHERE parent_email =?',
                            (parent_email, )).fetchone()

        if not child_username:
            error = 'Username is required'
        elif not parent_email:
            error = 'Email is required'
        elif not child_password:
            error = 'Password is required'

        elif db.execute('SELECT child_id FROM child WHERE child_username = ?',
                        (child_username, )).fetchone() is not None:
            error = 'USER {} is already registered'.format(child_username)

        elif parent is None:
            error = 'Parent  is not  registered Yet.'

        if error is None:
            db.execute(
                'INSERT INTO child (child_username , parent_email ,child_password) VALUES (? ,? , ?)',
                (child_username, parent_email,
                 generate_password_hash(child_password)))
            db.commit()
            return redirect(url_for('auth.first_child_login'))

        flash(error)

    return render_template('auth/child_register.html')
Beispiel #3
0
def delete(goal_id):
    get_goal(goal_id)
    db = get_db()
    db.execute('DELETE FROM goal WHERE goal_id = ?', (goal_id, ))
    db.commit()
    return redirect(url_for('goal.account'))
Beispiel #4
0
def account():
    db = get_db()

    goals = db.execute(
        'SELECT go.goal_id , income_amt , goal_amt , saving_amt , emergency_amt , author_id , goal_name , child_username , time_left ,personal_amt, created , bonus , counter , goal_saving  , fix_saving_amt'
        ' FROM goal go JOIN child c ON go.author_id = c.child_id'
        ' ORDER BY created DESC').fetchall()

    from datetime import datetime

    counter = 0
    for x in goals:
        counter += 1

    for i in range(0, counter):
        # print(goals[i]['created'])
        created_time = goals[i]['created']
        today = datetime.today()
        #created_time += 30

        goal_saving = goals[i]['goal_saving']

        fix_saving_amt = goals[i]['fix_saving_amt']

        #print("MYSQL" , created_time.strftime('%Y-%m-%d'))
        created_month = int(created_time.strftime('%m'))
        created_date = int(created_time.strftime('%d'))
        tracker = goals[i]['counter']

        tracker += created_month

        # print(created_time)
        # print(today)

        curr_month = int(today.strftime('%m'))
        curr_date = int(today.strftime('%d'))

        # DONE :UPDATE SAVING AMT for 1 year ONLY.

        if (tracker != 12):
            if (created_date == curr_date and tracker + 1 == curr_month):
                # update saving acct  x2
                saving_amt = goals[i]['saving_amt']

                goal_saving += fix_saving_amt
                saving_amt += saving_amt

                tracker += 1
                db.execute(
                    'UPDATE goal SET saving_amt = ? ,counter = ?, goal_saving= ? '
                    ' WHERE created = ?',
                    (saving_amt, tracker, goal_saving, created_time))
                db.commit()

        else:
            if (created_date == curr_date and curr_month == 1):
                saving_amt = goals[i]['saving_amt']

                goal_saving += fix_saving_amt
                saving_amt += saving_amt

                tracker = 1 - (created_month)
                db.execute(
                    'UPDATE goal SET saving_amt = ? ,counter = ?  , goal_saving=?'
                    ' WHERE created = ?',
                    (saving_amt, tracker, goal_saving, created_time))
                db.commit()

    return render_template('goal/account.html', goals=goals)