def mindex(): info = request.get_cookie('info',secret=secret) info = response.set_cookie('info','',secret=secret) response.set_cookie('info','',secret=secret) navs = level.get_next_lvls('') newslist = [(nav,news.get_lvl_news(str(nav.id))[:7]) for nav in navs] activeimgs = tools.get_imgs('./activeimg/') activeimgs = ['/active/'+i for i in activeimgs] if request.method == 'GET': name = request.get_cookie('name',secret=secret) id = request.get_cookie('id',secret=secret) return template('tpls/mindex.tpl', name=name, id=id, info=info, navs=navs, newslist=newslist, plid='', activeimgs=activeimgs, ) elif request.method == 'POST': verify_text = request.get_cookie('verify_text',secret=secret) response.set_cookie('verify_text','',secret=secret) if verify_text and verify_text.lower() == \ request.forms.getunicode('verify_text').lower().strip(): name = request.forms.getunicode('name') password = request.forms.getunicode('password') u = user.login(name,password) if u: response.set_cookie('name',u.name,secret=secret) response.set_cookie('id',str(u.id),secret=secret) return template('tpls/mindex.tpl', name=name, id=str(u.id), info=info, navs=navs, newslist=newslist, plid='', activeimgs=activeimgs, ) else: response.set_cookie('info', "登录失败,请检查用户名或密码!", secret=secret) else: response.set_cookie('info',"验证码错误,请重新登录!", secret=secret) redirect('/')
def POST(self, **kwargs): try: email = kwargs["email"] password = kwargs["password"] except: cherrypy.response.status = 400 return try: user, profile = db.user.User.register(email, password) token = user.login(password) return dict(success=True, message="Registration successful.", token=token, profile_id=profile.id) except db.user.UserExistsError: return dict(success=False, message="E-mail already exists.")
def GET(self, **kwargs): try: email = kwargs["email"] password = kwargs["password"] except: cherrypy.response.status = 400 return user = db.user.User.find(email=email) if not user: return dict(success=False, message="Incorrect e-mail and password combination.") token = user.login(password) if not token: return dict(success=False, message="Incorrect e-mail and password combination.") return dict(success=True, token=token, message="Login successful.")
def mindex(plid=''): info = request.get_cookie('info',secret=secret) info = response.set_cookie('info','',secret=secret) response.set_cookie('info','',secret=secret) navs = level.get_next_lvls(plid) navs = navs if navs else [level.get_lvl(plid)] newslist = [(nav,news.get_lvl_news(str(nav.id))) for nav in navs] if request.method == 'GET': name = request.get_cookie('name',secret=secret) id = request.get_cookie('id',secret=secret) # print(name,'......',id) return template('tpls/mindex.tpl', name=name, id=id, info=info, navs=navs, newslist=newslist, plid=plid ) elif request.method == 'POST': verify_text = request.get_cookie('verify_text',secret=secret) response.set_cookie('verify_text','',secret=secret) if verify_text and verify_text.lower() == \ request.forms.getunicode('verify_text').lower().strip(): name = request.forms.getunicode('name') password = request.forms.getunicode('password') u = user.login(name,password) if u: response.set_cookie('name',u.name,secret=secret) response.set_cookie('id',str(u.id),secret=secret) return template('tpls/mindex.tpl', name=name, id=str(u.id), info=info, navs=navs, newslist=newslist, plid=plid ) else: response.set_cookie('info', "登录失败,请检查用户名或密码!", secret=secret) else: response.set_cookie('info',"验证码错误,请重新登录!", secret=secret) redirect('/')