<commit_before>

require 'sinatra/base'
require 'mongo'
include Mongo


class Netmento < Sinatra::Base

  def initialize() 
    super()
    #Is it thread safe ?
    @db = MongoClient.new['local']
  end 
  enable :logging

  #TODO: how to make that cluster safe?
  use Rack::Session::Pool, :expire_after => 2592000
  
  use Rack::Auth::Basic, "Netmento" do |username, password|
    ([username, password] == ['admin', 'admin']) or ([username, password] == ['other', 'other'])    
  end

  before do
    session[:user] = @db.collection("users").find_one({:userId => "admin"}) unless session[:user]
    @user = session[:user]
  end
  
  get '/' do
    redirect '/netmento'
  end

  get '/netmento' do
    haml :home, :format => :html5
  end

  get '/profile' do    
    haml :profile, :format => :html5, :locals => {:user => session[:user] } 
  end

  get '/network' do
    haml :network, :format => :html5
  end

  get '/knowledgeArea' do
    haml :knowledgeArea, :format => :html5
  end
<commit_msg>start Editing entry in mongoDB<commit_after>

require 'sinatra/base'
require 'mongo'
include Mongo


class Netmento < Sinatra::Base

  def initialize() 
    super()
    #Is it thread safe ?
    @db = MongoClient.new['local']
  end 
  enable :logging

  #TODO: how to make that cluster safe?
  use Rack::Session::Pool, :expire_after => 2592000
  
  use Rack::Auth::Basic, "Netmento" do |username, password|
    #TODO check the password in mongoDB
    ([username, password] == [username, username]) 
  end

  before do
    #TODO get the real user from ENV
    session[:user] = @db.collection("users").find_one({:userId => "admin"}) unless session[:user]
    @user = session[:user]
  end
  
  get '/' do
    redirect '/netmento'
  end

  get '/netmento' do
    haml :home, :format => :html5
  end

  post '/profile' do
    @user["name"] = params[:name]
    @db.collection("users").save(@user)
    #TODO find a way to redirect
    haml :profile, :format => :html5
  end

  
  get '/profile' do
    haml :profile, :format => :html5
  end

  get '/network' do
    haml :network, :format => :html5
  end

  get '/knowledgeArea' do
    haml :knowledgeArea, :format => :html5
  end

{'fraction_non_alphanumeric': 0.14423963133640552, 'fraction_numerical': 0.010599078341013824, 'mean_word_length': 3.1590038314176243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2919304', 'n_tokens_mistral': 780, 'n_tokens_neox': 734, 'n_words': 224}