Пример #1
0
def addTopic(request):
    '''
  this function add a new topic with form post data "newTopic"
  '''
    currentUser = getCurrentUser(request)
    if currentUser:
        user = User(login=currentUser.login)
        user = user.findByLogin()

        if request.POST['newTopic']:
            inputTopicStr = smart_unicode(request.POST["newTopic"],
                                          encoding='utf-8',
                                          strings_only=False,
                                          errors='strict')
            inputArray = inputTopicStr.split(' ')
            for newTopic in inputArray:
                print "add Topic:" + newTopic
                topics = user.topics
                if not (newTopic.lower() in (topic.lower()
                                             for topic in topics)):
                    if newTopic is not '':
                        user.topics.append(newTopic.lower())
                        user.update()
                        print "result: " + str(user.topics)
    return HttpResponseRedirect('/user/')
Пример #2
0
def view(request, login):
    #TODO distinguish those case: the user see his page, the user see another page
    #And : Distinguish GET/POST method (need to split in different method)
    context = RequestContext(request)
    context = userauth.checkSession(request, context)
    currentUser = userauth.getCurrentUser(context)
    context['currentUser'] = currentUser
    if currentUser and currentUser.login == login:
        print currentUser.login
        context['isAdmin'] = True
        imageForm = ImageUploadForm()
        context['form'] = imageForm
    else:
        context['isAdmin'] = False
    user = User(login=login)
    user = user.findByLogin()
    if user is None:
        print "not found"
        return userNotFound(request)
    if not user.picture:
        user.picture = 'default.png'
    if user.picture is None:
        user.picture = 'default.png'

    context["user"] = user
    t = loader.get_template('profile.html')
    return HttpResponse(t.render(context))
Пример #3
0
def view(request, login) :
  #TODO distinguish those case: the user see his page, the user see another page
  #And : Distinguish GET/POST method (need to split in different method)
  context = RequestContext(request)
  context = userauth.checkSession(request, context)
  currentUser = userauth.getCurrentUser(context)
  context['currentUser']=currentUser
  if currentUser and currentUser.login == login:
    print currentUser.login
    context['isAdmin'] = True
    imageForm = ImageUploadForm()
    context['form'] = imageForm
  else :
    context['isAdmin'] =False
  user = User(login=login)
  user = user.findByLogin()
  if user is None :
    print "not found"
    return userNotFound(request)
  if not user.picture:
    user.picture='default.png'
  if user.picture is None:
    user.picture='default.png'

  context["user"] = user  
  t = loader.get_template('profile.html')
  return HttpResponse(t.render(context))
Пример #4
0
def getUserInfoWrapper (user) :
  '''
  This function return a Wrapper from a user contain
  '''
  uiw=User()
  uiw.id=user.id
  uiw.login=user.login
  uiw.resume=user.resume
  return uiw
Пример #5
0
def getUserInfoWrapper(user):
    """
  This function return a Wrapper from a user contain
  """
    uiw = User()
    uiw.id = user.id
    uiw.login = user.login
    uiw.resume = user.resume
    return uiw
Пример #6
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
Пример #7
0
def processFormInformation(login,password,email,request) :
  u = User(login=login,email=email,password=password)
  u=u.create()
  print u
  if u != None :
    code=sendActivationMail(login,email)
    u.activationCode=code
    u.update()
    message= 'account succesfully created'
  else :
    message= 'error: login name already taken'
  context={'message': message}
  return render_to_response('index.html', context ,context_instance=RequestContext(request))
Пример #8
0
def activate(request, code) :
  user = User(activationCode=code)
  user = user.findByActivationCode()
  if user != None:
    if user.isActivated == False :
      user.isActivated = True
      user.update()
      message = 'your account have been successfully activated'
      return HttpResponse('your account have been successfully activated')
    else :
      return HttpResponse('this account have already been activated')
  else :
    return HttpResponse('wrong activation link')
Пример #9
0
    def testBasicPersistence(self):
        switchToTestDatabase()
        u = User(login='******')
        u.create()
        u = u.findByLogin()
        id = u.id
        print id

        q = Question(asker=id, content="To be or not to be?")
        #print "before persistence: ",q
        print q.content
        question = q.create()
        deleteTestDatabase()
Пример #10
0
 def testBasicPersistence(self):
   switchToTestDatabase()  
   u=User(login='******')
   u.create()
   u=u.findByLogin()
   id=u.id
   print id
   
   q=Question(asker=id,content="To be or not to be?")
   #print "before persistence: ",q
   print q.content
   question=q.create()
   deleteTestDatabase()
Пример #11
0
def activate(request,code) :
  user=User(activationCode=code)
  user=user.findByActivationCode()
  if user != None:
    if user.isActivated == False :
      user.isActivated= True
      user.update()
      message = 'your account have been succesfully activated'
    else :
      message = 'this account have been already activated'
  else :
    message = 'wrong activation link'
  context={'message': message}
  return render_to_response('index.html', context ,context_instance=RequestContext(request))
Пример #12
0
def updateResume(request):
  '''
  this function updates user resume with form post data "newResume"
  '''
  currentUser = getCurrentUser(request)
  if currentUser:
    user = User(login=currentUser.login)
    user = user.findByLogin()
    newResume = smart_unicode(request.POST["newResume"], encoding='utf-8', strings_only=False, errors='strict')
    #newResume = request.POST['newResume'].decode('UTF-8')
    if newResume:
      user.resume = newResume
      user.update()
  return HttpResponseRedirect('/user/')
Пример #13
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}))
Пример #14
0
def pictureUpload(request):
  if request.method == 'POST':
    form = ImageUploadForm(request.POST, request.FILES)
    if form.is_valid():
      currentUser = getCurrentUser(request)
      if currentUser:
        path = "profile/"+currentUser.login+strftime("(%Y-%m-%d_%H.%M.%S)", gmtime())+".jpg"
        destination = open(STATIC_MEDIA_ROOT+"/"+path, 'wb+')
        for chunk in request.FILES['picture'].chunks():
          destination.write(chunk)
        destination.close()
        user = User(login=currentUser.login)
        user = user.findByLogin()
        user.picture=path
        user.update()
  
  return HttpResponseRedirect('/user/')
Пример #15
0
def signin(request) :
  login=request.POST['login']
  password=request.POST['password']
  user=User(login=login)
  user=user.findByLogin()
  password=encode(password)
  if login=='' or password=='' :
    message='Please enter a login and a password'
  elif not user :
    message = 'This account does not exist'
  elif not user.isActivated :
    message= 'This account has not been activated yet'
  elif not user.password == password :
    message= 'wrong login/password combination'
  else : #every thing went fine, the session can be open
    return openSession(request,user)
  #return a response in case an error occurred
  return render_to_response('index.html', {'message': message},context_instance=RequestContext(request))
Пример #16
0
def signin(request) :
  login=request.POST['login']
  password=request.POST['password']
  user=User(login=login)
  user=user.findByLogin()
  password=encode(password)
  if login=='' or password=='' :
    message='Please enter a login and a password'
  elif not user :
    message = 'This account does not exist'
  elif not user.isActivated :
    message= 'This account has not been activated yet'
  elif not user.password == password :
    message= 'wrong login/password combination'
  else : #every thing went fine, the session can be open
    return openSession(request,user)
  #return a response in case an error occurred
  return render_to_response('index.html', {'message': message},context_instance=RequestContext(request))
Пример #17
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}))
Пример #18
0
def createUser(userName):
  u = User(login=userName,email='*****@*****.**',password=encode('123123'))
  u = u.create()
  u.isActivated=True
  
  #allocate ramdom profile image
  number=random.randrange(1, 30)
  u.picture='profile/'+str(number)+'.jpg'
  u.update()
Пример #19
0
def addTopic(request):
  '''
  this function add a new topic with form post data "newTopic"
  '''
  currentUser = getCurrentUser(request)
  if currentUser:
    user = User(login=currentUser.login)
    user = user.findByLogin()
    
    if request.POST['newTopic']:
      newTopic = smart_unicode(request.POST["newTopic"], encoding='utf-8', strings_only=False, errors='strict')
      #newTopic = request.POST['newTopic'].decode('UTF-8')
      print "add Topic:"+newTopic
      topics = user.topics
      if not (newTopic.lower() in (topic.lower() for topic in topics)):
        
        user.topics.append(newTopic)
        user.update()
        print "result: "+str(user.topics)
  return HttpResponseRedirect('/user/')
Пример #20
0
def processFormInformation(login, password, email, request) :
  activationCode = hashlib.sha1(login+email+password).hexdigest()
  u = User(name=login, email=email, password_sha=password, activationCode=activationCode)
  print u
  u = u.create()
  print u
  if u != None :
    sendActivationMail(email=email, activationCode=activationCode)
    
    response=HttpResponse()
    response.status_code=200
    response['message'] = 'account successfully created'
    return response
  else :
    message = 'error: login name already taken'
    context={"message" :  "login name already taken"}
    response=HttpResponse()
    response['message'] = 'login already taken'
    response.status_code=412
    return response
Пример #21
0
def deleteTopic(request):
  '''
  this function delete a topic with form post data "deleteTopic"
  '''
  currentUser = getCurrentUser(request)
  if currentUser:
    user = User(login=currentUser.login)
    user = user.findByLogin()
    
    
    if request.POST['deleteTopic']:
      deleteTopic = request.POST['deleteTopic']
      #deleteTopic = smart_unicode(request.POST["deleteTopic"], encoding='utf-8', strings_only=False, errors='strict')
      print "del Topic:"+deleteTopic
      topics = user.topics
      user.topics = [topic for topic in topics if deleteTopic.lower() != topic.lower()]
        #if deleteTopic.lower() == topic.lower():
        #  print topics
        #  print topic
      user.update()
      print "result: "+str(user.topics)
  return HttpResponseRedirect('/user/') 
Пример #22
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
Пример #23
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
Пример #24
0
def processFormInformation(login, password, email, request):
    activationCode = hashlib.sha1(login + email + password).hexdigest()
    u = User(name=login,
             email=email,
             password_sha=password,
             activationCode=activationCode)
    print u
    u = u.create()
    print u
    if u != None:
        sendActivationMail(email=email, activationCode=activationCode)

        response = HttpResponse()
        response.status_code = 200
        response[
            'message'] = 'account successfully created, you will received your activation mail soon'
        return response
    else:
        message = 'error: login name already taken'
        context = {"message": "login name already taken"}
        response = HttpResponse()
        response['message'] = 'login already taken'
        response.status_code = 412
        return response
Пример #25
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
Пример #26
0
def createInitialUserList():
  username = ''
  profileImgCount = 1
  f = open('/Users/macuser/Kuestions/kuestionsWS/userlist')
  for line in f:
    username = line.replace('\n', '')
    u = User(login=username,email='*****@*****.**',password=encode('123123'))
    u = u.create()
    u.isActivated=True
    
    #allocate ramdom profile image
    u.picture='profile/'+str(profileImgCount)+'.jpg'
    profileImgCount = profileImgCount + 1
    u.update()
  
  f.close()
Пример #27
0
def activate(request, code):
    user = User(activationCode=code)
    user = user.findByActivationCode()
    if user != None:
        if user.isActivated == False:
            user.isActivated = True
            user.update()
            message = 'your account have been successfully activated'
            return HttpResponse(
                'your account have been successfully activated')
        else:
            return HttpResponse('this account have already been activated')
    else:
        return HttpResponse('wrong activation link')
Пример #28
0
def processFormInformation(login, password, email, request):
    u = User(login=login, email=email, password=password)
    u = u.create()
    print u
    if u != None:
        code = sendActivationMail(login, email)
        u.activationCode = code
        u.update()
        message = 'account successfully created, you are going to receive your activation mail soon'
    else:
        message = 'error: login name already taken'
    context = {'message': message}
    return render_to_response('index.html',
                              context,
                              context_instance=RequestContext(request))
Пример #29
0
def activate(request, code):
    user = User(activationCode=code)
    user = user.findByActivationCode()
    if user != None:
        if user.isActivated == False:
            user.isActivated = True
            user.update()
            message = 'your account have been succesfully activated'
        else:
            message = 'this account have been already activated'
    else:
        message = 'wrong activation link'
    context = {'message': message}
    return render_to_response('index.html',
                              context,
                              context_instance=RequestContext(request))
Пример #30
0
def updateResume(request):
    '''
  this function updates user resume with form post data "newResume"
  '''
    currentUser = getCurrentUser(request)
    if currentUser:
        user = User(login=currentUser.login)
        user = user.findByLogin()
        newResume = smart_unicode(request.POST["newResume"],
                                  encoding='utf-8',
                                  strings_only=False,
                                  errors='strict')
        #newResume = request.POST['newResume'].decode('UTF-8')
        if newResume:
            user.resume = newResume
            user.update()
    return HttpResponseRedirect('/user/')
Пример #31
0
def pictureUpload(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            currentUser = getCurrentUser(request)
            if currentUser:
                path = "profile/" + currentUser.login + strftime(
                    "(%Y-%m-%d_%H.%M.%S)", gmtime()) + ".jpg"
                destination = open(STATIC_MEDIA_ROOT + "/" + path, 'wb+')
                for chunk in request.FILES['picture'].chunks():
                    destination.write(chunk)
                destination.close()
                user = User(login=currentUser.login)
                user = user.findByLogin()
                user.picture = path
                user.update()

    return HttpResponseRedirect('/user/')
Пример #32
0
def deleteTopic(request):
    '''
  this function delete a topic with form post data "deleteTopic"
  '''
    currentUser = getCurrentUser(request)
    if currentUser:
        user = User(login=currentUser.login)
        user = user.findByLogin()

        if request.POST['deleteTopic']:
            deleteTopic = request.POST['deleteTopic']
            #deleteTopic = smart_unicode(request.POST["deleteTopic"], encoding='utf-8', strings_only=False, errors='strict')
            print "del Topic:" + deleteTopic
            topics = user.topics
            user.topics = [
                topic for topic in topics
                if deleteTopic.lower() != topic.lower()
            ]
            #if deleteTopic.lower() == topic.lower():
            #  print topics
            #  print topic
            user.update()
            print "result: " + str(user.topics)
    return HttpResponseRedirect('/user/')
Пример #33
0
def userPicture(request, login):
    user = User(login=login)
    user = user.findByLogin()
    if not user:
        return HttpResponseRedirect('/kuestions/media/profile.png')
    return HttpResponseRedirect('/kuestions/media/' + user.picture)
Пример #34
0
def userPicture(request, login):
    user = User(login=login)
    user = user.findByLogin()
    if not user:
        return HttpResponse('No User', mimetype="image/jpg")
    return HttpResponseRedirect('/kuestions/media/' + user.picture)
Пример #35
0
def userPicture(request, login):
  user=User(login=login)
  user=user.findByLogin()
  if not user:
    return HttpResponseRedirect('/kuestions/media/profile.png')
  return HttpResponseRedirect('/kuestions/media/'+user.picture)
Пример #36
0
def userPicture(request, login):
  user=User(login=login)
  user=user.findByLogin()
  if not user:
    return HttpResponse('No User',mimetype="image/jpg")  
  return HttpResponseRedirect('/kuestions/media/'+user.picture)