app/controllers/application_controller.rb
5fa8b94d
 class ApplicationController < ActionController::Base
7aef87db
 
120b99ea
 	before_filter :require_login
7aef87db
 
 	def require_login
 		if authenticated?
 			create_new_authentification()
 		else
120b99ea
 			unless controller_name == 'sessions' && (action_name == 'new' || action_name == 'create')
31d1a3aa
                 redirect_to root_url, flash: {error: I18n.t('login.access-denied')}
120b99ea
 			end
7aef87db
 		end
 	end
 
 	protected
 
 	def authenticated?
 		!! Token.authenticate(session)
 	end
 
 	def create_new_authentification
 		Token.remove_old_session(session[:token])
 
 		session[:token] = Token.generate_token()
 		session[:created_at] = Time.now
 		session[:ip] = request.remote_ip
 
 		Token.save_session(session)
 	end
5fa8b94d
 end