Пример #1
0
def signout(request) :
  sessionId=None
  if request.COOKIES.__contains__(userauth.COOKIE_KEY) :
    sessionId=request.COOKIES[userauth.COOKIE_KEY]
    user=User(sessionId=sessionId)
    user=user.findBySessionId()
    user.sessionId='XXX'+str(uuid.uuid1())
    user.update()
  response=HttpResponseRedirect('/')
  response.delete_cookie(userauth.COOKIE_KEY)
  return response
Пример #2
0
def signout(request) :
  sessionId=None
  if request.COOKIES.__contains__(userauth.COOKIE_KEY) :
    sessionId=request.COOKIES[userauth.COOKIE_KEY]
    user=User(sessionId=sessionId)
    user=user.findBySessionId()
    user.sessionId='XXX'+str(uuid.uuid1())
    user.update()
  response=HttpResponseRedirect('/')
  response.delete_cookie(userauth.COOKIE_KEY)
  return response
Пример #3
0
def session(request):
  '''
  this method allow to retrieve the current logged user information, if any,
  from the javascript
  '''
  sessionId=None
  if request.COOKIES.__contains__(userauth.COOKIE_KEY) :
    sessionId=request.COOKIES[userauth.COOKIE_KEY]
    user=User(sessionId=sessionId)
    user=user.findBySessionId()
    userW={"login":user.login,
           "followedQuestions":user.followedQuestions,
           "isOpen":True         
           }
    return HttpResponse(json.dumps(userW))
  else :
    return HttpResponse(json.dumps({"isOpen":False}))
Пример #4
0
def session(request):
    '''
  this method allow to retrieve the current logged user information, if any,
  from the javascript
  '''
    sessionId = None
    if request.COOKIES.__contains__(userauth.COOKIE_KEY):
        sessionId = request.COOKIES[userauth.COOKIE_KEY]
        user = User(sessionId=sessionId)
        user = user.findBySessionId()
        userW = {
            "login": user.login,
            "followedQuestions": user.followedQuestions,
            "topics": user.topics,
            "isOpen": True
        }
        return HttpResponse(json.dumps(userW))
    else:
        return HttpResponse(json.dumps({"isOpen": False}))
Пример #5
0
def checkSession(request, context={}):
    """
  add some information to the context for the main page, like user infor, current question, etc
  Only if the user is correctly logged in, otherwise , somme basic info will be add
  like top questions, etc
  """

    cookieValue = None
    if request.COOKIES.__contains__(COOKIE_KEY):
        cookieValue = request.COOKIES[COOKIE_KEY]
    if cookieValue:
        user = User(sessionId=cookieValue)
        user = user.findBySessionId()
        if user and checkSessionIsNotExpired(user):
            context["sessionIsOpen"] = True
            context["user"] = getUserInfoWrapper(user)
        else:
            context["sessionIsOpen"] = False
            context["user"] = None
    else:
        print "security: no cookie found"
        context["sessionIsOpen"] = False
    return context
Пример #6
0
def checkSession (request,context={}) :
  '''
  add some information to the context for the main page, like user infor, current question, etc
  Only if the user is correctly logged in, otherwise , somme basic info will be add
  like top questions, etc
  '''
  
  cookieValue=None
  if request.COOKIES.__contains__(COOKIE_KEY) : 
    cookieValue= request.COOKIES[COOKIE_KEY]
  if cookieValue :
    user=User(sessionId=cookieValue)
    user=user.findBySessionId()
    if user and checkSessionIsNotExpired(user) :
      context['sessionIsOpen']=True
      context['user']=getUserInfoWrapper(user)
    else :
      context['sessionIsOpen']=False
      context['user']=None
  else : 
    print 'security: no cookie found'
    context['sessionIsOpen']=False
  return context