def login_op(username, password):
    conn = opsql.Database()
    sql = "select username from user where username=%s and password=%s"
    para = [username, password]
    result = [i for i in conn.select(sql, para)]
    conn.close()
    return '2' if result == [] else '1'
def get_mail_op(name):
    conn = opsql.Database()
    sql = "select mail from user where username=%s"
    para = [name]
    result = [i for i in conn.select(sql, para)]
    conn.close()
    return result[0][0]
def file_download_op(name, filename):
    conn = opsql.Database()
    sql = "select content from file where username=%s and filename=%s"
    para = [name, filename]
    result = [i for i in conn.select(sql, para)]
    if result:
        return result[0][0]
    else:
        return 'nodata'
def get_filenames_op(name):
    conn = opsql.Database()
    sql = "select filename from file where username=%s"
    para = [name]
    result = 'begin '
    for i in conn.select(sql, para):
        result += i[0] + ' '
    result += 'end'
    conn.close()
    return result
def change_mail_op(name, new_mail):
    conn = opsql.Database()
    sql = "select mail from user where mail=%s"
    para = [new_mail]
    result = [i for i in conn.select(sql, para)]
    conn.close()
    if result != []:
        return '2'
    email = ope.Email()
    if (email.send_email(name, new_mail)):
        return '1'
    else:
        return '3'
Exemple #6
0
def register_verification_op(username, password, mail, v_code):
    conn = opsql.Database()
    if (storage.verification(username, v_code)):
        sql = "insert into user (username,password,mail) values (%s,%s,%s)"
        para = [username, password, mail]
        is_sucess = conn.iur(sql, para)
        if is_sucess:
            storage.remove(username)
            return '1'
        else:
            return '2'
    else:
        return '2'
def change_password_op(name, mail):
    conn = opsql.Database()
    sql = "select username,mail from user where username=%s or mail=%s"
    para = [name, mail]
    result = [i for i in conn.select(sql, para)]
    conn.close()
    if not result:
        return '2'
    email = ope.Email()
    if (email.send_email(result[0][0], result[0][1])):
        return '1'
    else:
        return '3'
def change_mail_verification_op(name, new_mail, verification_code):
    conn = opsql.Database()
    if (storage.verification(name, verification_code)):
        sql = "update user set mail=%s where username=%s"
        para = [new_mail, name]
        is_success = conn.iur(sql, para)
        conn.close()
        if (is_success):
            storage.remove(name)
            return '1'
        else:
            return '2'
    else:
        return '2'
def change_inside_password_op(name, old_password, new_password):
    conn = opsql.Database()
    sql = "select username from user where username=%s and password=%s"
    para = [name, old_password]
    result = [i for i in conn.select(sql, para)]
    if not result:
        return '2'
    sql2 = "update user set password=%s where username=%s"
    para2 = [new_password, name]
    is_success = conn.iur(sql2, para2)
    conn.close()
    if (is_success):
        return '1'
    else:
        return '2'
Exemple #10
0
def register_op(name, mail):
    conn = opsql.Database()
    name_sql = "select username from user where username=%s"
    name_para = [name]
    name_result = [i for i in conn.select(name_sql, name_para)]
    if name_result != []:
        return '2'
    mail_sql = "select username from user where mail=%s"
    mail_para = [mail]
    mail_result = [i for i in conn.select(mail_sql, mail_para)]
    conn.close()
    if mail_result != []:
        return '3'
    email = ope.Email()
    if (email.send_email(name, mail)):
        return '1'
    else:
        return '4'
def file_upload_op(name, filename, content):
    conn = opsql.Database()
    sql = "select file_id from file where username=%s and filename=%s"
    para = [name, filename]
    result = [i for i in conn.select(sql, para)]
    print(name)
    print(filename)
    print(content)
    if result == []:

        insert_sql = 'insert into file (filename,username,content) values (%s,%s,%s)'
        insert_para = [filename, name, content]
        is_success = conn.iur(insert_sql, insert_para)
        conn.close()
        return '1' if is_success else '2'
    else:
        update_sql = 'update file set content=%s where file_id=%s'
        update_para = [content, result[0][0]]
        is_success = conn.iur(update_sql, update_para)
        conn.close()
        return '1' if is_success else '2'