def password_email(user):
 from r2.lib.pages import PasswordReset
 user_reset_ratelimit = SimpleRateLimit(name=('email_reset_count_%s' % user._id36), seconds=int(datetime.timedelta(hours=12).total_seconds()), limit=3)
 if (not user_reset_ratelimit.record_and_check()):
  return False
 global_reset_ratelimit = SimpleRateLimit(name='email_reset_count_global', seconds=int(datetime.timedelta(hours=1).total_seconds()), limit=1000)
 if (not global_reset_ratelimit.record_and_check()):
  raise ValueError('password reset ratelimit exceeded')
 token = PasswordResetToken._new(user)
 base = (g.https_endpoint or g.origin)
 passlink = ((base + '/resetpassword/') + token._id)
 g.log.info(('Generated password reset link: ' + passlink))
 _system_email(user.email, PasswordReset(user=user, passlink=passlink).render(style='email'), Email.Kind.RESET_PASSWORD, user=user)
 return True

def password_email ( user ) : from r2 . lib . pages import PasswordReset user_reset_ratelimit = SimpleRateLimit ( name = ( 'email_reset_count_%s' % user . _id36 ) , seconds = int ( datetime . timedelta ( hours = 12 ) . total_seconds ( ) ) , limit = 3 ) if ( not user_reset_ratelimit . record_and_check ( ) ) : return False global_reset_ratelimit = SimpleRateLimit ( name = 'email_reset_count_global' , seconds = int ( datetime . timedelta ( hours = 1 ) . total_seconds ( ) ) , limit = 1000 ) if ( not global_reset_ratelimit . record_and_check ( ) ) : raise ValueError ( 'password reset ratelimit exceeded' ) token = PasswordResetToken . _new ( user ) base = ( g . https_endpoint or g . origin ) passlink = ( ( base + '/resetpassword/' ) + token . _id ) g . log . info ( ( 'Generated password reset link: ' + passlink ) ) _system_email ( user . email , PasswordReset ( user = user , passlink = passlink ) . render ( style = 'email' ) , Email . Kind . RESET_PASSWORD , user = user ) return True
for resetting a users password .