Esempio n. 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
Esempio n. 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")
Esempio n. 3
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')
    user_key = users_dao.get_user_key(account_id, user_id)
    acc = accounts_dao.authorize_api(account_id, api_key)

    logdiction = {'event':'getuserdata', 
                  'api': 'get_user_data',
                  'is_api':'yes',
                  'user':user_id,
                  'account':account_id,
                  'success':'true',
                  'ip':self.request.remote_addr}
    if not acc:
      logdiction['success'] = 'false'
      logdiction['details'] = auth_error()
      logs.create(logdiction)
      self.response.out.write(auth_error())
      return 

    user_ref = users_dao.get_user(account_id, user_id)
    if not user_ref:
      logdiction['success'] = 'false'
      logdiction['details'] = user_error()
      logs.create(logdiction)
      error("User for account %s, %s not found"%(account_id, user_id))
      self.response.out.write(user_error())
      return 

    badges = badges_dao.get_user_badges(user_ref)
    badge_keys = []

    # get the badge image link
    for b in badges:
      if b.awarded == "yes":
        bid = badges_dao.get_badge_id_from_instance_key(b.key().name())
        badge_keys.append(bid)
    ret = {"status":"success",
           "user_id":user_ref.userid,
           "is_enabled":user_ref.isEnabled,
           "creation_date":str(user_ref.creationDate),
           "points":user_ref.points,
           "profile_name": user_ref.profileName,
           "profile_link": user_ref.profileLink,
           "profile_img": user_ref.profileImg,
           "badges": badge_keys}
    logs.create(logdiction)
    self.response.out.write(json.dumps(ret)) 
    timing(start) 
Esempio n. 4
0
  def milestones_values(self, user_ref, acc_ref, height, width):
    user_badges = badges_dao.get_user_badges(user_ref)
    acc_badges = badges_dao.get_rendereable_badgeset(acc_ref)
    mcase_ref = None
    if not acc_ref:
      mcase_ref = Milestones()
    else:
      try:
        mcase_ref = acc_ref.milestoneWidget
      except:
        mcase_ref = widgets_dao.add_milestones(acc_ref)

    if user_ref and user_ref.userid == constants.ANONYMOUS_USER:
      user_badges = []

    badge_count = 0
    display_badges = []
    for badge in user_badges:
      b = {}
      try:
        # In case the badge was removed, we'll skip it
        b["badgeRef"] = badge.badgeRef
      except Exception, e:
        continue
      if badge.awarded == "yes":
        b["awarded"] = True
      else:
        b["awarded"] = True
      b["id"] = badge_count 
      b["awarded"] = badge.awarded
      b["pointsRequired"] = badge.pointsRequired

      # backward compatibility
      if badge.pointsRequired == 9999999999:
        b["pointsRequired"] = 0
   
      if badge.pointsEarned > badge.pointsRequired:
        b["pointsEarned"] = badge.pointsRequired
      else:  
        b["pointsEarned"] = badge.pointsEarned
      b["resource"] = badge.resource
      b["reason"] = badge.reason
      b["downloadLink"] = badge.downloadLink
      b["id"] = badge_count
      badge_count += 1
      display_badges.append(b)
Esempio n. 5
0
  def trophy_case_values(self, user_ref, acc_ref, height, width):
    badges = badges_dao.get_user_badges(user_ref)
    tcase_ref = None
    if not acc_ref:
      tcase_ref = TrophyCase()
    else:
      try:
        tcase_ref = acc_ref.trophyWidget
      except:
        tcase_ref = widgets_dao.add_trophy_case(acc_ref)

    awarded_badges= []
    for b in badges:
      if b.awarded == "yes":
        awarded_badges.append(b)
    # here we get the custom trophy case settings
    # Grab all the badge urls
    ret = {"status":"success"}
     
    for ii in tcase_ref.properties():
      ret[ii] = getattr(tcase_ref, ii)
    ret["badges"] = awarded_badges

    # Internal div's need to be slighy smaller than the iframe
    if width and height:
      try:
        width = int(width)
        height = int(height)
        # How did I get this equation? Trial and error.
        height = height - 2 *int(ret['borderThickness']) - 8
        width = width - 2 *int(ret['borderThickness']) - 8
        ret['height'] = height
        ret['width'] = width
      except:
        pass
    return ret 
Esempio n. 6
0
  def milestones_values(self, user_ref, acc_ref, height, width):
    user_badges = badges_dao.get_user_badges(user_ref)
    acc_badges = badges_dao.get_rendereable_badgeset(acc_ref)
    mcase_ref = None
    if not acc_ref:
      mcase_ref = Milestones()
    else:
      try:
        mcase_ref = acc_ref.milestoneWidget
      except:
        mcase_ref = widgets_dao.add_milestones(acc_ref)

    if user_ref and user_ref.userid == constants.ANONYMOUS_USER:
      user_badges = []

    badge_count = 0
    display_badges = []
    for badge in user_badges:
      b = {}
      if badge.awarded == "yes":
        b["awarded"] = True
      else:
        b["awarded"] = True
      b["id"] = badge_count 
      b["awarded"] = badge.awarded
      b["pointsRequired"] = badge.pointsRequired

      # backward compatibility
      if badge.pointsRequired == 9999999999:
        b["pointsRequired"] = 0
   
      if badge.pointsEarned > badge.pointsRequired:
        b["pointsEarned"] = badge.pointsRequired
      else:  
        b["pointsEarned"] = badge.pointsEarned
      b["resource"] = badge.resource
      b["reason"] = badge.reason
      b["downloadLink"] = badge.downloadLink
      b["id"] = badge_count
      b["badgeRef"] = badge.badgeRef
      badge_count += 1
      display_badges.append(b)
    # Put all badges that have not been awarded
    to_add = []
    for aa in acc_badges:
      is_there = False
      for dd in display_badges:
        if aa["key"] == dd["badgeRef"].key().name():
          is_there = True
      if not is_there:
        b = {}
        b["id"] = badge_count 
        b["awarded"] = False
        b["pointsEarned"] = 0
        b["pointsRequired"] = 0
        # This name should not have changed
        b["resource"] = ""
        b["reason"] = aa["description"]
        b["downloadLink"] = aa["downloadLink"]
        badge_count += 1
        to_add.append(b)
    display_badges.extend(to_add)
    ret = {"status":"success"}
     
    for ii in mcase_ref.properties():
      ret[ii] = getattr(mcase_ref, ii)
    ret["badges"] = display_badges

    # Internal div's need to be slighy smaller than the iframe
    if width and height:
      try:
        width = int(width)
        height = int(height)
        # How did I get this equation? Trial and error.
        height = height - 2 *int(ret['borderThickness']) - 8
        width = width - 2 *int(ret['borderThickness']) - 8
        ret['height'] = height
        ret['width'] = width
      except:
        pass
    ret['barSize'] = ret['imageSize']
    return ret