예제 #1
0
def api_info(request):
  try:
    user = _validate_and_get_geniuser(request)
  except LoggedInButFailedGetGeniUserError:
    return _show_failed_get_geniuser_page(request)
  
  if request.method == 'GET':
    return direct_to_template(request, 'control/api_info.html',
                              {'username' : user.username,
                               'api_key' : user.api_key,
                               'msg' : ""})

  # This is a POST, so it should be generation of an API key.
  if not request.POST.get('generate_api_key', False):
    msg = "Sorry, we didn't understand your request."
    return profile(request, info, msg) 
    #direct_to_template(request, 'control/api_info.html',
    #                          {'username' : user.username,
    #                           'api_key' : user.api_key,
    #                           'msg' : msg})
    
  interface.regenerate_api_key(user)
  msg = "Your API key has been regenerated. Your old one will no longer work."
  msg += " You should update any places you are using the API key"
  msg += " (e.g. in programs using the XML-RPC client)."
  return profile(request,msg)
예제 #2
0
 def regenerate_api_key(pwauth):
   """
   <Purpose>
     Regenerate a user's API key.This requires authenticating with the account
     password rather than the current API key.
   <Arguments>
     pwauth
       An authorization dict that includes a password instead of an apikey.
   <Exceptions>
     None.
   <Returns>
     The new API key.
   """
   geni_user = _pwauth(pwauth)
   return interface.regenerate_api_key(geni_user)