def POST(self): data = web.input() email = data.forgotEmail timestamp = time.mktime(time.localtime()) prev_timestamp = users.get_last_timestamp(email) g = timestamp - prev_timestamp if users.is_email_available(email): return '{"info":"此邮箱尚未注册过","status":"n"}' elif g < 3600: return '{"info":"太频繁了","status":"n"}' else: all = list( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ' ) token = '' for i in range(32): index = random.randint(0, len(all) - 1) token = token + all[index] #生成32位随机数 -> token #token = ''.join([str(random.randint(0, 9)) for i in range(32)]) tm = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) #格式化时间戳 users.passwordForgot(email, token, timestamp) #传递email到model,将取密码的记录存到库中 user = users.get_user_by_email(email) ua = web.ctx.env.get('HTTP_USER_AGENT') ip = web.ctx.ip email_templates.forgot(user, token, ua, ip, tm) return '{"info":"找回密码邮件已发送,请检查邮箱","status":"y"}'
def POST(self): data = web.input() email = data.forgotEmail timestamp = time.mktime(time.localtime()) prev_timestamp = users.get_last_timestamp(email) g = timestamp - prev_timestamp if users.is_email_available(email): return '{"info":"此邮箱尚未注册过","status":"n"}' elif g < 3600: return '{"info":"太频繁了","status":"n"}' else: all = list('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ') token = '' for i in range(32): index = random.randint(0,len(all)-1) token = token + all[index] #生成32位随机数 -> token #token = ''.join([str(random.randint(0, 9)) for i in range(32)]) tm = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) #格式化时间戳 users.passwordForgot(email, token, timestamp) #传递email到model,将取密码的记录存到库中 user = users.get_user_by_email(email) ua = web.ctx.env.get('HTTP_USER_AGENT') ip = web.ctx.ip email_templates.forgot(user, token, ua, ip, tm) return '{"info":"找回密码邮件已发送,请检查邮箱","status":"y"}'
def POST(self): f = self.form() show = web.input(show='all').show timestamp = time.mktime(time.localtime()) #时间戳 if not f.validates(web.input(_unicode=False)): return render_account(show, forgot_password_form=f) prev_timestamp = users.get_last_timestamp(f.d.email) g = timestamp - prev_timestamp if not (p.search(f.d.email)): return render_account( show='forgot_password_only', error_message= '<span class="alert alert-error">你输入的电子邮件地址不符合规则</span>') elif not users.is_email_exist(f.d.email): return render_account( show='forgot_password_only', error_message='<span class="alert alert-error">邮箱地址不存在</span>') elif g < 3600: return render_account( show='forgot_password_only', error_message= '<span class="alert alert-error">次数太频繁我会受不了,请1小时之后再来。</span>') else: all = list( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ' ) token = '' for i in range(32): index = random.randint(0, len(all) - 1) token = token + all[index] #生成32位随机数 -> token #token = ''.join([str(random.randint(0, 9)) for i in range(32)]) tm = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) #格式化时间戳 users.passwordForgot(f.d.email, token, timestamp) #传递email到model,将取密码的记录存到库中 user = users.get_user_by_email(f.d.email) ua = web.ctx.env.get('HTTP_USER_AGENT') ip = web.ctx.ip email_templates.forgot(user, token, ua, ip, tm) return render_account(show='reset_password_success', on_success_message='邮件已发送,请查收您的邮箱.')
def POST(self): f = self.form() show = web.input(show='all').show timestamp = time.mktime(time.localtime())#时间戳 if not f.validates(web.input(_unicode=False)): return render_account(show, forgot_password_form=f) prev_timestamp = users.get_last_timestamp(f.d.email) g = timestamp - prev_timestamp if not (p.search(f.d.email)): return render_account( show='forgot_password_only', error_message='<span class="alert alert-error">你输入的电子邮件地址不符合规则</span>' ) elif not users.is_email_exist(f.d.email): return render_account( show='forgot_password_only', error_message='<span class="alert alert-error">邮箱地址不存在</span>' ) elif g < 3600: return render_account( show='forgot_password_only', error_message='<span class="alert alert-error">次数太频繁我会受不了,请1小时之后再来。</span>' ) else: all = list('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ') token = '' for i in range(32): index = random.randint(0,len(all)-1) token = token + all[index] #生成32位随机数 -> token #token = ''.join([str(random.randint(0, 9)) for i in range(32)]) tm = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) #格式化时间戳 users.passwordForgot(f.d.email, token, timestamp) #传递email到model,将取密码的记录存到库中 user = users.get_user_by_email(f.d.email) ua = web.ctx.env.get('HTTP_USER_AGENT') ip = web.ctx.ip email_templates.forgot(user, token, ua, ip, tm) return render_account( show='reset_password_success', on_success_message='邮件已发送,请查收您的邮箱.' )