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 if not f.validates(web.input(_unicode=False)): return render_account(show, forgot_password_form=f) else: user = users.get_user_by_email(f.d.email) email_templates.resend_password(user) return render_account(show, on_success_message='Login information succesfully emailed.')
def POST(self): f = self.form() if not f.validates(web.input(_unicode=False)): show = web.input(show='all').show return render_account(show, login_form=f) else: session.login(f.d.email) user_info = users.get_user_by_email(f.d.email) user.douban_id = user_info.id # 普通注册用户直接把douban_id赋值为id, 方便后面一系列的对douban_id的逻辑 # raise web.seeother('/') raise web.seeother(session.get_last_visited_url())
def POST(self): f = self.form() show = web.input(show='all').show if not f.validates(web.input(_unicode=False)): return render_account(show, forgot_password_form=f) else: user = users.get_user_by_email(f.d.email) email_templates.resend_password(user) return render_account( show, on_success_message='Login information succesfully emailed.')
def POST(self): f = self.form() if not f.validates(web.input(_unicode=False)): show = web.input(show='all').show return render_account(show, register_form=f) elif len(f.d.username) > 16 : return render_account( show = 'register_only', error_message = '<span class="alert alert-error">不能超过16位</span>', register_form=f ) elif len(f.d.username) < 2 : return render_account( show = 'register_only', error_message = '<span class="alert alert-error">不能少过2位</span>', register_form=f ) elif not (re.search('^[a-zA-Z]{1}[\w\-]{5,15}$', f.d.username)): return render_account( show = 'register_only', error_message = '<span class="alert alert-error">请以字母开头,6-16个字母、数字</span>', register_form=f ) else: users.create_account(f.d.username, f.d.email, f.d.password, f.d.nickname, '/static/public/img/default_48x48.jpg') id = users.get_user_by_email(f.d.email).id users.update_user_by_id( id, douban_id=id ) if not users.is_user_exist_in__permission(id): db.insert('_permission', douban_id = id, rights = 1) if users.is_user_profile_exist(id): users.update_profile(id, city = '上海', bio = '') else: users.insert_profile(id, city = '上海', bio = '') session.login(f.d.email) user.is_logged = False # 虽然注册了, 但是还要等邮件确认 user.douban_id = id token = md5.md5(time.ctime() + f.d.email).hexdigest() try: email_templates.msg_new_user_email(user, f.d.email, token) #保存记录到数据库 users.save_confirm_email(f.d.email, user.id, token) #跳转到邮件发送成功页面 return web.seeother('/welcome/'+ f.d.username +'/send_email_feedback?status=succesful') except Exception, e: print 'error--------, send email feedback ------------------' print e return web.seeother('/welcome/'+ f.d.username +'/send_email_feedback?status=failed')
def login(email, password): s = get_session() if users.is_correct_password(email, password): s.is_logged = True user = users.get_user_by_email(email) s.username = user.get('name') s.userid = user.get('id') users.update_last_login(s.userid) logger.info('Usuario ' + s.username + ' (' + email + ')' + ' entrou no sistema!') return True else: logger.error('Usuario ' + email + ' tentou logar com a senha errada!') return False
def login(email): s = get_session() user = users.get_user_by_email(email) for k, v in user.items(): s[k] = v if user.privilege == 1: s['actions'] = [] elif user.privilege == 5: s['actions'] = [["/cumt/AddArticle", "Add Article"], ["/cumt/DelArticle", "Del Article"], ["/cumt/AlterArticle", "Alter Article"], ["/cumt/ResetUserPassword", "ResetUserPwd"], ["/cumt/UserManage", "User Management"]] s['actions'] += [["/cumt/ResetPassword", "Reset Password"], ["/cumt/Profile", "Profile"], ["/cumt/Logout", "Logout"]]
def login(email): s = get_session() user = users.get_user_by_email(email) for k, v in user.items(): s[k] = v if user.privilege == 1: s['actions'] = [] elif user.privilege == 5: s['actions']=[ ["/cumt/AddArticle","Add Article"], ["/cumt/DelArticle","Del Article"], ["/cumt/AlterArticle","Alter Article"], ["/cumt/ResetUserPassword","ResetUserPwd"], ["/cumt/UserManage","User Management"] ] s['actions'] += [["/cumt/ResetPassword","Reset Password"],["/cumt/Profile","Profile"],["/cumt/Logout","Logout"]]
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='邮件已发送,请查收您的邮箱.' )
def POST(self, token): f = self.form() show = web.input().show if not f.validates(web.input(_unicode=False)): return render_account(show='reset_password_only', reset_password_form=f, token = token) elif f.d.password != f.d.again: return render_account( show = 'reset_password_only', token = token, error_message = '<span class="alert alert-error">两次输入的密码不一致</span>' ) else: id = users.get_user_by_email(users.get_email(token)).get('id',False) users.update(id, password=hashlib.md5(f.d.password + encryption_key).hexdigest()) #更新密码 todo:是不是应该写到model里的 users.update_valid(token) #更改 valid 为 1 表示已经更改了密码 return render_account( show = 'reset_password_success', on_success_message = '密码已更新' )
def POST(self, token): f = self.form() show = web.input().show if not f.validates(web.input(_unicode=False)): return render_account(show='reset_password_only', reset_password_form=f, token=token) elif f.d.password != f.d.again: return render_account( show='reset_password_only', token=token, error_message= '<span class="alert alert-error">两次输入的密码不一致</span>') else: id = users.get_user_by_email(users.get_email(token)).get( 'id', False) users.update(id, password=hashlib.md5(f.d.password + encryption_key). hexdigest()) #更新密码 todo:是不是应该写到model里的 users.update_valid(token) #更改 valid 为 1 表示已经更改了密码 return render_account(show='reset_password_success', on_success_message='密码已更新')
def POST(self): ipt = web.input(_unicode=True) #print ipt f = self.user_search_form() myf = mww.MyForm(f,'/cumt/UserManage') if not f.validates(ipt): return "Argument Error" if len(ipt.uid)>0: if users.uid_exist_p(ipt.uid): us = [users.get_user_by_uid(ipt.uid)] else: us = [] elif len(ipt.name)>0: us = users.get_users_by_name(ipt.name) elif len(ipt.email)>0: if users.email_exist_p(ipt.email): us = [users.get_user_by_email(ipt.email)] else: us = [] elif ipt.country == 'All': us = users.get_all_users() elif ipt.country == 'China': us = users.get_users_by_country('China') elif ipt.country == 'Other': us = users.get_users_by_country_not('China') else: us = [] schema = [['uid',"Index"], ['name',"Name"], ['country',"Country"], ['email',"Email"], ['operations',"Operations"]] t = mww.Table(schema, map(user_record_trans_to_display,us), class_='table table-striped table-hover') s = mww.ListGroup(session.get_session().actions).render() l = mww.Panel('Settings',s) r = mww.Panel('User Management',myf.render_css()+t.render()) return render.l3r9(left=l.render(),right=r.render())
def POST(self): ipt = web.input(_unicode=True) #print ipt f = self.user_search_form() myf = mww.MyForm(f, '/cumt/UserManage') if not f.validates(ipt): return "Argument Error" if len(ipt.uid) > 0: if users.uid_exist_p(ipt.uid): us = [users.get_user_by_uid(ipt.uid)] else: us = [] elif len(ipt.name) > 0: us = users.get_users_by_name(ipt.name) elif len(ipt.email) > 0: if users.email_exist_p(ipt.email): us = [users.get_user_by_email(ipt.email)] else: us = [] elif ipt.country == 'All': us = users.get_all_users() elif ipt.country == 'China': us = users.get_users_by_country('China') elif ipt.country == 'Other': us = users.get_users_by_country_not('China') else: us = [] schema = [['uid', "Index"], ['name', "Name"], ['country', "Country"], ['email', "Email"], ['operations', "Operations"]] t = mww.Table(schema, map(user_record_trans_to_display, us), class_='table table-striped table-hover') s = mww.ListGroup(session.get_session().actions).render() l = mww.Panel('Settings', s) r = mww.Panel('User Management', myf.render_css() + t.render()) return render.l3r9(left=l.render(), right=r.render())
def login(email): s = get_session() for k, v in users.get_user_by_email(email).items(): s[k] = v s.is_logged = True