Пример #1
0
 def save(self):
     if self.id:
         query = "UPDATE Genders SET gender = %s WHERE id = %s"
         args = (self.gender, self.id)
     else:
         query = "INSERT INTO genders (gender) VALUES (%s)"
         args = (self.gender, )
     db.query_db(query, args, fetch=False)
     self.id, self.gender = self.get_object()
     return self
Пример #2
0
 def add_gender(self, gender_name):
     gender = Gender(gender_name)
     if not gender.id:
         gender.save()
     query = "UPDATE Users SET gender_id = %s WHERE id = %s"
     res = db.query_db(query, (gender.id, self.id), fetch=False)
     self.gender = gender
Пример #3
0
 def reset_password(self):
     new_password = ''.join(
         random.choice('0123456789ABCDEF') for i in range(5))
     query = "UPDATE Users SET password = %s WHERE id = %s"
     res = db.query_db(query,
                       (hash_password(new_password), self.user['id']),
                       fetch=False)
     mail.send_password_reset(self.user['mail'], new_password)
Пример #4
0
 def new(self, datas):
     datas['password'] = hash_password(datas['password'])
     query = """INSERT INTO Users (mail, username, password, first_name, last_name) VALUES (%s, %s, %s, %s, %s)"""
     res = db.query_db(query,
                       args=(datas["email"], datas["username"],
                             datas["password"], datas["firstname"],
                             datas["lastname"]),
                       fetch=False)
     self.user = self.get_by_username(datas["username"])
     return self.user
Пример #5
0
 def user_exists(self, mail, username):
     query = "SELECT * FROM Users WHERE users.mail=%s OR users.username=%s"
     res = db.query_db(query, args=(mail, username), one=True)
     if not res: return False
     if res["mail"] == mail: return "A user with this email already exists"
     return "A user with this username already exists"
Пример #6
0
 def get_by_email(self, email):
     query = "SELECT * FROM Users WHERE users.mail=%s"
     return db.query_db(query, args=(email, ), one=True)
Пример #7
0
 def get_by_username(self, username):
     query = "SELECT * FROM Users WHERE users.username=%s"
     return db.query_db(query, args=(username, ), one=True)
Пример #8
0
 def get_by_id(self, id):
     query = "SELECT * FROM Users WHERE users.id=%s"
     return db.query_db(query, args=(id, ), one=True)
Пример #9
0
 def get_object(self):
     query = "SELECT * FROM genders WHERE gender=%s OR genders.id = %s"
     res = db.query_db(query, args=(self.name, self.id), one=True)
     if not res:
         return self.name, self.id
     return res.name, res.id