Ejemplo n.º 1
0
 def recover_mana(self):
     """ Recover between 10-20% mana """
     true_user = User.by_id(self.id)
     max_mana = true_user.mana
     # If there is health to gain
     if self.mana < max_mana:
         self.mana += min(int(max_mana * (random() % 0.2)), max_mana)
Ejemplo n.º 2
0
 def post(self, *args, **kwargs):
     token = self.get_argument("token", "")
     uuid = self.get_argument("uuid", "")
     if self.valid_pass_token(token, uuid):
         if self.get_argument("pass1", "") != self.get_argument(
                 "pass2", ""):
             self.render(
                 "public/reset.html",
                 errors=None,
                 info=["Passwords do not match."],
                 token=token,
                 uuid=uuid,
             )
         else:
             pass_token = PasswordToken.by_value(token)
             user = User.by_id(pass_token.user_id)
             user.password = self.get_argument("pass1", "")
             pass_token.used = True
             self.dbsession.add(pass_token)
             self.dbsession.commit()
             self.render(
                 "public/reset.html",
                 errors=None,
                 info=["Successfully updated password."],
                 uuid=uuid,
                 token=token,
             )
Ejemplo n.º 3
0
 def get_current_user(self):
     ''' Get current user object from database '''
     if self.session is not None:
         if self._user is None:
             self._user = User.by_id(self.session['user_id'])
         return self._user
     return None
Ejemplo n.º 4
0
    def get(self):
        uid = self.read_secure_cookie('user_id')
        user = uid and User.by_id(int(uid))
        logging.error('DB Query')
        logged_username = user and user.name

        

        if logged_username == '' or logged_username == None:
            self.redirect('/')
        else:

            offer_added = self.request.get('offer_added')

            u = loged_user(logged_username) #User.by_name(logged_username)

            profile = loged_profile(logged_username) 

            logging.error('profile en welcome: %s' % profile)

            if  valid_username(logged_username):
                if profile:

                    if offer_added:
                        self.render('ioffer_welcome.html', user = u, profile = profile, categories = categories, offer_added = True, last_10_offers = self.get_last_10_offers())
                    else:
                        self.render('ioffer_welcome.html', user = u, profile = profile, categories = categories, countries = countries, last_10_offers = self.get_last_10_offers(), geo_params = self.get_geo_params())
                else:
                    self.render('ioffer_welcome.html', user = u, last_10_offers = self.get_last_10_offers(), categories = categories, geo_params = self.get_geo_params())
            
            else:
                error_username = '******' % logged_username
                self.render('ioffer_welcome.html', user = u, error_username = error_username, last_10_offers = self.get_last_10_offers(), categories = categories, geo_params = self.get_geo_params())
 def get_current_user(self):
     ''' Get current user object from database '''
     if self.session is not None:
         if self._user is None:
             self._user = User.by_id(self.session['user_id'])
         return self._user
     return None
Ejemplo n.º 6
0
 def wrapper(self, *args, **kwargs):
     if self.session is not None:
         user = User.by_id(self.session['user_id'])
         if user is not None and user.has_permission(permission):
             return method(self, *args, **kwargs)
     logging.warn("Attempted unauthorized access from %s to %s" %
                  (self.request.remote_ip, self.request.uri))
     self.redirect(self.application.settings['forbidden_url'])
Ejemplo n.º 7
0
 def recover_health(self):
     """ Recover between 10-20% health """
     true_user = User.by_id(self.id)
     max_health = true_user.health
     # If there is health to gain
     if self.health < max_health:
         # Random number between .0 <-> .2 take that percentage of max hp and add it back in capping at your max hp
         self.health += min(int(max_health * (random() % 0.1)), max_health)
Ejemplo n.º 8
0
 def post_avatar(self, *args, **kwargs):
     '''
     Saves avatar - Reads file header an only allows approved formats
     '''
     user = User.by_id(self.session['user_id'])
     if 'avatar' in self.request.files:
         user.avatar = self.request.files['avatar'][0]['body']
     else:
         self.render_page(errors=["Please provide an image"])
Ejemplo n.º 9
0
 def render(self, *args, **kwargs):
     ''' Renders the top menu '''
     if self.handler.session is not None:
         user = User.by_id(self.handler.session['user_id'])
         if self.handler.session['menu'] == 'user':
             return self.render_string('menu/user.html', user=user)
         elif self.handler.session['menu'] == 'admin':
             return self.render_string('menu/admin.html', handle=user.handle)
     return self.render_string('menu/public.html')
Ejemplo n.º 10
0
 def post_avatar(self, *args, **kwargs):
     '''
     Saves avatar - Reads file header an only allows approved formats
     '''
     user = User.by_id(self.session['user_id'])
     if 'avatar' in self.request.files:
         user.avatar = self.request.files['avatar'][0]['body']
     else:
         self.render_page(errors=["Please provide an image"])
Ejemplo n.º 11
0
    def initialize(self, *a, **kw):
        webapp2.RequestHandler.initialize(self, *a, **kw)
        uid = self.read_secure_cookie('user_id')
        self.user = uid and User.by_id(int(uid))

        if self.request.url.endswith('json'):
            self.format = 'json'
        else:
            self.format = 'html'
        self.client = memcache.Client()
Ejemplo n.º 12
0
 def get_current_user(self):
     """ Get current user object from database """
     if self.session is not None:
         try:
             return User.by_id(self.session['user_id'])
         except KeyError:
             logging.exception("Malformed session: %r" % self.session)
         except:
             logging.exception("Failed call to get_current_user()")
     return None
Ejemplo n.º 13
0
 def get(self, user_id=""):
     """ Ignore the Backbone.js ID values, and use the session """
     user = self.get_current_user()
     if len(user_id) < 1:
         self.write([user.to_dict() for user in User.all()])
     else:
         _user = User.by_id(user_id)
         if _user is not None:
             self.write(_user.to_manager_dict())
         else:
             raise ValidationError("User not found")
Ejemplo n.º 14
0
 def render(self, *args, **kwargs):
     ''' Renders the top menu '''
     if self.handler.session is not None:
         user = User.by_id(self.handler.session['user_id'])
     else:
         user = None
     scoreboard_visible = self.scoreboard_visible(user)
     if self.handler.session is not None:
         if self.handler.session['menu'] == 'user':
             return self.render_string('menu/user.html', user=user, scoreboard_visible=scoreboard_visible)
         elif self.handler.session['menu'] == 'admin':
             return self.render_string('menu/admin.html', handle=user.handle, scoreboard_visible=scoreboard_visible)
     return self.render_string('menu/public.html', scoreboard_visible=scoreboard_visible)
Ejemplo n.º 15
0
 def delete(self, user_id=""):
     """ Delete an existing user """
     current_user = self.get_current_user()
     rm_user = User.by_id(user_id)
     if rm_user is not None and rm_user != current_user:
         rm_user.account_locked = True
         self.dbsession.add(rm_user)
         self.dbsession.commit()
         self.write(rm_user.to_dict())
     elif current_user == rm_user:
         raise ValidationError("You cannot delete yourself")
     else:
         raise ValidationError("User not found")
Ejemplo n.º 16
0
 def initialize(self, *a, **kw):
     
     webapp2.RequestHandler.initialize(self, *a, **kw)
     uid = self.read_secure_cookie('user_id')
     
     self.user = uid and User.by_id(int(uid))
     
     #Enviroment globals variables
     jinja_env.globals['HOST_URL'] = self.request.host_url
     jinja_env.globals['USER'] = self.user
     if self.request.url.endswith('.json'):
         self.format = 'json'
     else:
         self.format = 'html'
Ejemplo n.º 17
0
 def attack_monster(self, monster):
     """ Calculates the damage toward a given monster """
     true_monster = Monster.by_id(monster.id)
     true_user = User.by_id(self.id)
     monster_armor = ArmoryArmor.by_id(true_monster.armor_id)
     weapon = true_user.equiped_weapon
     if monster_armor != None and weapon != None:
         hit = self.roll_hit()
         if hit:
             reduction = monster_armor.rating
             damage = get_random_damage(weapon.damage)
             damage -= int(reduction / REDUCTION_CONSTANT)
             # Make sure we never return zero
             return max(damage, 0)
     return 0
Ejemplo n.º 18
0
 def advanced_attack_user(self, user):
     """ calculates damage agianst a provided user """
     true_monster = Monster.by_id(self.id)
     true_user = User.by_id(user.id)
     user_armor = true_user.equiped_armor
     weapon = ArmoryWeapon.by_id(true_monster.weapon_id)
     if user_armor != None and weapon != None:
         hit = self.roll_advanced_hit()
         if hit:
             reduction = user_armor.rating
             damage = get_random_damage(weapon.damage)
             damage -= int(reduction / REDUCTION_CONSTANT)
             # Make sure we never return zero
             return max(damage, 0) * 2
     return 0
Ejemplo n.º 19
0
 def get_current_user(self):
     """ Get current user object from database """
     if self.session is not None:
         try:
             if self._user is None:
                 self._user = User.by_id(self.session['user_id'])
             assert self._user is not None
             return self._user
         except KeyError:
             logging.exception("Malformed session: %r", self.session)
         except AssertionError:
             logging.error("Failed to find user in database with id %r",
                           self.session['user_id'])
         except:
             logging.exception("Failed call to get_current_user()")
     return None
Ejemplo n.º 20
0
 def get_current_user(self):
     """ Get current user object from database """
     if self.session is not None:
         try:
             if self._user is None:
                 self._user = User.by_id(self.session['user_id'])
             assert self._user is not None
             return self._user
         except KeyError:
             logging.exception("Malformed session: %r", self.session)
         except AssertionError:
             logging.error("Failed to find user in database with id %r",
                           self.session['user_id'])
         except:
             logging.exception("Failed call to get_current_user()")
     return None
Ejemplo n.º 21
0
 def valid_pass_token(self, token, uuid):
     pass_token = PasswordToken.by_value(token)
     if pass_token:
         user = User.by_id(pass_token.user_id)
         if (user and user.uuid == uuid and not pass_token.is_expired()
                 and not pass_token.used):
             return True
     self.render(
         "public/reset.html",
         errors=[
             "The password reset token does not exist, is invalid or expired."
         ],
         info=None,
         token="",
         uuid="",
     )
     return False
Ejemplo n.º 22
0
    def check_ended(self):
        """ This checks wether a user or monster is dead """
        valid_user = User.by_id(self.user.id)
        # check is the user died
        if self.monster.health <= 0:
            # update the user
            valid_user.experience += self.monster.experience
            valid_user.gold += self.monster.gold

            # Grab the quest
            quest = Quest.by_id(valid_user.quest_level)
            if quest != None:
                # If we still have battles left in our quest
                if valid_user.current_quest_battle < quest.number_of_battles:
                    valid_user.current_quest_battle += 1
                # If not, give us the next quest
                else:
                    valid_user.current_quest_battle = 0
                    valid_user.quest_level += 1
            dbsession.add(valid_user)
            dbsession.flush()

            # set variable for the client
            self.victor = self.user
            self.text = self.user.name + " has defeated " + self.monster.name + " !"
            self.exp = self.monster.experience
            self.gold = self.monster.gold
            return True

        elif self.user.health <= 0:
            # decrement experience
            valid_user.lost_battle()
            dbsession.add(valid_user)
            dbsession.flush()

            # set variable for the client
            self.victor = self.monster
            self.text = self.monster.name + " has defeated " + self.user.name + " !"
            self.exp = self.user.experience - valid_user.experience
            self.gold = 0
            return True

        # Both user and monster are alive
        return False
Ejemplo n.º 23
0
 def render(self, *args, **kwargs):
     ''' Renders the top menu '''
     if self.handler.session is not None:
         user = User.by_id(self.handler.session['user_id'])
     else:
         user = None
     scoreboard_visible = self.scoreboard_visible(user)
     if self.handler.session is not None:
         if self.handler.session['menu'] == 'user':
             return self.render_string(
                 'menu/user.html',
                 user=user,
                 scoreboard_visible=scoreboard_visible)
         elif self.handler.session['menu'] == 'admin':
             return self.render_string(
                 'menu/admin.html',
                 handle=user.handle,
                 scoreboard_visible=scoreboard_visible)
     return self.render_string('menu/public.html',
                               scoreboard_visible=scoreboard_visible)
Ejemplo n.º 24
0
 def render(self, *args, **kwargs):
     """ Renders the top menu """
     if self.handler.session is not None:
         user = User.by_id(self.handler.session["user_id"])
     else:
         user = None
     scoreboard_visible = self.scoreboard_visible(user)
     if self.handler.session is not None:
         if self.handler.session["menu"] == "user":
             return self.render_string(
                 "menu/user.html",
                 user=user,
                 scoreboard_visible=scoreboard_visible)
         elif self.handler.session["menu"] == "admin":
             return self.render_string(
                 "menu/admin.html",
                 user=user,
                 scoreboard_visible=scoreboard_visible)
     return self.render_string("menu/public.html",
                               scoreboard_visible=scoreboard_visible)
Ejemplo n.º 25
0
 def do_user_round(self, choice):
     """ perform the users turn """
     if choice == BattleMessage.ATTACK:
         damage = self.user.attack_monster(self.monster)
         self.monster.health -= damage
         if damage > 0:
             self.text = self.user.name + " hits " + self.monster.name + " for " + str(damage) + " damage!"
         else:
             self.text = self.user.name + " misses !"
     elif choice == BattleMessage.DEFEND:
         initial_health = self.user.health
         initial_mana = self.user.mana
         self.user.recover_health()
         self.user.recover_mana()
         self.text = (
             self.user.name
             + " defends and recovers "
             + str(self.user.health - initial_health)
             + " health and "
             + str(self.user.mana - initial_mana)
             + " mana!"
         )
     elif choice == BattleMessage.ADVANCED:
         true_user = User.by_id(self.user.id)
         required_mana = true_user.equiped_weapon.rating
         if self.user.mana > required_mana:
             # Remove the mana we jsut used
             self.user.mana -= required_mana
             damage = self.user.advanced_attack_monster(self.monster)
             self.monster.health -= damage
             if damage > 0:
                 self.text = (
                     self.user.name
                     + "'s Advanced attack hits "
                     + self.monster.name
                     + " for "
                     + str(damage)
                     + " damage!"
                 )
             else:
                 self.text = self.user.name + "'s Advanced attack misses !"
Ejemplo n.º 26
0
 def post(self, *args, **kwargs):
     token = self.get_argument("token", "")
     uuid = self.get_argument("uuid", "")
     if self.get_argument("pass1", "") != self.get_argument("pass2", ""):
         self.render(
             "public/reset.html",
             errors=None,
             info=["Passwords do not match."],
             token=token,
             uuid=uuid,
         )
         return
     pass_token = PasswordToken.by_value(token)
     if pass_token:
         user = User.by_id(pass_token.user_id)
         if (
             user
             and user.uuid == uuid
             and not pass_token.is_expired()
             and not pass_token.used
         ):
             user.password = self.get_argument("pass1", "")
             pass_token.used = True
             self.dbsession.add(pass_token)
             self.dbsession.commit()
             self.render(
                 "public/reset.html",
                 errors=None,
                 info=["Successfully updated password."],
                 uuid=uuid,
                 token=token,
             )
             return
     self.render(
         "public/reset.html",
         errors=["The user or token does not exist, is invalid or expired."],
         info=None,
         token=token,
         uuid=uuid,
     )
Ejemplo n.º 27
0
    def put(self, user_id=""):
        ch_user = User.by_id(user_id)
        ch_user.name = self.get_argument("name", ch_user.name)

        email_address = self.get_argument("email_address", "")
        if 4 < len(email_address):
            ch_user.email_address = email_address
        else:
            ch_user.clear_email_address()
        ch_user.email_updates = self.get_argument("email_updates", False)

        if self.get_argument("is_admin"):
            self._make_admin(ch_user)
        elif ch_user.has_permission(ADMIN_PERMISSION):
            self._remove_admin(ch_user)

        if ch_user.account_locked:
            ch_user.account_locked = self.get_argument("account_locked", True)

        self.dbsession.add(ch_user)
        self.dbsession.commit()
        self.write(ch_user.to_dict())
Ejemplo n.º 28
0
 def user(self):
     return User.by_id(self.user_id)
Ejemplo n.º 29
0
 def target(self):
     return User.by_id(self.target_id)
Ejemplo n.º 30
0
 def user(self):
     return User.by_id(self.user_id)
Ejemplo n.º 31
0
 def cracker(self):
     """ Returns display name of cracker """
     return User.by_id(self.cracker_id)
Ejemplo n.º 32
0
 def cracker(self):
     ''' Returns display name of cracker '''
     return User.by_id(self.cracker_id)
Ejemplo n.º 33
0
 def target(self):
     return User.by_id(self.target_id)
Ejemplo n.º 34
0
 def wrapper(self, *args, **kwargs):
     if self.session is not None:
         user = User.by_id(self.session['user_id'])
         if user is not None and user.has_permission(permission):
             return method(self, *args, **kwargs)
     self.redirect(self.application.settings['forbidden_url'])
Ejemplo n.º 35
0
 def victim(self):
     """ Returns display name of user """
     return User.by_id(self.victim_id)
Ejemplo n.º 36
0
 def cracker(self):
     ''' Returns display name of cracker '''
     return User.by_id(self.cracker_id)
Ejemplo n.º 37
0
 def initialize(self, *a, **kw):
     webapp2.RequestHandler.initialize(self, *a, **kw)
     uid = self.read_secure_cookie('user_id')
     self.user = uid and User.by_id(int(uid))
Ejemplo n.º 38
0
 def victim(self):
     ''' Returns display name of user '''
     return User.by_id(self.victim_id)
Ejemplo n.º 39
0
 def victim(self):
     ''' Returns display name of user '''
     return User.by_id(self.victim_id)
Ejemplo n.º 40
0
 def initialize(self, *a, **kw):
     AppHandler.initialize(self, *a, **kw)
     uid = self.read_secure_cookie('user_id')
     self.user = uid and User.by_id(int(uid))