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
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
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
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()
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
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
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()
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)
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
def get_nv(mail): sql = "select name, valid ,rank ,rank_times from users where mail = '%s'" % mail result = getdb().execute(sql).fetchone() return result