mailr/app/controllers/user_controller.rb

76 lines
1.5 KiB
Ruby
Raw Normal View History

2011-07-22 21:58:59 +02:00
class UserController < ApplicationController
2011-07-21 20:20:15 +02:00
2011-07-23 21:55:26 +02:00
theme :theme_resolver
layout "simple"
2011-07-21 20:20:15 +02:00
2011-07-23 21:55:26 +02:00
def login
end
2011-07-21 20:20:15 +02:00
2011-07-23 21:55:26 +02:00
def logout
reset_session
2011-08-16 20:05:58 +02:00
flash[:notice] = t(:logged_out,:scope=>:user)
2011-07-23 21:55:26 +02:00
redirect_to :action => "login"
end
2011-07-21 20:20:15 +02:00
2011-07-23 21:55:26 +02:00
def authenticate
2011-08-26 22:59:43 +02:00
if not $defaults["only_can_logins"].nil?
if not $defaults["only_can_logins"].include?(params[:user][:email])
redirect_to :controller => 'internal', :action => 'onlycanlogins'
return false
end
2011-08-24 19:20:13 +02:00
end
2011-08-26 22:59:43 +02:00
2011-07-24 22:22:13 +02:00
user = User.find_by_email(params[:user][:email])
2011-07-23 21:55:26 +02:00
if user.nil?
2011-07-27 20:34:30 +02:00
redirect_to :action => 'unknown' ,:email=> params[:user][:email]
2011-07-23 21:55:26 +02:00
else
2011-07-29 20:05:47 +02:00
session[:user_id] = user.id
user.set_cached_password(session,params[:user][:password])
2011-07-24 22:22:13 +02:00
2011-07-29 20:05:47 +02:00
if session["return_to"]
redirect_to(session["return_to"])
session["return_to"] = nil
2011-07-23 21:55:26 +02:00
else
2011-08-24 19:20:13 +02:00
redirect_to :controller=> 'messages', :action=> 'index'
2011-07-23 21:55:26 +02:00
end
2011-07-29 20:05:47 +02:00
2011-07-23 21:55:26 +02:00
end
end
2011-07-22 22:57:36 +02:00
2011-07-23 21:55:26 +02:00
def loginfailure
end
def setup
@user = User.new
@server = Server.new
end
def unknown
end
def create
2011-07-27 20:34:30 +02:00
2011-07-23 21:55:26 +02:00
@user = User.new
2011-08-16 20:05:58 +02:00
@user.email = params[:user][:email]
@user.first_name = params[:user][:first_name]
@user.last_name = params[:user][:last_name]
2011-07-27 20:34:30 +02:00
@server = Server.new
2011-08-16 20:05:58 +02:00
@server.name = params[:server][:name]
2011-07-27 20:34:30 +02:00
2011-07-23 21:55:26 +02:00
if @user.valid? and @server.valid?
@user.save
2011-09-03 13:07:40 +02:00
#@server.user_id = @user.id
#@server.save
Prefs.create_default(@user)
Server.create_defaults(@user)
2011-08-16 20:05:58 +02:00
flash[:notice] = t(:setup_done,:scope=>:user)
2011-07-23 21:55:26 +02:00
redirect_to :action => 'login'
else
render "setup"
end
end
2011-07-21 20:20:15 +02:00
end