def render_GET(self, request): session = request.getSession() if session.uid in sessions: context = {'key': "You're already registered!"} request.write(render_response('sorry.html', context)) request.finish() return NOT_DONE_YET return render_response('signup.html')
def render_POST(self, request): dusername = cgi.escape(request.args['username'][0]) dpassword = cgi.escape(request.args['password'][0]) dpassword2 = cgi.escape(request.args['passwordconfirm'][0]) if dpassword != dpassword2: context = {'key': 'Your passwords did not match!'} request.write(render_response('sorry.html', context)) request.finish() return NOT_DONE_YET d = _db.users.find_one({'username': dusername}) def verify_user(user): if user: context = {'key': 'That username already exists!'} request.write(render_response('sorry.html', context)) request.finish() else: salt = bcrypt.gensalt() dhashword = bcrypt.hashpw(dpassword, salt) userinfo = {'username': dusername, 'password': dhashword} return _db.users.insert(userinfo) d.addCallback(verify_user) def user_created(_): request.redirect('/login') request.finish() d.addCallback(user_created) return NOT_DONE_YET
def verify_user(user): if user: context = {'key': 'That username already exists!'} request.write(render_response('sorry.html', context)) request.finish() else: salt = bcrypt.gensalt() dhashword = bcrypt.hashpw(dpassword, salt) userinfo = {'username': dusername, 'password': dhashword} return _db.users.insert(userinfo)
def user_found(user): if not user: context = {'key': "You're " 'not a user! Would you like to ' '<a href="/register">register</a>?'} request.write(render_response('sorry.html', context)) request.finish() return 'not user' if bcrypt.hashpw(password, user['password']) == user['password']: session = request.getSession() if session.uid not in sessions: sessions.add(session.uid) request.redirect('/admin') request.finish() return 'password correct' else: context = {'key': 'Incorrect password!'} request.write(render_response('sorry.html', context)) request.finish() return 'password incorrect'
def handle_post(post): context = {'post': post} request.write(render_response('create.html', context)) request.finish()
def render_GET(self, request): session = request.getSession() if session.uid not in sessions: request.redirect('/login') return '' return render_response('create.html')
def handle_posts(posts): context = {'posts': posts} request.write(render_response('posts.html', context)) request.finish()
def render_GET(self, request): request.write(render_response('login.html')) request.finish() return NOT_DONE_YET
def render_POST(self, request): return render_response('nope.html')