Beispiel #1
0
  def post(self):
    isLocal = os.environ['SERVER_SOFTWARE'].startswith('Dev')
    if not isLocal:
      return
    api_key = self.request.get('apikey')
    account_id = self.request.get('accountid')
    badge_id = self.request.get('badgeid')
    badge_theme = self.request.get('theme')
    user_id = self.request.get('user')
    if not badge_theme or not badge_id or not account_id or not api_key:
      ret = bad_args()
      self.response.out.write(ret)
      return

    user_key = users_dao.get_user_key(account_id, user_id)
    user_ref = users_dao.get_user(account_id, user_id)
    if user_ref:
      badge_instances = badges_dao.get_user_badges(user_ref)
      for b in badge_instances:
        badges_dao.delete_badge_instance(b.key().name())
      users_dao.delete_user(user_key)

    trophy_case_widget = TrophyCase(key_name=account_id)
    points_widget = Points(key_name=account_id)
    rank_widget = Rank(key_name=account_id)
    notifier_widget = Notifier(key_name=account_id)
    leader_widget = Leaderboard(key_name=account_id)
    milestones_widget = Milestones(key_name=account_id)
    acc = Accounts(key_name=account_id,
                   email=account_id,
                   password="******",
                   isEnabled=constants.ACCOUNT_STATUS.ENABLED, 
                   accountType="admin",
                   paymentType="free",
                   cookieKey="xxxxxxxxx", 
                   apiKey=api_key, 
                   trophyWidget=trophy_case_widget,
                   pointsWidget=points_widget,
                   rankWidget=rank_widget,
                   leaderWidget=leader_widget,
                   milestoneWidget=milestones_widget)

     # delete ten badges
    for ii in range(0,10):
      badgeKey = badges_dao.create_badge_key(account_id, badge_theme, str(ii), "private")
      badges_dao.delete_badge_image(badgeKey)
      badges_dao.delete_badge(badgeKey)

    widgets_dao.delete_widget(account_id, "TrophyCase")
    widgets_dao.delete_widget(account_id, "Points")
    widgets_dao.delete_widget(account_id, "Rank")
    widgets_dao.delete_widget(account_id, "Leaderboard")
    widgets_dao.delete_widget(account_id, "Notifier")
    widgets_dao.delete_widget(account_id, "Milestones")
    accounts_dao.delete_account(account_id)
    self.response.out.write(success_ret())
    return
Beispiel #2
0
def delete_user(user_key):
  user_ref = get_user_with_key(user_key)
  if not user_ref:
    logging.error("Unable to get user with key: " + str(user_key))
    return 

  badges = badges_dao.get_user_badges(user_ref)
  for b in badges:
    badges_dao.delete_badge_instance(b.key().name())

  return memcache_db.delete_entity_with_key(user_key, "Users")
Beispiel #3
0
def delete_user(user_key):
    user_ref = get_user_with_key(user_key)
    if not user_ref:
        logging.error("Unable to get user with key: " + str(user_key))
        return

    badges = badges_dao.get_user_badges(user_ref)
    for b in badges:
        badges_dao.delete_badge_instance(b.key().name())

    return memcache_db.delete_entity_with_key(user_key, "Users")
Beispiel #4
0
  def post(self):
    start = time.time()
    api_key = self.request.get('apikey')
    account_id = self.request.get('accountid')
    user_id = self.request.get('userid')
    badge_ref_id = self.request.get('badgeid')
    logdiction = {'event':'removebadge', 
                  'api':'remove_badge',
                  'badgeid':badge_ref_id,
                  'is_api':'yes',
                  'ip':self.request.remote_addr,
                  'user':user_id,
                  'account':account_id,
                  'success':'true'}

    # Get the account 
    acc = accounts_dao.authorize_api(account_id, api_key)
    if not acc:
      logdiction['success'] = 'false'
      logdiction['details'] = auth_error()
      logs.create(logdiction)
      self.response.out.write(auth_error())
      return 

    if not user_id or not badge_ref_id:
      logdiction['success'] = 'false'
      logdiction['details'] = bad_args()
      logs.create(logdiction)
      self.response.out.write(bad_args())
      return  

    badge_key = badges_dao.get_key_from_badge_id(account_id, badge_ref_id)
    if not badge_key:
      logdiction['success'] = 'false'
      logdiction['details'] = badge_error()
      logs.create(logdiction)
      self.response.out.write(badge_error())
      return  
  
    # Get the user
    user_ref = users_dao.get_or_create_user(account_id, user_id, acc)
    if not user_ref:
      logdiction['success'] = 'false'
      logdiction['details'] = db_error()
      logs.create(logdiction)
      self.response.out.write(db_error())
      return 
 
    badge_instance_key = badges_dao.get_badge_instance_key(badge_key, user_id) 
    # Get the Badge Type (used as a reference for the instances) 
    badge_ref = badges_dao.get_badge(badge_key)
    if not badge_ref:
      logdiction['success'] = 'false'
      logdiction['details'] = badge_error()
      logs.create(logdiction)
      self.response.out.write(badge_error())
      return  

    try:
      new_badge_instance = badges_dao.delete_badge_instance(badge_instance_key)
    except:
      logdiction['success'] = 'false'
      logdiction['details'] = db_error()
      logs.create(logdiction)
      self.response.out.write(db_error())
      return 
    logs.create(logdiction)
    self.response.out.write(success_ret())
    timing(start)
    return