# encoding: utf-8
#encoding: utf-8
require 'digest/md5'

class LoginController < ApplicationController

  def index
  end

  def login
    user = User.find_by(loginname: params[:loginname])

    if user && User.authenticate(params[:loginname], params[:password])
      log_in user
      user.update_lastlogin
      session[:nojs] = (params[:nojs]=='on')
      redirect_to :controller => params[:goal].blank? ? 'start' : params[:goal]
    else
      flash.notice = "Benutzername oder Passwort nicht korrekt"
      redirect_to :controller => :login, :action => :index
    end
  end

  def logout
    tmp = flash[:notice]
    reset_session
    flash.notice = tmp.nil? ? "Sie wurden erfolgreich ausgeloggt." : tmp
    redirect_to :controller => :login, :action => :index
  end

  def impressum

  end

 end
