Пример #1
0
def apply():
    msg = ''
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']

        qualification = request.form['qualification']
        skills = request.form['skills']
        jobs = request.form['s']
        cursor = mysql.connection.cursor()
        cursor.execute('SELECT * FROM job WHERE userid = % s',
                       (session['id'], ))
        account = cursor.fetchone()
        print(account)
        if account:
            msg = 'there is only 1 job position! for you'
            return render_template('apply.html', msg=msg)

        cursor = mysql.connection.cursor()
        cursor.execute(
            'INSERT INTO job VALUES (% s, % s, % s, % s,% s, % s)',
            (session['id'], username, email, qualification, skills, jobs))
        mysql.connection.commit()
        msg = 'You have successfully applied for job !'
        session['loggedin'] = True
        TEXT = "Hello sandeep,a new appliaction for job position" + jobs + "is requested"

        #sendmail(TEXT,"*****@*****.**")
        sendgridmail("*****@*****.**", TEXT)

    elif request.method == 'POST':
        msg = 'Please fill out the form !'
    return render_template('apply.html', msg=msg)
Пример #2
0
def registet():
    msg = ''
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        password = request.form['password']

        cursor = mysql.connection.cursor()
        cursor.execute('SELECT * FROM user WHERE username = % s', (username, ))
        account = cursor.fetchone()
        print(account)
        if account:
            msg = 'Account already exists !'
        elif not re.match(r'[^@]+@[^@]+\.[^@]+', email):
            msg = 'Invalid email address !'
        elif not re.match(r'[A-Za-z0-9]+', username):
            msg = 'name must contain only characters and numbers !'
        else:
            cursor.execute('INSERT INTO user VALUES (NULL, % s, % s, % s)',
                           (username, email, password))
            mysql.connection.commit()
            msg = 'You have successfully registered !'
            TEXT = "Hello " + username + ",\n\n" + """Thanks for applying registring at smartinterns """
            message = 'Subject: {}\n\n{}'.format("smartinterns Carrers", TEXT)
            #sendmail(TEXT,email)
            sendgridmail(email, TEXT)
    elif request.method == 'POST':
        msg = 'Please fill out the form !'
    return render_template('register.html', msg=msg)
Пример #3
0
def register():
    msg = ''
    if request.method == 'POST':
        username = request.form['uname']
        password = request.form['pass']
        email = request.form['email']
        session['username'] = username
        session['password'] = password
        session['email'] = email
        hashed_pr = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
        session['hash'] = hashed_pr

        cursor = mysql.connection.cursor()
        cursor.execute('SELECT * FROM user WHERE username = % s', (username, ))
        account = cursor.fetchone()

        if account:
            msg = "Account already exists"
        else:
            msg = "you have sucessfully registerd"
            cursor.execute('INSERT INTO user VALUES (NULL, % s, % s, % s)', (
                username,
                hashed_pr,
                email,
            ))
            mysql.connection.commit()
            msg = 'You have successfully registered  Please Check your  Registerd Email'
            session['loggedin'] = False

            TEXT = "Hello " + username + ",\n\n" + """Thanks for registering at Ex-Pense Tracker please login to your account for better experince  """
            message = 'Subject: {}\n\n{}'.format("Ex-Pense Tracker", TEXT)
            sendmail(TEXT, email)
            sendgridmail(email, TEXT)

            return render_template('main.html', msg=msg)

    return render_template('register.html', msg=msg)
Пример #4
0
def expense():
    if 'id' in session:

        username = session['username']
        email = session['email']
        userid = session['id']

    e_id = session['id']
    amount = request.form['am']
    category = request.form['categ']
    date = request.form['date']

    description = request.form['desc']
    cursor = mysql.connection.cursor()
    session['y_r'] = date[0:4]

    cursor.execute(
        'SELECT bamount FROM budget WHERE id=%s AND b_month LIKE %s',
        (session['id'], date[0:4] + '-' + month[int(date[5:7]) - 1]))
    check = cursor.fetchone()
    if check:

        cursor.execute('INSERT INTO expense_a VALUES(NULL,%s,%s,%s,%s,%s)', (
            e_id,
            amount,
            category,
            date,
            description,
        ))
        mysql.connection.commit()

    cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
    cursor.execute('SELECT bamount FROM budget WHERE id = % s ', (e_id, ))
    bud = cursor.fetchone()

    cursor.execute(
        'SELECT ex_id,amount,category,date,description FROM expense_a WHERE id = %s AND monthname(date)=%s AND YEAR(date)=%s',
        (session['id'], session['b_m'], session['y_r']))
    data = cursor.fetchall()

    cursor.execute(
        'SELECT SUM(amount) AS tsum FROM expense_a WHERE id = %s AND monthname(date)=%s AND YEAR(date)=%s ',
        (
            session['id'],
            session['b_m'],
            session['y_r'],
        ))
    total = cursor.fetchone()

    session['total'] = str(total['tsum'])

    if total['tsum'] == None:
        total['tsum'] = 0

    bud = session['budget']

    if check:

        if data:
            if session['s_m']:
                flash(u"Expense has been added", "success")

                if (total['tsum'] > bud):
                    msg = 'You have successfully registered  Please Check your  Registerd Email'
                    session['loggedin'] = True

                    TEXT = ' Dear' + ' ' + session[
                        'username'] + ' You have exceeded your monthly budget of amount' + ' ' + str(
                            session['budget']
                        ) + ', For the month of' + ' ' + session[
                            's_m'] + '.You current expenses are worth:' + session[
                                'total'] + 'Yours Truely,Ex-pense Tracker'
                    message = 'Subject: {}\n\n{}'.format(
                        "Ex-Pense Tracker", TEXT)
                    sendmail(TEXT, email)
                    sendgridmail(email, TEXT)
                return redirect(
                    url_for('switch_month',
                            mon=session['s_m'],
                            data=data,
                            budget=int(bud),
                            total=int(total['tsum'])))
            else:
                flash(u"Expense has been added", "success")

                return redirect(
                    url_for('switch_month',
                            mon=session['b_m'],
                            data=data,
                            budget=int(bud),
                            total=int(total['tsum'])))

    else:

        flash(u"Budget not set for the month inputted for the expense",
              "danger")
        return redirect(
            url_for('dashboard',
                    data=data,
                    budget=int(bud),
                    total=int(total['tsum'])))