2012-03-10 18:08:39 +01:00
|
|
|
class UserController < ApplicationController
|
|
|
|
|
|
|
|
#theme :theme_resolver
|
|
|
|
layout "simple"
|
|
|
|
|
|
|
|
def login
|
2012-03-24 13:23:34 +01:00
|
|
|
# database empty redirect to setup screen
|
|
|
|
users = User.all
|
|
|
|
if users.count.zero?
|
|
|
|
redirect_to :controller => 'user', :action => 'setup'
|
|
|
|
return false
|
|
|
|
end
|
2012-03-10 18:08:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def logout
|
|
|
|
reset_session
|
|
|
|
flash[:success] = t(:logged_out,:scope=>:user)
|
|
|
|
redirect_to :action => "login"
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate
|
2012-03-10 21:03:56 +01:00
|
|
|
|
2012-03-24 13:23:34 +01:00
|
|
|
# check if user can use application
|
2012-03-10 21:03:56 +01:00
|
|
|
if not $defaults["only_can_logins"].nil?
|
|
|
|
if not $defaults["only_can_logins"].include?(params[:user][:login])
|
2012-03-24 13:23:34 +01:00
|
|
|
flash[:error] = t(:only_can_logins,:scope=>:user)
|
|
|
|
redirect_to :action => 'login'
|
2012-03-10 21:03:56 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2012-03-10 18:08:39 +01:00
|
|
|
|
|
|
|
user = User.find_by_login(params[:user][:login])
|
|
|
|
if user.nil?
|
2012-03-24 13:23:34 +01:00
|
|
|
|
|
|
|
flash[:error] = t(:login_failure,:scope=>:user)
|
|
|
|
redirect_to :action => 'login'
|
|
|
|
return false
|
|
|
|
|
2012-03-10 18:08:39 +01:00
|
|
|
else
|
2012-03-24 13:23:34 +01:00
|
|
|
|
|
|
|
session[:user_id] = user.id
|
2012-03-10 18:08:39 +01:00
|
|
|
user.set_cached_password(session,params[:user][:password])
|
|
|
|
|
|
|
|
if session["return_to"]
|
2012-03-24 13:23:34 +01:00
|
|
|
redirect = session["return_to"]
|
2012-03-10 18:08:39 +01:00
|
|
|
session["return_to"] = nil
|
2012-03-24 13:23:34 +01:00
|
|
|
redirect_to(redirect)
|
2012-03-10 18:08:39 +01:00
|
|
|
else
|
|
|
|
redirect_to :controller=> 'messages', :action=> 'index'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-24 13:23:34 +01:00
|
|
|
#def loginfailure
|
|
|
|
#end
|
2012-03-10 18:08:39 +01:00
|
|
|
|
|
|
|
def setup
|
2012-03-24 13:23:34 +01:00
|
|
|
users = User.all
|
|
|
|
if !users.count.zero?
|
|
|
|
redirect_to :controller => 'internal', :action => 'allready_configured'
|
|
|
|
return false
|
|
|
|
end
|
2012-03-10 18:08:39 +01:00
|
|
|
@user = User.new
|
|
|
|
@server = Server.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
@user = User.new
|
|
|
|
@user.login = params[:user][:login]
|
|
|
|
@user.first_name = params[:user][:first_name]
|
|
|
|
@user.last_name = params[:user][:last_name]
|
|
|
|
|
2012-03-24 13:23:34 +01:00
|
|
|
@server = Server.new
|
2012-03-10 18:08:39 +01:00
|
|
|
@server.name = params[:server][:name]
|
|
|
|
|
|
|
|
if @user.valid? and @server.valid?
|
|
|
|
@user.save
|
|
|
|
#@server.user_id = @user.id
|
|
|
|
#@server.save
|
|
|
|
Prefs.create_default(@user)
|
2012-03-24 18:09:31 +01:00
|
|
|
Server.create_server(@user,@server.name)
|
2012-03-10 18:08:39 +01:00
|
|
|
flash[:success] = t(:setup_done,:scope=>:user)
|
|
|
|
redirect_to :action => 'login'
|
|
|
|
else
|
|
|
|
render "setup"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|