start to switch to rails 3.2.2
This commit is contained in:
parent
244942a78f
commit
74c23fa0d1
253 changed files with 648 additions and 17155 deletions
98
app/controllers/application_controller.rb
Executable file → Normal file
98
app/controllers/application_controller.rb
Executable file → Normal file
|
@ -1,99 +1,3 @@
|
|||
require 'yaml'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
|
||||
before_filter :load_defaults,:current_user,:set_locale
|
||||
before_filter :plugins_configuration
|
||||
|
||||
def load_defaults
|
||||
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
end
|
||||
|
||||
################################# protected section ###########################################
|
||||
|
||||
protected
|
||||
|
||||
def theme_resolver
|
||||
if @current_user.nil?
|
||||
$defaults['theme']
|
||||
else
|
||||
@current_user.prefs.theme || $defaults['theme']
|
||||
end
|
||||
end
|
||||
|
||||
def set_locale
|
||||
if @current_user.nil?
|
||||
I18n.locale = $defaults['locale'] || I18n.default_locale
|
||||
else
|
||||
I18n.locale = @current_user.prefs.locale.to_sym || I18n.default_locale
|
||||
end
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
||||
end
|
||||
|
||||
def check_current_user
|
||||
if @current_user.nil?
|
||||
session["return_to"] = request.fullpath
|
||||
redirect_to :controller => 'user', :action => 'login'
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def selected_folder
|
||||
if session[:selected_folder]
|
||||
@selected_folder = session[:selected_folder]
|
||||
else
|
||||
folder = @current_user.folders.inbox.first
|
||||
if not folder.nil?
|
||||
@selected_folder = folder.full_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_current_folders
|
||||
@folders_shown = @current_user.folders.shown.order("name asc")
|
||||
if not @selected_folder.nil?
|
||||
@current_folder = @current_user.folders.find_by_full_name(@selected_folder)
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_compose_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'sendout',:scope=>:compose,:image => 'email.png'}
|
||||
@buttons << {:text => 'save',:scope=>:compose,:image => 'save.png'}
|
||||
end
|
||||
|
||||
def create_message_with_params
|
||||
@message = Message.new(params[:message])
|
||||
# if params[:message]
|
||||
# @message.update_attributes(params[:message])
|
||||
# end
|
||||
files = Dir.glob(File.join($defaults["msg_upload_dir"],@current_user.username + "*"))
|
||||
@attachments = []
|
||||
files.each do |f|
|
||||
@attachments << {:name => File.basename(f).gsub!(/#{@current_user.username}_/,"") , :size => File.stat(f).size }
|
||||
end
|
||||
end
|
||||
|
||||
def get_system_folders
|
||||
@drafts_folder = @current_user.folders.drafts.first
|
||||
@sent_folder = @current_user.folders.sent.first
|
||||
@inbox_folder = @current_user.folders.inbox.first
|
||||
@trash_folder = @current_user.folders.trash.first
|
||||
end
|
||||
|
||||
##################################### private section ##########################################
|
||||
|
||||
private
|
||||
|
||||
def plugins_configuration
|
||||
WillPaginate::ViewHelpers.pagination_options[:previous_label] = t(:previous_page,:scope=>:common)
|
||||
WillPaginate::ViewHelpers.pagination_options[:next_label] = t(:next_page,:scope=>:common)
|
||||
end
|
||||
|
||||
protect_from_forgery
|
||||
end
|
||||
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
require 'tempfile'
|
||||
|
||||
class ContactsController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :get_contacts, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_contact_path)
|
||||
return
|
||||
end
|
||||
if !params["cids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:contact)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["cids"].each do |id|
|
||||
@current_user.contacts.find_by_id(id).destroy
|
||||
end
|
||||
elsif params["compose_to_selected"]
|
||||
redirect_to :controller=>'messages',:action=>'compose',:cids=>params["cids"]
|
||||
return
|
||||
end
|
||||
end
|
||||
redirect_to(contacts_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
# redirect_to(contacts_path)
|
||||
#end
|
||||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@contact = @current_user.contacts.find(params[:id])
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = @current_user.contacts.build(params[:contact])
|
||||
if @contact.valid?
|
||||
@contact.save
|
||||
flash[:notice] = t(:was_created,:scope=>:contact)
|
||||
redirect_to(contacts_path)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@contact = @current_user.contacts.find(params[:id])
|
||||
if @contact.update_attributes(params[:contact])
|
||||
redirect_to(contacts_path)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def external
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"])
|
||||
tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"])
|
||||
tmp_file.write(params[:upload][:datafile].read)
|
||||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect}
|
||||
rescue Exception => e
|
||||
flash[:error] = e.to_s
|
||||
else
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def export
|
||||
contacts = @current_user.contacts
|
||||
s = ""
|
||||
contacts.each do |c|
|
||||
s += c.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="contacts.csv")
|
||||
render :text => s
|
||||
end
|
||||
|
||||
####################################### protected section ################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'compose_to_selected',:scope=> 'contact', :image => 'email.png'}
|
||||
@buttons << {:text => 'create_new',:scope=> 'contact', :image => 'plus.png'}
|
||||
@buttons << {:text => 'delete_selected',:scope=>'contact',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'contact',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'contact',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
||||
def get_contacts
|
||||
@contacts = Contact.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir])
|
||||
end
|
||||
|
||||
end
|
|
@ -1,172 +0,0 @@
|
|||
require 'imap_mailbox'
|
||||
require 'imap_session'
|
||||
|
||||
class FoldersController < ApplicationController
|
||||
|
||||
include ImapMailboxModule
|
||||
include ImapSessionModule
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :open_imap_session, :except => [:index,:show_hide,:system]
|
||||
after_filter :close_imap_session, :except => [:index,:show_hide,:system]
|
||||
|
||||
before_filter :get_folders
|
||||
before_filter :prepare_buttons_to_folders
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
#before_filter
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:folder][:target].empty?
|
||||
flash[:warning] = t(:to_create_empty,:scope=>:folder)
|
||||
render "index"
|
||||
else
|
||||
begin
|
||||
#TODO recreate local copy of folders
|
||||
if params[:folder][:parent].empty?
|
||||
@mailbox.create_folder(params[:folder][:target])
|
||||
else
|
||||
parent_folder = @current_user.folders.find(params[:folder][:parent])
|
||||
if parent_folder.depth >= $defaults["mailbox_max_parent_folder_depth"].to_i
|
||||
raise Exception, t(:max_depth,:scope=>:folder)
|
||||
end
|
||||
@mailbox.create_folder(parent_folder.full_name + parent_folder.delim + params[:folder][:target])
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:can_not_create,:scope=>:folder) + ' (' + e.to_s + ')'
|
||||
render 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_created,:scope=>:folder)
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
if params[:folder][:delete].empty?
|
||||
flash[:warning] = t(:to_delete_empty,:scope=>:folder)
|
||||
render "index"
|
||||
else
|
||||
begin
|
||||
folder = @current_user.folders.find(params[:folder][:delete])
|
||||
if @folders_system.include?(folder)
|
||||
raise Exception, t(:system,:scope=>:folder)
|
||||
end
|
||||
@mailbox.delete_folder(folder.full_name)
|
||||
if @current_folder.eql? folder
|
||||
session[:selected_folder] = nil
|
||||
end
|
||||
folder.destroy
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:can_not_delete,:scope=>:folder) + ' (' + e.to_s + ')'
|
||||
render 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_deleted,:scope=>:folder)
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def system
|
||||
logger.custom('sss',params[:folder].inspect)
|
||||
@folders.each do |f|
|
||||
logger.custom('s',f.inspect)
|
||||
if f.isSystem?
|
||||
f.setNone
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_inbox].to_i
|
||||
f.setInbox
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_sent].to_i
|
||||
f.setSent
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_trash].to_i
|
||||
f.setTrash
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_drafts].to_i
|
||||
f.setDrafts
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def refresh
|
||||
# TODO save system folders
|
||||
if params[:refresh]
|
||||
Folder.refresh(@mailbox,@current_user)
|
||||
flash.keep
|
||||
elsif params[:show_hide]
|
||||
if !params["folders_to_show"].nil?
|
||||
@folders.each do |f|
|
||||
if params["folders_to_show"].include?(f.id.to_s)
|
||||
f.shown = true
|
||||
f.save
|
||||
else
|
||||
f.shown = false
|
||||
f.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def select
|
||||
session[:selected_folder] = params[:id]
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
def refresh_status
|
||||
@folders_shown.each do |f|
|
||||
@mailbox.set_folder(f.full_name)
|
||||
folder_status = @mailbox.status
|
||||
f.update_attributes(:total => folder_status['MESSAGES'], :unseen => folder_status['UNSEEN'])
|
||||
end
|
||||
redirect_to :controller=> 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
def emptybin
|
||||
begin
|
||||
trash_folder = @current_user.folders.trash.first
|
||||
if trash_folder.nil?
|
||||
raise Exception, t(:not_configured_trash,:scope=>:folder)
|
||||
end
|
||||
@mailbox.set_folder(trash_folder.full_name)
|
||||
trash_folder.messages.each do |m|
|
||||
@mailbox.delete_message(m.uid)
|
||||
end
|
||||
@mailbox.expunge
|
||||
trash_folder.messages.destroy_all
|
||||
trash_folder.update_attributes(:unseen => 0, :total => 0)
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error,:scope=>:common)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
|
||||
############################################# protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_buttons_to_folders
|
||||
@buttons = []
|
||||
@buttons << {:text => 'show_hide',:scope=>'folder',:image => 'flag.png'}
|
||||
@buttons << {:text => 'refresh',:scope=>'folder',:image => 'refresh.png'}
|
||||
end
|
||||
|
||||
def get_folders
|
||||
@folders = @current_user.folders
|
||||
@folders_shown = @current_user.folders.shown
|
||||
#@folders_system = @current_user.folders.sys
|
||||
@current_user.folders.inbox.first.nil? ? @folder_inbox = "" : @folder_inbox = @current_user.folders.inbox.first.id
|
||||
@current_user.folders.drafts.first.nil? ? @folder_drafts = "" : @folder_drafts = @current_user.folders.drafts.first.id
|
||||
@current_user.folders.sent.first.nil? ? @folder_sent = "" : @folder_sent = @current_user.folders.sent.first.id
|
||||
@current_user.folders.trash.first.nil? ? @folder_trash = "" : @folder_trash = @current_user.folders.trash.first.id
|
||||
end
|
||||
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
class InternalController < ApplicationController
|
||||
|
||||
before_filter :check_current_user ,:selected_folder, :get_current_folders, :only => [:about]
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
|
||||
ERRORS = [
|
||||
:internal_server_error,
|
||||
:not_found,
|
||||
:unprocessable_entity
|
||||
].freeze
|
||||
|
||||
ERRORS.each do |e|
|
||||
define_method e do
|
||||
@title = t(e,:scope=>:internal)
|
||||
@error = t(e,:scope=>:internal)
|
||||
render 'error'
|
||||
end
|
||||
end
|
||||
|
||||
def error
|
||||
@title = t(:unspecified_error,:scope=>:internal)
|
||||
@error = params[:error] || t(:unspecified_error,:scope=>:internal)
|
||||
end
|
||||
|
||||
def imaperror
|
||||
@title = t(:imap_error,:scope => :internal)
|
||||
@error = params[:error] || t(:unspecified_error, :scope => :internal)
|
||||
logger.error "!!! InternalControllerImapError: " + @error
|
||||
render 'error'
|
||||
end
|
||||
|
||||
def loginfailure
|
||||
reset_session
|
||||
flash[:error] = t(:login_failure,:scope=>:user)
|
||||
@current_user = nil
|
||||
redirect_to :controller=>'user', :action => 'login'
|
||||
end
|
||||
|
||||
def onlycanlogins
|
||||
reset_session
|
||||
flash[:error] = t(:only_can_logins,:scope=>:user)
|
||||
@current_user = nil
|
||||
redirect_to :controller=>'user', :action => 'login'
|
||||
end
|
||||
|
||||
def about
|
||||
render 'internal/about', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
|
@ -1,133 +0,0 @@
|
|||
require 'tempfile'
|
||||
|
||||
class LinksController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :get_links, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :only => [:index]
|
||||
|
||||
#, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_link_path)
|
||||
return
|
||||
end
|
||||
if !params["ids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:link)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["ids"].each do |id|
|
||||
@current_user.links.find_by_id(id).destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to(links_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
# redirect_to(contacts_path)
|
||||
#end
|
||||
|
||||
def new
|
||||
@link = Link.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@link = @current_user.links.find(params[:id])
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def create
|
||||
@link = @current_user.links.build(params[:link])
|
||||
if @link.valid?
|
||||
@link.save
|
||||
flash[:notice] = t(:was_created,:scope=>:link)
|
||||
redirect_to(links_path)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@link = @current_user.links.find(params[:id])
|
||||
if @link.update_attributes(params[:link])
|
||||
redirect_to(links_path)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def external
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"])
|
||||
tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"])
|
||||
tmp_file.write(params[:upload][:datafile].read)
|
||||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect}
|
||||
rescue Exception => e
|
||||
flash[:error] = e.to_s
|
||||
else
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def export
|
||||
contacts = @current_user.contacts
|
||||
s = ""
|
||||
contacts.each do |c|
|
||||
s += c.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="contacts.csv")
|
||||
render :text => s
|
||||
end
|
||||
|
||||
####################################### protected section ################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'create_new',:scope=> 'link', :image => 'plus.png'}
|
||||
@buttons << {:text => 'delete_selected',:scope=>'link',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'link',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'link',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
||||
def get_links
|
||||
@links = Link.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir])
|
||||
end
|
||||
|
||||
end
|
|
@ -1,210 +0,0 @@
|
|||
require 'imap_session'
|
||||
require 'imap_mailbox'
|
||||
require 'imap_message'
|
||||
require 'mail'
|
||||
require 'mail_plugin_extension'
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
|
||||
include ImapMailboxModule
|
||||
include ImapSessionModule
|
||||
include ImapMessageModule
|
||||
include MessagesHelper
|
||||
|
||||
before_filter :check_current_user ,:selected_folder,:get_current_folders
|
||||
before_filter :open_imap_session, :select_imap_folder
|
||||
before_filter :prepare_compose_buttons, :only => [:compose]
|
||||
before_filter :get_system_folders, :only => [:index]
|
||||
before_filter :create_message_with_params, :only => [:compose]
|
||||
before_filter :prepare_multi1_buttons, :only => [:index,:show]
|
||||
before_filter :prepare_multi2_buttons, :only => [:index]
|
||||
before_filter :prepare_multi3_buttons, :only => [:show]
|
||||
after_filter :close_imap_session
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
if @sent_folder.nil? || @drafts_folder.nil? || @inbox_folder.nil? || @trash_folder.nil?
|
||||
flash[:warning] = t(:not_all_configured,:scope => :folder)
|
||||
end
|
||||
|
||||
if @current_folder.nil?
|
||||
flash[:warning] = t(:no_selected,:scope => :folder)
|
||||
redirect_to :controller => 'folders', :action => 'index'
|
||||
return
|
||||
end
|
||||
|
||||
@messages = []
|
||||
|
||||
folder_status = @mailbox.status
|
||||
@current_folder.update_attributes(:total => folder_status['MESSAGES'], :unseen => folder_status['UNSEEN'])
|
||||
|
||||
folder_status['MESSAGES'].zero? ? uids_remote = [] : uids_remote = @mailbox.fetch_uids
|
||||
uids_local = @current_user.messages.where(:folder_id => @current_folder).collect(&:uid)
|
||||
|
||||
logger.custom('current_folder',@current_folder.inspect)
|
||||
logger.custom('uids_local',uids_local.join(","))
|
||||
logger.custom('uids_remote',uids_remote.join(","))
|
||||
logger.custom('to_delete',(uids_local-uids_remote).join(","))
|
||||
logger.custom('to_fetch',(uids_remote-uids_local).join(","))
|
||||
|
||||
(uids_local-uids_remote).each do |uid|
|
||||
@current_folder.messages.find_by_uid(uid).destroy
|
||||
end
|
||||
|
||||
(uids_remote-uids_local).each_slice($defaults["imap_fetch_slice"].to_i) do |slice|
|
||||
messages = @mailbox.uid_fetch(slice, ImapMessageModule::IMAPMessage.fetch_attr)
|
||||
messages.each do |m|
|
||||
Message.createForUser(@current_user,@current_folder,m)
|
||||
end
|
||||
end
|
||||
|
||||
@messages = Message.getPageForUser(@current_user,@current_folder,params[:page],params[:sort_field],params[:sort_dir])
|
||||
|
||||
end
|
||||
|
||||
def compose
|
||||
#before filter :prepare_compose_buttons, :create_message_with_params
|
||||
@operation = :new
|
||||
if params["cid"].present?
|
||||
contact = @current_user.contacts.find_by_id(params["cid"])
|
||||
if not contact.nil?
|
||||
@message.to_addr = contact.email
|
||||
end
|
||||
elsif params["cids"].present?
|
||||
contacts = []
|
||||
params["cids"].each do |c|
|
||||
contact = @current_user.contacts.find_by_id(c)
|
||||
if not contact.nil?
|
||||
contacts << contact.email
|
||||
end
|
||||
end
|
||||
@message.to_addr = contacts.join(';')
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@images = []
|
||||
@attachments = []
|
||||
@text_part = nil
|
||||
@html_part = nil
|
||||
|
||||
@message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:id]).first
|
||||
@message.update_attributes(:unseen => false)
|
||||
imap_message = @mailbox.fetch_body(@message.uid)
|
||||
|
||||
mail = Mail.new(imap_message)
|
||||
@plain_header = mail.header.to_s
|
||||
|
||||
|
||||
# FIXME missing fields and support arrays
|
||||
#@from = mail.From.addrs.presence
|
||||
#@to = mail.To.addrs.presence
|
||||
@from = @message.from_addr
|
||||
@to = @message.to_addr
|
||||
@cc = mail.Cc.presence
|
||||
@bcc = mail.Bcc.presence
|
||||
#@subject = mail.Subject
|
||||
@date = mail.date.presence
|
||||
|
||||
if mail.multipart? == true
|
||||
if not mail.text_part.nil?
|
||||
@text_part = mail.text_part.decoded_and_charseted
|
||||
end
|
||||
if not mail.html_part.nil?
|
||||
@html_part = mail.html_part.decoded_and_charseted
|
||||
end
|
||||
attachments = mail.attachments
|
||||
if not attachments.size.zero?
|
||||
for idx in 0..attachments.size - 1
|
||||
a = attachments[idx]
|
||||
a.idx = idx
|
||||
a.parent_id = @message.uid
|
||||
if a.isImage? and @current_user.prefs.msg_image_view_as.to_sym.eql?(:thumbnail)
|
||||
@images << a
|
||||
else
|
||||
@attachments << a
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
part = Mail::Part.new(mail)
|
||||
part.idx = 0
|
||||
part.parent_id = @message.uid
|
||||
if part.isText?
|
||||
@text_part = part.decoded_and_charseted
|
||||
elsif part.isImage? and @current_user.prefs.msg_image_view_as.to_sym.eql?(:thumbnail)
|
||||
@images << part
|
||||
elsif part.isHtml?
|
||||
@html_part = part.decoded_and_charseted
|
||||
else
|
||||
@attachments << part
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def html_body
|
||||
message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:id]).first
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
if mail.multipart?
|
||||
@body = mail.html_part.decoded_and_charseted
|
||||
else
|
||||
@body = mail.decoded_and_charseted
|
||||
end
|
||||
|
||||
if @body.nil?
|
||||
@body = t(:no_body,:scope=>:message)
|
||||
else
|
||||
if @body=~/cid:([\w@\.]+)/
|
||||
attachments = mail.attachments
|
||||
if not attachments.size.zero?
|
||||
for idx in 0..attachments.size - 1
|
||||
@body.gsub!(/cid:#{attachments[idx].cid}/,attachment_download_path(message.uid,idx))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
render 'html_body',:layout => 'html_body'
|
||||
end
|
||||
|
||||
def attachment
|
||||
attachments = []
|
||||
message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:id]).first
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
if mail.multipart? == true
|
||||
attachments = mail.attachments
|
||||
else
|
||||
attachments << Mail::Part.new(mail)
|
||||
end
|
||||
a = attachments[params[:idx].to_i]
|
||||
headers['Content-type'] = a.main_type + "/" + a.sub_type
|
||||
headers['Content-Disposition'] = %(attachment; filename="#{a.filename}")
|
||||
render :text => a.decoded
|
||||
end
|
||||
|
||||
|
||||
############################################# protected section ##########################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_multi2_buttons
|
||||
@multi2_buttons = []
|
||||
@multi2_buttons << {:text => 'trash',:scope=>:message,:image => 'trash.png'}
|
||||
@multi2_buttons << {:text => 'set_unread',:scope=>:message,:image => 'unseen.png'}
|
||||
@multi2_buttons << {:text => 'set_read',:scope=>:message,:image => 'seen.png'}
|
||||
end
|
||||
|
||||
def prepare_multi1_buttons
|
||||
@multi1_buttons = []
|
||||
@multi1_buttons << {:text => 'copy',:scope=>:message,:image => 'copy.png'}
|
||||
@multi1_buttons << {:text => 'move',:scope=>:message,:image => 'move.png'}
|
||||
end
|
||||
|
||||
def prepare_multi3_buttons
|
||||
@multi3_buttons = []
|
||||
@multi3_buttons << {:text => 'show_header',:scope=>:show,:image => 'zoom.png'}
|
||||
@multi3_buttons << {:text => 'trash',:scope=>:show,:image => 'trash.png'}
|
||||
@multi3_buttons << {:text => 'reply',:scope=>:show,:image => 'reply.png'}
|
||||
end
|
||||
end
|
|
@ -1,354 +0,0 @@
|
|||
require 'imap_session'
|
||||
require 'imap_mailbox'
|
||||
require 'imap_message'
|
||||
require 'mail'
|
||||
require 'mail_plugin_extension'
|
||||
require 'net/smtp'
|
||||
|
||||
class MessagesOpsController < ApplicationController
|
||||
|
||||
include ImapMailboxModule
|
||||
include ImapSessionModule
|
||||
include ImapMessageModule
|
||||
include MessagesHelper
|
||||
|
||||
before_filter :check_current_user ,:selected_folder,:get_current_folders
|
||||
before_filter :open_imap_session, :select_imap_folder
|
||||
before_filter :prepare_compose_buttons
|
||||
before_filter :get_system_folders, :only => [:composed,:single,:multi]
|
||||
before_filter :prepare_composed , :only => [:composed]
|
||||
before_filter :create_message_with_params, :only=> [:composed,:single,:multi]
|
||||
after_filter :close_imap_session
|
||||
theme :theme_resolver
|
||||
|
||||
|
||||
############################################### single #####################################
|
||||
|
||||
def single
|
||||
if params[:reply]
|
||||
reply
|
||||
return
|
||||
elsif params[:trash]
|
||||
trash
|
||||
elsif params[:move]
|
||||
move
|
||||
elsif params[:copy]
|
||||
copy
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
############################################### multi ######################################
|
||||
|
||||
def multi
|
||||
begin
|
||||
if !params[:uids]
|
||||
flash[:warning] = t(:no_selected,:scope=>:message)
|
||||
elsif params[:set_unread]
|
||||
set_unread
|
||||
elsif params[:set_read]
|
||||
set_read
|
||||
elsif params[:trash]
|
||||
trash
|
||||
elsif params[:copy]
|
||||
copy
|
||||
elsif params[:move]
|
||||
move
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error,:scope=>:internal)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
############################################### ################################################
|
||||
|
||||
|
||||
def set_unread
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_unread(uid)
|
||||
@current_user.messages.where('folder_id = ? and uid = ?',@current_folder,uid).first.update_attributes(:unseen => 1)
|
||||
end
|
||||
end
|
||||
|
||||
def set_read
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_read(uid)
|
||||
@current_user.messages.where('folder_id = ? and uid = ?',@current_folder,uid).first.update_attributes(:unseen => 0)
|
||||
end
|
||||
end
|
||||
|
||||
def trash
|
||||
if @trash_folder.nil?
|
||||
flash[:warning] = t(:not_configured_trash, :scope=>:folder)
|
||||
else
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.move_message(uid,@trash_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
message.change_folder(@trash_folder)
|
||||
end
|
||||
@mailbox.expunge
|
||||
@trash_folder.update_stats
|
||||
@current_folder.update_stats
|
||||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
if params[:folder][:target].empty?
|
||||
flash[:warning] = t(:no_selected,:scope=>:folder)
|
||||
else
|
||||
dest_folder = @current_user.folders.find(params[:folder][:target])
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.copy_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
new_message = message.clone
|
||||
new_message.folder_id = dest_folder.id
|
||||
new_message.save
|
||||
end
|
||||
dest_folder.update_stats
|
||||
@current_folder.update_stats
|
||||
end
|
||||
end
|
||||
|
||||
def move
|
||||
if params[:folder][:target].empty?
|
||||
flash[:warning] = t(:no_selected,:scope=>:folder)
|
||||
else
|
||||
dest_folder = @current_user.folders.find(params[:folder][:target])
|
||||
logger.info "DEST: "+dest_folder.inspect
|
||||
params["uids"].each do |uid|
|
||||
logger.info "UID: "+uid
|
||||
logger.info "DEST_FULL: "+dest_folder.full_name
|
||||
@mailbox.move_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
logger.info "M: "+message.inspect
|
||||
logger.info "UPDATE_DEST_BEFORE1: "+dest_folder.inspect
|
||||
message.change_folder(dest_folder)
|
||||
logger.info "UPDATE_DEST_BEFORE2: "+dest_folder.inspect
|
||||
end
|
||||
logger.info "UPDATE_DEST_BEFORE: "+dest_folder.inspect
|
||||
@mailbox.expunge
|
||||
dest_folder.update_stats
|
||||
logger.info "UPDATE_DEST: "+dest_folder.inspect
|
||||
@current_folder.update_stats
|
||||
logger.info "UPDATE_CUT: "+@current_folder.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def upload
|
||||
begin
|
||||
raise MailrException.new :cause=>:no_tmp_dir,:scope=>:common if not File.exists?($defaults["msg_upload_dir"])
|
||||
raise MailrException.new :cause=>:no_file_chosen,:scope=>:common if not params[:upload]
|
||||
@operation = :upload
|
||||
name = params[:file][:data].original_filename
|
||||
upload_dir = $defaults["msg_upload_dir"]
|
||||
path = File.join(upload_dir, @current_user.username + "_" + name)
|
||||
File.open(path, "wb") { |f| f.write(params[:file][:data].read) }
|
||||
rescue MailrException => e
|
||||
flash[:error] = t(e.message[:cause],:scope => e.message[:scope])
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:general_error,:scope=>:internal) + " (" + e.class.name + " " + e.to_s + ")"
|
||||
end
|
||||
create_message_with_params
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
# Files uploaded from Internet Explorer:
|
||||
#
|
||||
#Internet Explorer includes the entire path of a file in the filename sent, so the original_filename routine will return something like:
|
||||
#
|
||||
#C:\Documents and Files\user_name\Pictures\My File.jpg
|
||||
#
|
||||
#instead of just:
|
||||
#
|
||||
#My File.jpg
|
||||
#
|
||||
#This is easily handled by File.basename, which strips out everything before the filename.
|
||||
#
|
||||
#def sanitize_filename(file_name)
|
||||
# # get only the filename, not the whole path (from IE)
|
||||
# just_filename = File.basename(file_name)
|
||||
# # replace all none alphanumeric, underscore or perioids
|
||||
# # with underscore
|
||||
# just_filename.sub(/[^\w\.\-]/,'_')
|
||||
#end
|
||||
#
|
||||
#Deleting an existing File:
|
||||
#
|
||||
#If you want to delete any existing file then its simple and need to write following code:
|
||||
#
|
||||
# def cleanup
|
||||
# File.delete("#{RAILS_ROOT}/dirname/#{@filename}")
|
||||
# if File.exist?("#{RAILS_ROOT}/dirname/#{@filename}")
|
||||
# end
|
||||
|
||||
def composed
|
||||
if params[:delete_marked] and params[:files]
|
||||
params[:files].each do |filename|
|
||||
path = File.join(Rails.root,$defaults["msg_upload_dir"],@current_user.username + "_" +filename)
|
||||
File.delete(path) if File.exist?(path)
|
||||
end
|
||||
create_message_with_params
|
||||
@operation = :new
|
||||
render 'messages/compose'
|
||||
return
|
||||
elsif params[:upload]
|
||||
upload
|
||||
elsif params[:save]
|
||||
save
|
||||
elsif params[:sendout]
|
||||
sendout
|
||||
else
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def sendout
|
||||
begin
|
||||
smtp_server = @current_user.servers.primary_for_smtp
|
||||
raise MailrException.new :cause=>:not_configured_smtp,:scope => :compose if smtp_server.nil?
|
||||
raise MailrException.new :cause=>:has_no_domain,:scope=>:user if @current_user.has_domain?.nil?
|
||||
raise MailrException.new :cause=>:not_configured_sent,:scope=>:compose if @sent_folder.nil?
|
||||
send_mail_message( smtp_server,
|
||||
@current_user.has_domain?,
|
||||
@current_user.login,
|
||||
@current_user.get_cached_password(session),
|
||||
@mail.to_s,
|
||||
@current_user.email,
|
||||
params[:message][:to_addr]
|
||||
)
|
||||
@mailbox.append(@sent_folder.full_name,@mail.to_s,[:Seen])
|
||||
upload_dir = $defaults["msg_upload_dir"]
|
||||
@attachments.each do |file|
|
||||
path = File.join(upload_dir, @current_user.username + "_" + file[:name])
|
||||
File.delete(path) if File.exist?(path)
|
||||
end
|
||||
rescue MailrException => e
|
||||
flash[:error] = t(e.message[:cause],:scope => e.message[:scope])
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:general_error,:scope=>:internal) + " (" + e.class.name + " " + e.to_s + ")"
|
||||
else
|
||||
flash[:notice] = t(:was_sent,:scope => :compose)
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
return
|
||||
end
|
||||
@operation = :new
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
def save
|
||||
begin
|
||||
raise MailrException.new :cause=>:not_configured_drafts,:scope=>:folder if @drafts_folder.nil?
|
||||
@mailbox.append(@drafts_folder.full_name,@mail.to_s,[:Seen])
|
||||
if params[:olduid].present?
|
||||
@mailbox.move_message(params[:olduid],@trash_folder.full_name)
|
||||
@mailbox.expunge
|
||||
end
|
||||
rescue MailrException => e
|
||||
flash[:error] = t(e.message[:cause],:scope => e.message[:scope])
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:general_error,:scope=>:internal) + " (" + e.class.name + " " + e.to_s + ")"
|
||||
else
|
||||
@attachments.each do |filename|
|
||||
path = File.join(Rails.root,filename)
|
||||
File.delete(path) if File.exist?(path)
|
||||
end
|
||||
flash[:notice] = t(:was_saved,:scope => :compose)
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
#FIXME edit does not support attachments
|
||||
def edit
|
||||
old_message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:uids].first).first
|
||||
@message = Message.new
|
||||
@message.to_addr = old_message.to_addr
|
||||
@message.subject = old_message.subject
|
||||
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.nil? ? "" : mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
end
|
||||
@attachments = []
|
||||
@operation = :edit
|
||||
@olduid = old_message.uid
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
def reply
|
||||
old_message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:uids].first).first
|
||||
@message = Message.new
|
||||
@message.to_addr = old_message.from_addr
|
||||
@message.subject = old_message.subject
|
||||
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.nil? ? "" : mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
end
|
||||
@attachments = []
|
||||
@operation = :reply
|
||||
render 'messages/compose'
|
||||
end
|
||||
###################################### protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
def send_mail_message(smtp_server,domain,username,password,msgstr,from,to)
|
||||
if smtp_server.auth.nil?
|
||||
smtp = Net::SMTP.start(smtp_server.name, smtp_server.port, domain)
|
||||
else
|
||||
smtp = Net::SMTP.start(smtp_server.name, smtp_server.port, domain, username, password, smtp_server.auth)
|
||||
end
|
||||
smtp.send_message msgstr, from, to
|
||||
smtp.finish
|
||||
end
|
||||
|
||||
def prepare_composed
|
||||
@mail = Mail.new
|
||||
@mail.subject = params[:message][:subject]
|
||||
@mail.from = @current_user.full_id
|
||||
#TODO check if email address is valid if not get address from contacts
|
||||
@mail.to = params[:message][:to_addr]
|
||||
@mail.body = params[:message][:body]
|
||||
@attachments = Dir.glob(File.join($defaults["msg_upload_dir"],@current_user.username + "*"))
|
||||
@attachments.each do |a|
|
||||
@mail.add_file :filename => File.basename(a.gsub(/#{@current_user.username}_/,"")), :content => File.read(a)
|
||||
end
|
||||
end
|
||||
|
||||
############################################ set_mail_defaults ####################################
|
||||
|
||||
def set_mail_defaults(user,server,session)
|
||||
if server.auth.nil? or server.auth == 'none'
|
||||
password = nil
|
||||
authentication = nil
|
||||
enable_starttls_auto = nil
|
||||
openssl_verify_mode = nil
|
||||
user_name = nil
|
||||
else
|
||||
password = user.get_cached_password(session)
|
||||
authentication = server.auth
|
||||
enable_starttls_auto = server.use_tls
|
||||
openssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
user_name = user.login
|
||||
end
|
||||
Mail.defaults do
|
||||
delivery_method :smtp, {:address => server.name,
|
||||
:port => server.port,
|
||||
:domain => user.domain,
|
||||
:user_name => user_name,
|
||||
:password => password,
|
||||
:authentication => authentication,
|
||||
:enable_starttls_auto => enable_starttls_auto,
|
||||
:openssl_verify_mode => openssl_verify_mode
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
class PrefsController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder
|
||||
|
||||
before_filter :get_current_folders
|
||||
|
||||
before_filter :get_prefs, :only => [:look,:update_look]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def update_look
|
||||
if params[:prefs]
|
||||
@prefs.update_attributes(params[:prefs])
|
||||
end
|
||||
flash[:notice] = t(:were_saved,:scope=>:prefs)
|
||||
redirect_to :action => 'look'
|
||||
end
|
||||
|
||||
def update_servers
|
||||
|
||||
redirect_to :action => 'servers'
|
||||
end
|
||||
|
||||
def update_identity
|
||||
if params[:user]
|
||||
@current_user.first_name = params[:user][:first_name]
|
||||
@current_user.last_name = params[:user][:last_name]
|
||||
@current_user.domain = params[:user][:domain]
|
||||
if @current_user.valid?
|
||||
@current_user.save
|
||||
flash[:notice] = t(:were_saved,:scope=>:prefs)
|
||||
redirect_to :action => 'identity'
|
||||
else
|
||||
render 'prefs/identity'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def look
|
||||
|
||||
end
|
||||
|
||||
def identity
|
||||
end
|
||||
|
||||
def servers
|
||||
@servers = @current_user.servers
|
||||
end
|
||||
|
||||
############################# protected section ##################################
|
||||
|
||||
def get_prefs
|
||||
@prefs = @current_user.prefs
|
||||
end
|
||||
end
|
|
@ -1,75 +0,0 @@
|
|||
class UserController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
def login
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash[:notice] = t(:logged_out,:scope=>:user)
|
||||
redirect_to :action => "login"
|
||||
end
|
||||
|
||||
def authenticate
|
||||
|
||||
if not $defaults["only_can_logins"].nil?
|
||||
if not $defaults["only_can_logins"].include?(params[:user][:login])
|
||||
redirect_to :controller => 'internal', :action => 'onlycanlogins'
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
user = User.find_by_login(params[:user][:login])
|
||||
if user.nil?
|
||||
redirect_to :action => 'unknown' ,:login=> params[:user][:login]
|
||||
else
|
||||
session[:user_id] = user.id
|
||||
user.set_cached_password(session,params[:user][:password])
|
||||
|
||||
if session["return_to"]
|
||||
redirect_to(session["return_to"])
|
||||
session["return_to"] = nil
|
||||
else
|
||||
redirect_to :controller=> 'messages', :action=> 'index'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def loginfailure
|
||||
end
|
||||
|
||||
def setup
|
||||
@user = User.new
|
||||
@server = Server.new
|
||||
end
|
||||
|
||||
def unknown
|
||||
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]
|
||||
|
||||
@server = Server.new
|
||||
@server.name = params[:server][:name]
|
||||
|
||||
if @user.valid? and @server.valid?
|
||||
@user.save
|
||||
#@server.user_id = @user.id
|
||||
#@server.save
|
||||
Prefs.create_default(@user)
|
||||
Server.create_defaults(@user)
|
||||
flash[:notice] = t(:setup_done,:scope=>:user)
|
||||
redirect_to :action => 'login'
|
||||
else
|
||||
render "setup"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue