Exemplo n.º 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/')
Exemplo n.º 2
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()
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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')
Exemplo n.º 6
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))
Exemplo n.º 7
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')
Exemplo n.º 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 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))
Exemplo n.º 9
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/')
Exemplo n.º 10
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))
Exemplo n.º 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))
Exemplo n.º 12
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()
Exemplo n.º 13
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/')
Exemplo n.º 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/')
Exemplo n.º 15
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/')
Exemplo n.º 16
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/')
Exemplo n.º 17
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/') 
Exemplo n.º 18
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/')