Example #1
0
def add_tarefa():
    # gets tarefa from the form and add to db
    tarefa = request.form.get("tarefa")
    email = session["user"]
    sql = "INSERT INTO tarefas(email, tarefa) VALUES('{}','{}')".format(
        email, tarefa)
    update_data(sql)
    return redirect("todo")
def add_acount(email, pwd):
    sql = "SELECT email FROM accounts WHERE email = " + "'" + email + "'"
    result = get_data(sql)
    if len(result) == 0:
        time = datetime.now()
        pwd = generate_password_hash(pwd)
        sql = "INSERT INTO accounts(email, pwd, date_time) VALUES('{}','{}','{}')".format(
            email, pwd, time)
        update_data(sql)
        return "Cadastro realizado com sucesso"
    else:
        return "Email já cadastrado"
def recupera_senha(email):
    sql = "SELECT email, pwd FROM accounts WHERE email = " + "'" + email + "'"
    result = get_data(sql)
    if len(result) == 0:
        return "Email não cadastrado"
    else:
        randon_pwd = get_random_alphanumeric_string(10)
        new_pwd = generate_password_hash(randon_pwd)
        sql = "UPDATE accounts SET pwd='{}' WHERE email = '{}'".format(
            new_pwd, email)
        update_data(sql)
        return randon_pwd
def alterar_senha(email, pwd_atual, pwd_novo_1, pwd_novo_2):
    # check email and pwd
    result = login(email, pwd_atual)
    if result == "sucess":
        # check if new passords provided  match
        if pwd_novo_1 == pwd_novo_2:
            new_pwd = generate_password_hash(pwd_novo_1)
            sql = "UPDATE accounts SET pwd='{}' WHERE email = '{}'".format(
                new_pwd, email)
            update_data(sql)
            return "Password alterado com sucesso."
        else:
            return "Password novos são diferentes."
    else:
        return "Password atual é invalido."
Example #5
0
def delete_tarefa():
    # gets the tarefa's id and delete from db
    tarefa_id = request.form.get("tarefa_id")
    sql = "DELETE FROM tarefas WHERE tarefa_id = {}".format(tarefa_id)
    update_data(sql)
    return redirect("todo")