Exemplo n.º 1
0
 def changeNote(self, id):
     """ Change the note """
     try:
         pin = Session.query(ModeratorPin).get(id)
     except Exception, e:
         log.critical('Could not fetch the pin because: %s' % e)
         h.flash('Could not find PIN.')
         redirect(url(controller='main/new_pin', action='index'))
Exemplo n.º 2
0
    def new_pin(self):
        """Request a new PIN"""
        if len(request.params.get('participant_pin', '')) != 7 or len(request.params.get('moderator_pin', '')) != 7:
            h.flash("Your PINs need to be 7 numbers.")
            redirect(url('/main/new_pin/new_pin_form'))
        
        if Session.query(ModeratorPin).filter(ModeratorPin.username == session.get('username')).count() >= 5:
            redirect(url('/main/conferences/index'))

        try:            
            mPin = ModeratorPin(session.get('username'), session.get('domain'), request.params.get('moderator_pin'), note=request.params.get('note') or None)
        except Exception, e:
            h.flash(str(e))
            redirect(url('/main/new_pin/new_pin_form'))
Exemplo n.º 3
0
    def gen_report(self):
        """View the reports"""
        conf_name = request.params.get('conf_name')
        date_from = request.params.get('date_from')
        date_to = request.params.get('date_to')
        stmt = Session.query(Conference).join(ModeratorPin).filter(ModeratorPin.username == session.get('username'))

        if date_from and date_to:
            try:
                ddate_from = datetime(*strptime(date_from, '%m/%d/%Y')[:3])
                ds = strptime(date_to, '%m/%d/%Y')
                ddate_to = datetime(ds[0], ds[1], ds[2] , 23, 59, 59)
                stmt = stmt.filter(and_(Conference.created >= ddate_from, Conference.ended <= ddate_to))
            except ValueError, e:
                log.warning('User has supplied the wrong time format, disregarding filter: %s %s' % (date_from, date_to))
                h.flash('Invalid date format.')
                redirect(url(controller='main/reports', action='index'))
Exemplo n.º 4
0
    def new_pin(self):
        """Request a new PIN"""
        if len(request.params.get('participant_pin', '')) < 7 or len(request.params.get('moderator_pin', '')) < 7:
            h.flash("Your PINs need to be 7 numbers.")
            redirect(url('/main/new_pin/new_pin_form'))
        
        if Session.query(ModeratorPin).filter(ModeratorPin.username == session.get('username')).count() >= 5:
            redirect(url('/main/conferences/index'))

        mPin = ModeratorPin(session.get('username'), session.get('domain'))
        mPin.pin = request.params.get('moderator_pin')
        try:
            Session.query(ModeratorPin).filter(or_(ModeratorPin.pin == mPin.pin, ParticipantPin.pin == mPin.pin)).one()
            h.flash('Moderator PIN was taken.')
            redirect(url('/main/new_pin/new_pin_form'))
        except NoResultFound, e:
            Session.add(mPin)
Exemplo n.º 5
0
        mPin = ModeratorPin(session.get('username'), session.get('domain'))
        mPin.pin = request.params.get('moderator_pin')
        try:
            Session.query(ModeratorPin).filter(or_(ModeratorPin.pin == mPin.pin, ParticipantPin.pin == mPin.pin)).one()
            h.flash('Moderator PIN was taken.')
            redirect(url('/main/new_pin/new_pin_form'))
        except NoResultFound, e:
            Session.add(mPin)


        pPin = ParticipantPin(session.get('username'))
        pPin.pin = request.params.get('participant_pin')
        try:
            Session.query(ModeratorPin).filter(or_(ModeratorPin.pin == pPin.pin, ParticipantPin.pin == pPin.pin)).one()
            h.flash('Participant PIN was taken.')
            redirect(url('/main/new_pin/new_pin_form'))
        except NoResultFound, e:
            mPin.participant_pin = pPin
            Session.add(pPin)
            Session.commit()
        
        redirect(url('/main/new_pin/index'))
        
    def generatePin(self):
        """Generate a new available PIN"""
        while True:
            mPin = ModeratorPin(session.get('username'), session.get('domain'))
            try:
                Session.query(ModeratorPin, ParticipantPin).filter(or_(ModeratorPin.pin == mPin.pin, ParticipantPin.pin == mPin.pin)).one()
            except NoResultFound, e:
Exemplo n.º 6
0
            h.flash("Your PINs need to be 7 numbers.")
            redirect(url('/main/new_pin/new_pin_form'))
        
        if Session.query(ModeratorPin).filter(ModeratorPin.username == session.get('username')).count() >= 5:
            redirect(url('/main/conferences/index'))

        try:            
            mPin = ModeratorPin(session.get('username'), session.get('domain'), request.params.get('moderator_pin'), note=request.params.get('note') or None)
        except Exception, e:
            h.flash(str(e))
            redirect(url('/main/new_pin/new_pin_form'))
            
        try:
            pins = Session.query(ModeratorPin).join(ParticipantPin).filter(or_(ModeratorPin.pin == mPin.pin, ParticipantPin.pin == mPin.pin)).one()
            log.debug('Found %s while testing pPin.' % pins.pin)
            h.flash('Moderator PIN was taken.')
            redirect(url('/main/new_pin/new_pin_form'))
        except NoResultFound:
            log.debug('%s is available for moderator pin.' % mPin.pin)


        try:
            pPin = ParticipantPin(session.get('username'), request.params.get('participant_pin'))
        except Exception, e:
            h.flash(str(e))
            redirect(url('/main/new_pin/new_pin_form'))
          
        try:  
            pins = Session.query(ModeratorPin).join(ParticipantPin).filter(or_(ModeratorPin.pin == pPin.pin, ParticipantPin.pin == pPin.pin)).one()
            log.debug('Found %s while testing pPin.' % pins.pin)
            Session.rollback()
Exemplo n.º 7
0
 def logout(self):
     """Log the user out"""
     session.clear()
     session.save()
     h.flash("User logged out.")
     redirect("/")
Exemplo n.º 8
0
    def login(self):
        username = request.POST["username"]
        password = request.POST["password"]
        domain = request.POST["domain"]
        if username:
            # Authenticate the user!
            Base = config.get("ldap.base")

            Scope = ldap.SCOPE_SUBTREE
            Filter = "(&(objectClass=user)(sAMAccountName=" + username + "))"
            Attrs = ["displayName", "mail"]

            # Set the LDAP timeout for the connection.
            ldap.set_option(ldap.OPT_NETWORK_TIMEOUT, int(config.get("ldap.timeout")))

            for Server in aslist(config.get("ldap.hosts"), sep=","):
                Server = "ldap://" + Server
                log.info("Connecting to server: %s" % Server)
                l = ldap.initialize(Server)
                l.protocol_version = 3
                l.set_option(ldap.OPT_REFERRALS, 0)
                try:
                    l.simple_bind_s(username + "@" + domain, password)
                    r = l.search(Base, Scope, Filter, Attrs)
                    Type, user = l.result(r, 10)
                    Name, Attrs = user[0]
                    if hasattr(Attrs, "has_key") and Attrs.has_key("mail"):
                        email = Attrs["mail"][0]
                        session["email"] = email
                    if hasattr(Attrs, "has_key") and Attrs.has_key("displayName"):
                        displayName = Attrs["displayName"][0]
                        session["displayName"] = displayName

                    session["username"] = username
                    session["domain"] = domain
                    session["logged_in"] = True
                    session.save()
                except ldap.SERVER_DOWN, e:
                    log.warning("Server %s is down!" % Server)

                    if aslist(config.get("ldap.hosts"), sep=",").pop() in Server:
                        # We are the last server, so ...
                        log.critical("All LDAP servers are down. Last server tried was: %s" % Server)
                        msg = "Active Directory server is down for the moment. Please try again later."
                        h.flash(msg)
                        location = url(controller="auth/login", action="index")
                        redirect(location)
                    else:
                        continue
                except ldap.INVALID_CREDENTIALS, e:
                    msg = "Invalid username/password"
                    h.flash(msg)
                    location = url(controller="auth/login", action="index")
                    log.warning("User denied, redirecting to: %s. Error: %s" % (location, e))
                    redirect(location)
                except ldap.LDAPError, e:
                    msg = "Server error. Try again later."
                    h.flash(msg)
                    location = url(controller="auth/login", action="index")
                    log.critical("Redirecting to: %s because %s" % (location, e))
                    redirect(location)
Exemplo n.º 9
0
                        continue
                except ldap.INVALID_CREDENTIALS, e:
                    msg = "Invalid username/password"
                    h.flash(msg)
                    location = url(controller="auth/login", action="index")
                    log.warning("User denied, redirecting to: %s. Error: %s" % (location, e))
                    redirect(location)
                except ldap.LDAPError, e:
                    msg = "Server error. Try again later."
                    h.flash(msg)
                    location = url(controller="auth/login", action="index")
                    log.critical("Redirecting to: %s because %s" % (location, e))
                    redirect(location)

                # if we get here, user has been authenticated just fine. Break the loop
                break

        else:
            msg = "Invalid username/password"
            h.flash(msg)
            location = url(controller="auth/login", action="index")

        redirect(session.pop("after_login", url(controller="main/conferences", action="index")))

    def logout(self):
        """Log the user out"""
        session.clear()
        session.save()
        h.flash("User logged out.")
        redirect("/")