Exemplo n.º 1
0
    def move_up(self):
        """check if people can move up to attendance"""
        count = self.yescount  # people attending
        self.log.debug("moveup: count = %s, maxcount = %s" %
                       (count, self.settings.maxpeople))
        if count >= self.settings.maxpeople:
            return  # nothing to do

        # find people on the waitinglist
        diff = self.settings.maxpeople - count
        users = self.coll.find(
            {
                'state': 'live',
                'attend': 'yes',
                'waitinglist': True
            },
            sort=[('queue_date', 1)],
            as_class=User).limit(diff)

        for user in users:
            user['queue_date'] = None
            user['waitinglist'] = False
            user.log("move up from waitinglist")
            self.log.info("user %s (%s) moved from waitinglist" %
                          (user['_id'], user['name']))
            euser = emails.UserEMailAdapter(self.settings, user)
            euser.send_attend()
            self.coll.save(user)
Exemplo n.º 2
0
    def process_attendance(self, old_user, new_user):
        """trigger any events which might result from a change in attendance state.
        We get the old record of the user and the new one."""
        old_attend = old_user['attend']
        new_attend = new_user['attend']
        self.log.debug("old_attend: %s, new_attend: %s" %
                       (old_attend, new_attend))
        if old_attend == new_attend:
            return new_user  # if nothing changed, nothing has to be done
        count = self.yescount  # this includes the old state of the user
        self.log.debug("count: %s, maxpeople: %s" %
                       (count, self.settings.maxpeople))
        if count < self.settings.maxpeople:
            # clear any attendance metadata
            new_user['queue_date'] = None
            new_user['waitinglist'] = False
            return new_user  # nothing to be done if we have less people than allowed

        if new_attend == "yes":
            # user changed to yes and thus needs to get onto the waiting list
            new_user['queue_date'] = datetime.datetime.now()
            new_user['waitinglist'] = True
            new_user.log("user added to waiting list")
            euser = emails.UserEMailAdapter(self.settings, new_user)
            euser.send_waitinglist()
            return new_user
        elif old_attend == "yes":
            # user was attending but now isn't anymore
            new_user.log("user removed from attending or waiting list")
        new_user['queue_date'] = None
        new_user['waitinglist'] = False
        return new_user
Exemplo n.º 3
0
 def send_new_password(self, user):
     """create and send a new password to a user"""
     if user['state'] == "created":
         self.settings.log.warn(
             "a new password is not supposed to be sent to users with state==created, user=%s"
             % user['email'])
         return None
     pw = user.create_pw()
     euser = emails.UserEMailAdapter(self.settings, user)
     euser.send_newpw(pw)
     user.log("new password sent")
     self.coll.save(user)
Exemplo n.º 4
0
 def send_validation_code(self, user):
     """create and send a validation code and a password to a user"""
     if user['state'] != "created":
         self.settings.log.warn(
             "a validation code is not supposed to be sent to users with state!=created, user=%s"
             % user['email'])
         return None
     code = user.create_validation_code()
     euser = emails.UserEMailAdapter(self.settings, user)
     euser.send_optin()
     user.log("validation code %s sent" % code)
     self.coll.save(user)
Exemplo n.º 5
0
    def validate_code(self, code):
        """check the validation code and change the state. Returns ``True`` for
        success and ``False`` for failure (wrong code)"""
        user = self.get_by_code(code)
        if user['state'] != "created":
            settings.log.warn(
                "a validation code is not supposed to be checked to users with state!=created, user=%s"
                % user['email'])
            return
        if user['validationcode'] == code:
            user['state'] = "live"
            user['validationcode'] = None
            user.log("validation code checked successfully")
            self.settings.log.info(
                "validation code for user %s checked successfully" %
                user['email'])

            # check if the user needs to go on the waitinglist
            if self.yescount >= self.settings.maxpeople and user[
                    'attend'] == "yes":
                self.settings.log.info("User %s goes to the waiting list" %
                                       user['_id'])
                user['queue_date'] = datetime.datetime.now()
                user['waitinglist'] = True

            # now send the welcome mail
            pw = user.create_pw()
            euser = emails.UserEMailAdapter(self.settings, user)
            euser.send_welcome(pw)
            user.log("welcome mail sent")
            self.coll.save(user)
            return True
        else:
            user.log("validation code NOT checked successfully")
            settings.log.info(
                "validation code for user %s NOT checked successfully" %
                user['email'])
            return False