コード例 #1
0
ファイル: views.py プロジェクト: brownplt/k3
def plt_login(request):
  if request.method != 'POST':
    return HttpResponseNotAllowed(['POST'])

  args = bcap.dataPostProcess(request.read())
  if not args.has_key('username'):
    return logWith404(logger, 'plt_login: post data missing username')
  if not args.has_key('password'):
    return logWith404(logger, 'plt_login: post data missing password')

  username = args['username']
  rawpassword = args['password']

  credentials = PltCredentials.objects.filter(username=username)
  if len(credentials) > 1:
    return logWith404(logger, 'plt_login: fatal error: duplicate credentials', level='error')

  if len(credentials) == 0:
    return bcap.bcapResponse({'loggedIn' : False})
  c = credentials[0]

  hashed_password = get_hashed(rawpassword, c.salt)
  if hashed_password != c.hashed_password:
    return bcap.bcapResponse({'loggedIn' : False})

  session_id = str(uuid.uuid4())
  session = BelaySession(session_id=session_id, account=c.account)
  session.save()

  response = {
    'station': bcap.Capability(c.account.station_url),
    'makeStash': bcap.regrant('make-stash', c.account)
  }
  return bcap.bcapResponse(response)
コード例 #2
0
ファイル: views.py プロジェクト: brownplt/k3
  def post(self, grantable, args):
    username = grantable.pendingaccount.email
    rawpassword = args['password']

    if len(username) > 200:
      return logWith404(logger, 'create_plt_account: bad username')

    if len(rawpassword) < 8:
      return logWith404(logger, 'create_plt_account: bad password')

    salt = str(uuid.uuid4())
    hashed_password = get_hashed(rawpassword, salt)

    station_cap = newStationCap()
    account = BelayAccount(station_url=station_cap.serialize())
    account.save()
    credentials = PltCredentials(username=username, \
      salt=salt, \
      hashed_password=hashed_password, \
      account=account)
    credentials.save()

    session_id = str(uuid.uuid4())

    session = BelaySession(session_id=session_id, account=account)
    session.save()

    grantable.pendingaccount.delete()

    response = {
      'station': station_cap,
      'makeStash': bcap.regrant('make-stash', account)
    }
    return bcap.bcapResponse(response)
コード例 #3
0
ファイル: views.py プロジェクト: brownplt/k3
def glogin_landing(request):
  if request.method == 'GET':
    d = request.GET
  else:
    d = request.POST
  maybe_client_key = check_pending(request.path_info)
  if not maybe_client_key:
    return logWith404(logger, "Bad pending: %s" % request.path_info, level='error')

  # 11.4.2 Verifying directly with the OpenID Provider
  # 11.4.2.1.  Request Parameters
  #   . openid.mode
  #         Value: "check_authentication"
  #   . Exact copies of all fields from the authentication response, except
  #     for "openid.mode".
  # http://openid.net/specs/openid-authentication-2_0.html#check_auth
  verify = {}
  for e in d:
    verify[e] = d[e]
  verify['openid.mode'] = 'check_authentication'

  try:
    f = urllib2.urlopen("https://www.google.com/accounts/o8/ud", urllib.urlencode(verify))
    beginning = str(f.read()[0:13]) 
    
    if(beginning != 'is_valid:true'):
      return bcap.bcapResponse('fail')
  except urllib2.HTTPError as e:
    logger.error("ErrorResponse: %s" % e.read())
    return bcap.bcapNullResponse()
    
  identity = d['openid.identity']
  email = d['openid.ext1.value.email']

  q = GoogleCredentials.objects.filter(identity=identity)
  if len(q) == 0:
    station_cap = newStationCap()
    account = BelayAccount(station_url=station_cap.serialize())
    account.save()

    gc = GoogleCredentials(account=account, identity=identity)
    gc.save()
  else:
    account = q[0].account

  session_id = str(uuid.uuid4())
  session = BelaySession(account=account, session_id=session_id)
  session.save()

  response = render_to_response('glogin.html', {
    'clientkey': maybe_client_key,
    'station': account.station_url,
    'make_stash': bcap.regrant('make-stash', account).serialize(),
    'site_name': settings.SITE_NAME,
    'email': email
  })
  return response
コード例 #4
0
ファイル: views.py プロジェクト: brownplt/k3
def create_plt_account(request):
  if request.method != 'POST':
    return HttpResponseNotAllowed(['POST'])

  args = bcap.dataPostProcess(request.read())
  if not args.has_key('username'):
    return logWith404(logger, 'create_plt_account: post data missing username')

  if not args.has_key('password'):
    return logWith404(logger, 'create_plt_account: post data missing password')

  username = args['username']
  rawpassword = args['password']

  if len(username) > 20:
    return logWith404(logger, 'create_plt_account: bad username')

  if len(rawpassword) < 8:
    return logWith404(logger, 'create_plt_account: bad password')

  salt = str(uuid.uuid4())
  hashed_password = get_hashed(rawpassword, salt)

  station_cap = newStationCap()
  account = BelayAccount(station_url=station_cap.serialize())
  account.save()
  credentials = PltCredentials(username=username, \
    salt=salt, \
    hashed_password=hashed_password, \
    account=account)
  credentials.save()

  session_id = str(uuid.uuid4())

  session = BelaySession(session_id=session_id, account=account)
  session.save()

  response = {
    'station': station_cap,
    'makeStash': bcap.regrant('make-stash', account)
  }
  return bcap.bcapResponse(response)