def validate_username(self, username): if re.match("^[a-zA-Z0-9_]+$", username.data) == None: raise ValidationError('username has invalid charactor!') user = mysql.One("user", {"username": "******" % username.data}, ["id"]) if user != 0: raise ValidationError('Please use a different username.')
def load_user(id): msg = mysql.One("user", {"id": id}) if msg != 0 and msg != -1: user = User(id=msg[0], username=msg[1], email=msg[2], password_hash=msg[3], note=msg[4], last_seen=msg[5]) return user else: return None
def load_user_by_username(username): msg = mysql.One("user", {"username": "******" % username}) if msg != 0 and msg != -1: user = User(id=msg[0], username=msg[1], email=msg[2], password_hash=msg[3], note=msg[4], last_seen=msg[5]) return user else: return msg
def validate_email(self, email): user = mysql.One("user", {"email": "'%s'" % email.data}, ["id"]) if user != 0: raise ValidationError('Please use a different email address.')
def is_following(self, user): res = mysql.One('followers', { "followed_id": user.id, "follower_id": self.id }) return True if (res != 0 and res != 1) else False