Example #1
0
def search( request ):
  ident = SessionManager( request.session ).check_cookie()

  if len( ident ) != 2:
    return HttpResponseRedirect( '/' )
 
  checker = TalentHelper.get_empty_val_checker( request.GET )
  if not checker( 'type' ) or not checker ( 'key' ):
       result = TalentUser.objects.all()
       return render_to_response( 'search/index.htm', { 'all_search_result' : result, 'total_qualified':len(result) } )
  
  else:
       search_type = request.GET[ 'type' ]
       search_key  = request.GET[ 'key' ]
       
       if ( search_type == 'project' ):
         result = Project.objects.filter( description__icontains=search_key )
       if ( search_type == 'skill' ):
         result = Skill.objects.filter( skill__icontains=search_key )
       if ( search_type == 'certification' ):
         result = Certification.objects.filter( cert_name__icontains=search_key )
       
       users = []
       for re in result:
         users.append(re.username)
       
       return render_to_response( 'search/index.htm', { 'all_search_result' : users, 'total_qualified':len(users) } )
Example #2
0
def signin( request):
  checker = TalentHelper.get_empty_val_checker( request.POST )
  if checker( 'name' ) and checker( 'pass' ):
    username = request.POST[ 'name' ]
    password = request.POST[ 'pass' ]
  else:
    return HttpResponseRedirect( \
      '/error/?msg=%s' % 'Both username and password cannot be empty' )

  if TalentUser.objects.filter( username__exact = username, \
    password__exact = hashlib.sha1( password ).hexdigest() )[:1]:
    SessionManager( request.session ).set_cookie( username )
    return HttpResponseRedirect( '/search/' )
  else:
    return HttpResponseRedirect( \
      '/error/?msg=%s' % 'Invalid username or password' )
Example #3
0
def signup( request ):
  checker = TalentHelper.get_empty_val_checker( request.POST )
  if    checker( 'reg-name' ) and checker( 'reg-pass' ) \
    and checker( 'reg-title' ) and checker( 'reg-team' ):
    reg_name   = request.POST[ "reg-name"  ]
    reg_passwd = request.POST[ "reg-pass"  ]
    reg_title  = request.POST[ "reg-title" ]
    reg_team   = request.POST[ "reg-team"  ]
  else:
    return HttpResponseRedirect( \
      '/error/?msg=%s' % 'Invalid register data' )

  if TalentUser.objects.filter( username__exact = reg_name )[:1]:
    return HttpResponseRedirect( \
      '/error/?msg=%s' % 'Username has been taken' )
  TalentUser( \
    username = reg_name, \
    password = hashlib.sha1( reg_passwd ).hexdigest(), \
    title    = reg_title,
    team     = reg_team ).save()
  SessionManager( request.session ).set_cookie( reg_name )
  return HttpResponseRedirect( '/search/' )