Пример #1
0
    def forget_password(self, *args, **kw):
        try:
            email_address = kw['email_address']
            user=DBSession.query(User).filter_by(email_address=email_address).first()
            if not user:
                return dict(success=False, error_code=ErrorCode.NONEXISTEDUSER)
                                                
            log.info("Reset password: %s"%email_address)
            reset_pwd = ResetPassword()
            reset_pwd.email_address=email_address
            reset_pwd.code = Registration.generate_code(email_address)
            
            DBSession.add(reset_pwd)
            DBSession.flush()
            
            email_data = {'sender':config['registration.email_sender'],
                      'subject':_('Message from Jminee'),
                      'body':'''
Please click on this link to reset your password

%s
''' % (url_for(self.mount_point+'/confirm_reset', code=reset_pwd.code, email=reset_pwd.email_address, qualified=True))}

        
            send_email(reset_pwd.email_address, email_data['sender'], email_data['subject'], email_data['body'])
        except Exception as e:
            log.exception('Got exception')
            return dict(success=False)
        return dict(success=True)
Пример #2
0
 def reset_password(self, *agrs, **kw):
     try:
         log.info('User reset password: %s'%str(kw))
         ResetPassword.clear_expired_user(kw['email_address'])
         reset = ResetPassword.get_inactive(kw['email_address'], kw['code'])
         if not reset:
             return dict(success=False, error_code=ErrorCode.NORESETRECORD)
         
         user=DBSession.query(User).filter_by(email_address=kw['email_address']).first()
         user.password = kw['password']
         
         reset.email = kw['email_address'] 
         reset.reset = datetime.now()
     
         DBSession.flush()
         return dict(success=True)
     except Exception as e:
         log.exception('Got exception')
         return dict(success=False, error_code=ErrorCode.OTHERS)