Ejemplo n.º 1
0
def main():
    try:
        try:
            rqstSession = request.get_cookie('pysessionid',
                                             secret=prop('cookieSecret'))
        except:
            pass
        if check_session(rqstSession) is True:
            try:
                roomTemp = check_temp.temp('room').get_temp()
                radTemp = check_temp.temp('rad').get_temp()
                outsideTemp = check_temp.temp('outside').get_temp()
                if request.forms.get('override', '').strip():
                    logging.debug('override')
                    set_override()
                    return template('main',
                                    roomTemp=roomTemp,
                                    radTemp=radTemp,
                                    outsideTemp=outsideTemp)
            except:
                pass
            return template('main',
                            roomTemp=roomTemp,
                            radTemp=radTemp,
                            outsideTemp=outsideTemp)
        elif request.forms.get('override', '').strip() is '':
            rqstSession = request.get_cookie('pysessionid',
                                             secret=prop('cookieSecret'))
            username = request.forms.get('username').upper()
            password = request.forms.get('password').strip()
            logging.debug(password)
            if auth.passwd(username, password).check_password() == True:
                set_session(rqstSession)
                return template('main',
                                roomTemp=roomTemp,
                                radTemp=radTemp,
                                outsideTemp=outsideTemp)
            else:
                return template('login')
    except Exception as e:
        logging.debug('exception in main: %s' % e)
        return '<p>Error</p>'
Ejemplo n.º 2
0
def new_user():
    try:
        rqstSession = request.get_cookie('pysessionid',
                                         secret=prop('cookieSecret'))
    except:
        pass
    if check_session(rqstSession) is True:
        if request.forms.get('save', '').strip():
            userid = request.forms.get('userid', '').upper()
            password = request.forms.get('password').strip()
            confpassword = request.forms.get('confpassword').strip()
            logging.debug('new user password = %s' % password)
            if password is not '' and password == confpassword and userid is not '':
                hashed_password = auth.passwd(userid, password).hash_password()

                conn_string = prop('database')
                conn = psycopg2.connect(conn_string)
                cursor = conn.cursor()

                sql = """
                        insert into users (id_usrr, userid, password) values (nextval('users_id_usrr_seq'), %(userid)s, %(password)s)
                        """
                cursor.execute(sql, {
                    'userid': userid,
                    'password': hashed_password
                })
                conn.commit()
                cursor.close()
                redirect("/main")

            else:
                return template('newuser')
        else:
            return template('newuser')
    else:
        pysessionid = ''
        response.set_cookie('pysessionid',
                            pysessionid,
                            secret=prop('cookieSecret'),
                            Expires='Thu, 01-Jan-1970 00:00:10 GMT',
                            httponly=True)
        return template('login')