예제 #1
0
 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')
예제 #2
0
    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
예제 #3
0
 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)
예제 #4
0
 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'
예제 #5
0
 def handle_post(post):
     context = {'post': post}
     request.write(render_response('create.html', context))
     request.finish()
예제 #6
0
 def render_GET(self, request):
     session = request.getSession()
     if session.uid not in sessions:
         request.redirect('/login')
         return ''
     return render_response('create.html')
예제 #7
0
 def handle_posts(posts):
     context = {'posts': posts}
     request.write(render_response('posts.html', context))
     request.finish()
예제 #8
0
 def render_GET(self, request):
     request.write(render_response('login.html'))
     request.finish()
     return NOT_DONE_YET
예제 #9
0
 def render_POST(self, request):
     return render_response('nope.html')