# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
import sys
import os
sys.path.append( os.path.join( os.getcwd(), '..' ) )


# Make template classes
from mako.template import Template
from mako.lookup import TemplateLookup
templateLookup = TemplateLookup(directories=['./'])


#local classes for Numb3r L0ck3r
from config.Config import Config


localConfig = Config()
localConfig.parseConfigurationFile()

t = Template(filename='template/frontPage.tmpl',lookup=templateLookup)

#print(page)
print(t.render(templateDir="template",
	       **localConfig.getConfigurationDict()))

#local classes for Numb3r L0ck3r
from config.Config import Config

# The database class. Used to escape some sensitive information.
from DataBase import DataBase

# The authorization class to get the password hash for the admin user
from User.Authorize import Authorize



# Create objects from the configuration and database classes
config = Config('../config/config.dat')

# Parse the config file.
if(config.parseConfigurationFile()) :
    # The config file was successfully parsed.
    db = DataBase()                                      # Create the db object
    siteInfo     = config.getConfigurationDict()         # Get the site variables
    databaseInfo = config.getDatabaseConfigurationDict() # get the db variables
    securityInfo = config.getSecurityConfigurationDict() # get the security variables
    siteInfo.update(databaseInfo)                        # Add all the dicts into one master
    siteInfo.update(securityInfo)

    # Set the admin password
    auth = Authorize()
    auth.setPassPhrase(securityInfo['passwordSecurityHash'])
    siteInfo['adminPassword'] = auth.getHash(securityInfo['administratorPassword'])

    # read in the create.sql template.
    sqlCreateTemplate = Template(filename='create.sql.template',lookup=templateLookup)