def reset_password(uid): db = m.Session() user = db.query(m.User).filter_by(id=uid).first() if user is None: logging.warning('try reset password for uid->%s but user not found' % (str(uid))) return old_request = db.query(m.Password).filter_by(uid=uid).first() if old_request is not None: db.delete(old_request) token = md5_hexdigest() password = m.Password(token=token, uid=user.id) db.add(password) template = tmp_env.get_template('email/reset_password.txt') subject = 'reset password token' content = template.render(username=user.name, token=token).encode('utf8') to_addr = user.email try: db.commit() except: db.rollback() raise finally: db.close() send_notice(subject, content, to_addr)
def reset_password(uid): db = m.Session() user = db.query(m.User).filter_by(id=uid).first() if user is None: logging.warning('try reset password for uid->%s but user not found' %(str(uid))) return old_request = db.query(m.Password).filter_by(uid=uid).first() if old_request is not None: db.delete(old_request) token = md5_hexdigest() password = m.Password(token=token, uid=user.id) db.add(password) template = tmp_env.get_template('email/reset_password.txt') subject = 'reset password token' content = template.render(username=user.name, token = token).encode('utf8') to_addr = user.email try: db.commit() except: db.rollback() raise finally: db.close() send_notice(subject, content, to_addr)
def auth(self, raw_password): password = md5_hexdigest(raw_password + self.salt) return password == self.password
def set_password(self, raw_password): self._set_salt() self.password = md5_hexdigest(raw_password + self.salt)
def _set_salt(self): self.salt = md5_hexdigest()