alchemy_cms 2.0.rc1 → 2.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/messages_controller.rb +63 -46
- data/app/mailers/messages.rb +3 -3
- data/app/models/message.rb +21 -9
- data/app/views/messages/contact_form_mail.html.erb +14 -0
- data/app/views/messages/contact_form_mail.text.erb +10 -0
- data/config/alchemy/config.yml +1 -0
- data/config/routes.rb +5 -4
- data/lib/alchemy/version.rb +1 -1
- metadata +5 -4
- data/app/views/messages/mail.text.erb +0 -10
@@ -1,7 +1,7 @@
|
|
1
1
|
# == Sending Messages:
|
2
2
|
# To send Messages via contact forms you can create your form fields in the config.yml
|
3
3
|
# === Example:
|
4
|
-
# Make an Element with this options inside your elements.yml file:
|
4
|
+
# Make an Element with this options inside your @elements.yml file:
|
5
5
|
#
|
6
6
|
# - name: contact
|
7
7
|
# display_name: Kontaktformular
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# type: EssenceText
|
17
17
|
#
|
18
18
|
# The fields mail_to, mail_from, subject and success_page are recommended.
|
19
|
-
# The MessagesController uses them to send your mails. So your customer has full controll of these values inside his contactform element.
|
19
|
+
# The MessagesController uses them to send your mails. So your customer has full controll of these values inside his contactform @element.
|
20
20
|
#
|
21
21
|
# Then make a page layout for your contact page in the page_layouts.yml file:
|
22
22
|
#
|
@@ -24,73 +24,90 @@
|
|
24
24
|
# display_name: Kontakt
|
25
25
|
# unique: true
|
26
26
|
# cache: false
|
27
|
-
# elements: [pageheading, heading, contact, bild, absatz, file_download]
|
27
|
+
# @elements: [pageheading, heading, contact, bild, absatz, file_download]
|
28
28
|
# autogenerate: [contact]
|
29
29
|
#
|
30
30
|
# Disabling the page caching is stronlgy recommended!
|
31
31
|
#
|
32
|
-
# The editor view for your element should have this layout:
|
32
|
+
# The editor view for your @element should have this layout:
|
33
33
|
#
|
34
|
-
# <%= render_essence_editor_by_name(element, 'mail_from') %>
|
35
|
-
# <%= render_essence_editor_by_name(element, 'mail_to') %>
|
36
|
-
# <%= render_essence_editor_by_name(element, 'subject') %>
|
34
|
+
# <%= render_essence_editor_by_name(@element, 'mail_from') %>
|
35
|
+
# <%= render_essence_editor_by_name(@element, 'mail_to') %>
|
36
|
+
# <%= render_essence_editor_by_name(@element, 'subject') %>
|
37
37
|
# <p>
|
38
|
-
# Folgeseite: <%= page_selector(element, 'success_page') %>
|
38
|
+
# Folgeseite: <%= page_selector(@element, 'success_page') %>
|
39
39
|
# </p>
|
40
40
|
#
|
41
|
-
# Please have a look at the
|
41
|
+
# Please have a look at the alchemy/config/config.yml file for further Message settings.
|
42
42
|
|
43
43
|
class MessagesController < AlchemyController
|
44
44
|
|
45
|
+
before_filter :get_page, :except => :create
|
46
|
+
|
45
47
|
helper :pages
|
46
48
|
|
49
|
+
def index#:nodoc:
|
50
|
+
redirect_to show_page_path(:urlname => @page.urlname, :lang => multi_language? ? @page.language_code : nil)
|
51
|
+
end
|
52
|
+
|
47
53
|
def new#:nodoc:
|
48
54
|
@message = Message.new
|
49
|
-
@page = Page.find_by_page_layout(Alchemy::Config.get(:mailer)[:form_layout_name])
|
50
|
-
@root_page = Page.language_root_for(session[:language_id])
|
51
|
-
raise "Page for page_layout #{configuration(:mailer)[:page_layout_name]} not found" if @page.blank?
|
52
55
|
render :template => '/pages/show', :layout => 'pages'
|
53
56
|
end
|
54
57
|
|
55
|
-
def index#:nodoc:
|
56
|
-
@page = Page.find_by_page_layout(configuration(:mailer)[:page_layout_name])
|
57
|
-
raise "Page for page_layout #{configuration(:mailer)[:page_layout_name]} not found" if @page.blank?
|
58
|
-
redirect_to send("show_page#{multi_language? ? '_with_language' : '' }_path", :urlname => @page.urlname, :lang => multi_language? ? @page.language_code : nil)
|
59
|
-
end
|
60
|
-
|
61
58
|
def create#:nodoc:
|
62
|
-
@message = Message.new(params[:
|
63
|
-
@
|
64
|
-
|
65
|
-
@page = element.page
|
59
|
+
@message = Message.new(params[:message].merge(:ip => request.remote_ip))
|
60
|
+
@element = Element.find_by_id(@message.contact_form_id)
|
61
|
+
@page = @element.page
|
66
62
|
@root_page = @page.get_language_root
|
67
|
-
if @message.
|
68
|
-
|
69
|
-
|
70
|
-
else
|
71
|
-
mail_to = Alchemy::Config.get(:mailer)[:mail_addresses].detect{ |c| c[0] == params[:mail_to] }[1]
|
72
|
-
end
|
73
|
-
mail_from = element.ingredient("mail_from") rescue configuration(:mailer)[:mail_from]
|
74
|
-
subject = element.ingredient("subject") rescue configuration(:mailer)[:subject]
|
75
|
-
|
76
|
-
Messages.mail(@message, mail_to, mail_from, subject).deliver
|
77
|
-
|
78
|
-
if element.ingredient("success_page")
|
79
|
-
if multi_language?
|
80
|
-
language = Language.find(session[:language_id])
|
81
|
-
redirect_to show_page_url(:urlname => element.ingredient("success_page"), :lang => language.code)
|
82
|
-
else
|
83
|
-
redirect_to show_page_url(:urlname => element.ingredient("success_page"))
|
84
|
-
end
|
85
|
-
elsif configuration(:mailer)[:forward_to_page] && configuration(:mailer)[:mail_success_page]
|
86
|
-
redirect_to :controller => 'pages', :action => 'show', :urlname => Page.find_by_urlname(configuration(:mailer)[:mail_success_page]).urlname
|
87
|
-
else
|
88
|
-
flash[:notice] = I18n.t('alchemy.contactform.messages.success')
|
89
|
-
redirect_to :controller => 'pages', :action => 'show', :urlname => Page.language_root_for(session[:language_id]).urlname
|
90
|
-
end
|
63
|
+
if @message.valid?
|
64
|
+
Messages.contact_form_mail(@message, mail_to, mail_from, subject).deliver
|
65
|
+
redirect_to_success_page
|
91
66
|
else
|
92
67
|
render :template => '/pages/show', :layout => 'pages'
|
93
68
|
end
|
94
69
|
end
|
95
70
|
|
71
|
+
private
|
72
|
+
|
73
|
+
def mailer_config
|
74
|
+
Alchemy::Config.get(:mailer)
|
75
|
+
end
|
76
|
+
|
77
|
+
def mail_to
|
78
|
+
@element.ingredient("mail_to")
|
79
|
+
rescue
|
80
|
+
mailer_config[:mail_to]
|
81
|
+
end
|
82
|
+
|
83
|
+
def mail_from
|
84
|
+
@element.ingredient("mail_from")
|
85
|
+
rescue
|
86
|
+
mailer_config[:mail_from]
|
87
|
+
end
|
88
|
+
|
89
|
+
def subject
|
90
|
+
@element.ingredient("subject")
|
91
|
+
rescue
|
92
|
+
mailer_config[:subject]
|
93
|
+
end
|
94
|
+
|
95
|
+
def redirect_to_success_page
|
96
|
+
if @element.ingredient("success_page")
|
97
|
+
urlname = @element.ingredient("success_page")
|
98
|
+
elsif mailer_config[:forward_to_page] && mailer_config[:mail_success_page]
|
99
|
+
urlname = Page.find_by_urlname(mailer_config[:mail_success_page]).urlname
|
100
|
+
else
|
101
|
+
flash[:notice] = I18n.t('alchemy.contactform.messages.success')
|
102
|
+
urlname = Page.language_root_for(session[:language_id]).urlname
|
103
|
+
end
|
104
|
+
redirect_to show_page_path(:urlname => urlname, :lang => multi_language? ? session[:language_code] : nil)
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_page
|
108
|
+
@page = Page.find_by_page_layout(mailer_config[:form_layout_name])
|
109
|
+
@root_page = @page.get_language_root
|
110
|
+
raise "Page for page_layout #{mailer_config[:page_layout_name]} not found" if @page.blank?
|
111
|
+
end
|
112
|
+
|
96
113
|
end
|
data/app/mailers/messages.rb
CHANGED
@@ -2,12 +2,12 @@ class Messages < ActionMailer::Base
|
|
2
2
|
|
3
3
|
default :from => Alchemy::Config.get(:mailer)[:mail_from]
|
4
4
|
|
5
|
-
def
|
6
|
-
@
|
5
|
+
def contact_form_mail(message, mail_to, mail_from, subject)
|
6
|
+
@message = message
|
7
7
|
mail(
|
8
8
|
:from => mail_from,
|
9
9
|
:to => mail_to,
|
10
|
-
:reply_to =>
|
10
|
+
:reply_to => message.email,
|
11
11
|
:subject => subject
|
12
12
|
)
|
13
13
|
end
|
data/app/models/message.rb
CHANGED
@@ -31,23 +31,35 @@
|
|
31
31
|
# :message: blank_email
|
32
32
|
|
33
33
|
class Message
|
34
|
-
|
34
|
+
|
35
|
+
@@config = Alchemy::Config.get(:mailer)
|
36
|
+
|
37
|
+
extend ActiveModel::Naming
|
35
38
|
include ActiveModel::Validations
|
36
|
-
|
39
|
+
include ActiveModel::Conversion
|
40
|
+
|
37
41
|
attr_accessor :contact_form_id, :ip
|
38
|
-
|
39
|
-
Alchemy::Config.get(:mailer)[:fields].each do |field|
|
42
|
+
@@config[:fields].each do |field|
|
40
43
|
attr_accessor field.to_sym
|
41
44
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
validates_presence_of field[0], :message => I18n.t("alchemy.contactform.validations.#{field[1][:message].to_s}")
|
45
|
+
|
46
|
+
@@config[:validate_fields].each do |field|
|
47
|
+
validates_presence_of field[0], :message => '^' + I18n.t(field[1][:message].to_s, :scope => "alchemy.contactform.validations")
|
46
48
|
if field[0].to_s.include?('email')
|
47
|
-
validates_format_of field[0], :with => Authlogic::Regex.email, :message => I18n.t('alchemy.contactform.validations.wrong_email_format'), :if => :email_is_filled
|
49
|
+
validates_format_of field[0], :with => Authlogic::Regex.email, :message => '^' + I18n.t('alchemy.contactform.validations.wrong_email_format'), :if => :email_is_filled
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
53
|
+
def initialize(attributes = {})
|
54
|
+
attributes.keys.each do |a|
|
55
|
+
send("#{a}=", attributes[a])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def persisted? #:nodoc:
|
60
|
+
false
|
61
|
+
end
|
62
|
+
|
51
63
|
private
|
52
64
|
|
53
65
|
def email_is_filled #:nodoc:
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<pre>
|
2
|
+
<%= @message.message %>
|
3
|
+
</pre>
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<%= @message.salutation %><br>
|
7
|
+
<%= @message.firstname %> <%= @message.lastname %><br>
|
8
|
+
<br>
|
9
|
+
<%= @message.address %><br>
|
10
|
+
<%= @message.zip %> <%= @message.city %><br>
|
11
|
+
<br>
|
12
|
+
<%= @message.phone %><br>
|
13
|
+
<%= @message.email %>
|
14
|
+
</p>
|
data/config/alchemy/config.yml
CHANGED
@@ -94,6 +94,7 @@ default_language:
|
|
94
94
|
:forward_to_page: false
|
95
95
|
:mail_success_page: thanks
|
96
96
|
:mail_from: your.mail@your-domain.com
|
97
|
+
:mail_to: your.mail@your-domain.com
|
97
98
|
:fields: [salutation, firstname, lastname, address, zip, city, phone, email, message]
|
98
99
|
:validate_fields:
|
99
100
|
:lastname:
|
data/config/routes.rb
CHANGED
@@ -2,6 +2,8 @@ Rails.application.routes.draw do
|
|
2
2
|
|
3
3
|
root :to => 'pages#show'
|
4
4
|
|
5
|
+
resources :messages, :only => [:index, :new, :create]
|
6
|
+
|
5
7
|
match '/admin' => 'admin#index',
|
6
8
|
:as => :admin
|
7
9
|
match '/admin/login' => 'admin#login',
|
@@ -35,8 +37,7 @@ Rails.application.routes.draw do
|
|
35
37
|
|
36
38
|
resources :user_sessions
|
37
39
|
resources :elements, :only => :show
|
38
|
-
|
39
|
-
|
40
|
+
|
40
41
|
namespace :admin do
|
41
42
|
|
42
43
|
resources :users
|
@@ -119,7 +120,7 @@ Rails.application.routes.draw do
|
|
119
120
|
|
120
121
|
resources :languages
|
121
122
|
|
122
|
-
# OHOHOH lovely Rails! Why, oh why I
|
123
|
+
# OHOHOH lovely Rails! Why, oh why I always have to hack thou?
|
123
124
|
resource :clipboard, :only => :index, :controller => 'clipboard' do
|
124
125
|
collection do
|
125
126
|
get :index
|
@@ -129,7 +130,7 @@ Rails.application.routes.draw do
|
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
132
|
-
# OHOHOH lovely Rails! Why, oh why I
|
133
|
+
# OHOHOH lovely Rails! Why, oh why I always have to hack thou?
|
133
134
|
resource :trash, :only => :index, :controller => 'trash' do
|
134
135
|
collection do
|
135
136
|
get :index
|
data/lib/alchemy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alchemy_cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424193
|
5
5
|
prerelease: 4
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
9
|
- rc
|
10
|
-
-
|
11
|
-
version: 2.0.
|
10
|
+
- 2
|
11
|
+
version: 2.0.rc2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Thomas von Deyen
|
@@ -523,7 +523,8 @@ files:
|
|
523
523
|
- app/views/layouts/login.html.erb
|
524
524
|
- app/views/layouts/pages.html.erb
|
525
525
|
- app/views/layouts/sitemap.xml.erb
|
526
|
-
- app/views/messages/
|
526
|
+
- app/views/messages/contact_form_mail.html.erb
|
527
|
+
- app/views/messages/contact_form_mail.text.erb
|
527
528
|
- app/views/messages/new.html.erb
|
528
529
|
- app/views/notifications/admin_user_created.text.erb
|
529
530
|
- app/views/notifications/registered_user_created.text.erb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
<%= @mail_data[:message] %>
|
2
|
-
|
3
|
-
--
|
4
|
-
|
5
|
-
<%= @mail_data[:salutation] %>
|
6
|
-
<%= @mail_data[:firstname] %> <%= @mail_data[:lastname] %>
|
7
|
-
<%= @mail_data[:address] %>
|
8
|
-
<%= @mail_data[:zip] %> <%= @mail_data[:city] %>
|
9
|
-
<%= @mail_data[:phone] %>
|
10
|
-
<%= @mail_data[:email] %>
|