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 post(self):
        current_session = Session().get_current_session(self)
        account_entity = current_session.get_account_entity()
        email = account_entity.email
        ui = ui_api.UserInfuser(email, account_entity.apiKey, sync_all=True)

        user_id = self.request.get('userid')
        if not user_id:
            self.redirect('/adminconsole/users?error=NoUserID')
            return
        if user_id == constants.ANONYMOUS_USER:
            self.redirect('/adminconsole/users?error=InvalidID')
            return
        if not users_dao.get_user(email, user_id):
            self.redirect('/adminconsole/users?error=InvalidID')
            return
        award_type = self.request.get('awardtype')
        if award_type == 'awardbadge':
            badge_id = self.request.get("badgeid")
            if not badge_id:
                logging.error("Badge ID not provided %s" % email)
                self.redirect('/adminconsole/users?error=BadBadge')
            badge_key = badges_dao.get_key_from_badge_id(email, badge_id)
            if not badges_dao.get_badge(badge_key):
                logging.error("Badge ID does not exist for account %s" % email)
                self.redirect('/adminconsole/users?error=BadBadge')
            if not ui.award_badge(user_id, badge_id):
                self.redirect('/adminconsole/users?error=BadBadge')
                logging.error(
                    "Make sure the client code urls points to http://<app-id>.appspot.com if this is a custom deploy"
                )
                logging.error(
                    "Account %s is unable to award badge %s to user %s" %
                    (email, badge_id, user_id))
                self.redirect('/adminconsole/users?error=BadBadge')
        elif award_type == 'awardpoints':
            points = self.request.get("points")
            try:
                points = int(points)
            except:
                points = 0
            if not ui.award_points(user_id, points):
                logging.error(
                    "Account %s is unable to award points %d to user %s" %
                    (email, points, user_id))
                self.redirect('/adminconsole/users?error=InvalidID')
        else:
            logging.error(
                "Received %s for console user award from account %s" %
                (award_type, email))
            self.redirect('/adminconsole/users?error=InvalidID')

        self.redirect('/adminconsole/users/edit?name=' + user_id)
Beispiel #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) 
Beispiel #4
0
  def post(self):
    current_session = Session().get_current_session(self)
    account_entity = current_session.get_account_entity()
    email = account_entity.email
    ui = ui_api.UserInfuser(email, account_entity.apiKey, sync_all=True)

    user_id = self.request.get('userid')
    if not user_id:
      self.redirect('/adminconsole/users?error=NoUserID')
      return
    if user_id == constants.ANONYMOUS_USER:
      self.redirect('/adminconsole/users?error=InvalidID')
      return 
    if not users_dao.get_user(email, user_id):
      self.redirect('/adminconsole/users?error=InvalidID')
      return 
    award_type = self.request.get('awardtype')
    if award_type == 'awardbadge':
      badge_id = self.request.get("badgeid")
      if not badge_id:
        logging.error("Badge ID not provided %s"%email)
        self.redirect('/adminconsole/users?error=BadBadge')
      badge_key = badges_dao.get_key_from_badge_id(email, badge_id)
      if not badges_dao.get_badge(badge_key):
        logging.error("Badge ID does not exist for account %s"%email)
        self.redirect('/adminconsole/users?error=BadBadge')
      if not ui.award_badge(user_id, badge_id):
        self.redirect('/adminconsole/users?error=BadBadge')
        logging.error("Make sure the client code urls points to http://<app-id>.appspot.com if this is a custom deploy")
        logging.error("Account %s is unable to award badge %s to user %s"%(email, badge_id, user_id))
        self.redirect('/adminconsole/users?error=BadBadge')
    elif award_type == 'awardpoints': 
      points = self.request.get("points")
      try:
        points = int(points)
      except:
        points = 0
      if not ui.award_points(user_id, points):
        logging.error("Account %s is unable to award points %d to user %s"%(email, points, user_id))
        self.redirect('/adminconsole/users?error=InvalidID')
    else:
      logging.error("Received %s for console user award from account %s"%(award_type, email))
      self.redirect('/adminconsole/users?error=InvalidID')
      
    self.redirect('/adminconsole/users/edit?name=' + user_id)