示例#1
0
def isMailExisted(mail):
    sql = "select mail from users where mail='%s'" % mail
    result = getdb().execute(sql).fetchall()
    if (0 == len(result)):
        return False
    else:
        return True
示例#2
0
def check_valid(mail):
    sql = "select valid from users where mail='%s'" % mail
    result = getdb().execute(sql).fetchone()
    if result is None:
        return False
    else:
        return True
示例#3
0
def isNameExisted(name):
    sql = "select name from users where name='%s'" % name
    result = getdb().execute(sql).fetchall()
    if (0 == len(result)):
        return False
    else:
        return True
示例#4
0
def db_change_password(new_password, mail):
    sql = "update users set password = new_password where mail = '%s'" % mail
    try:
        getdb().execute(sql)
        getdb().commit()
    except:
        getdb().rollback()
示例#5
0
def check_activate_token(token):
    s = Serializer(current_app.config['SECRET_KEY'])
    try:
        data = s.loads(token)
    except:
        return False
    sql = "select mail from users where mail= '%s'" % data.get('mail')
    result = getdb().execute(sql).fetchone()
    if not result:
        flash('用户不存在')
        return False
    sql2 = "select valid from users where mail='%s'" % data.get('mail')
    result2 = getdb().execute(sql2).fetchone()
    valid = result2[0]
    if not valid:  # 账户没有激活
        flash('用户不存在')
        sql3 = "update users set valid=1 where mail='%s' " % data.get('mail')
        try:
            getdb().execute(sql3)
            getdb().commit()
            getdb().close()
        except:
            getdb().rollback()
    return True
示例#6
0
def check_reset_token(token):
    s = Serializer(current_app.config['SECRET_KEY'])
    try:
        data = s.loads(token)
    except:
        return False
    sql = "update users set password = '******' where mail = '%s'" % (
        data.password, data.mail)
    try:
        getdb().execute(sql)
        getdb().commit()
    except:
        getdb().rollback()
    return True
示例#7
0
def addUser(name, mail, password_hash):
    sql = "insert into users (name, mail, password, valid, rank_times, rank) values ('%s', '%s', '%s',0 ,0 ,0)" % (
        name, mail, password_hash)
    getdb().execute(sql)
    getdb().commit()
示例#8
0
def verify_password(password, mail):
    sql = "select password from users where mail = '%s' " % mail
    password_hash = getdb().execute(sql).fetchone()
    return check_password_hash(password_hash[0], password)
示例#9
0
def load_user(user_id):
    sql = "select name, mail, password, valid , rank , rank_times from users where mail = '%s' " % str(
        user_id)
    result = getdb().execute(sql).fetchone()
    u = User(result[0], result[1], result[2], result[3], result[4], result[5])
    return u
示例#10
0
def get_nv(mail):
    sql = "select name, valid ,rank ,rank_times from users where mail = '%s'" % mail
    result = getdb().execute(sql).fetchone()
    return result