Example #1
0
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)
Example #2
0
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)
Example #3
0
 def auth(self, raw_password):
     password = md5_hexdigest(raw_password + self.salt)
     return password == self.password
Example #4
0
 def set_password(self, raw_password):
     self._set_salt()
     self.password = md5_hexdigest(raw_password + self.salt)
Example #5
0
 def _set_salt(self):
     self.salt = md5_hexdigest()
Example #6
0
 def auth(self, raw_password):
     password = md5_hexdigest(raw_password + self.salt)
     return password == self.password
Example #7
0
 def set_password(self, raw_password):
     self._set_salt()
     self.password = md5_hexdigest(raw_password + self.salt)
Example #8
0
 def _set_salt(self):
     self.salt = md5_hexdigest()