diff --git a/app/controllers/contact_controller.rb b/app/controllers/contact_controller.rb index ddc2203..b3108c4 100644 --- a/app/controllers/contact_controller.rb +++ b/app/controllers/contact_controller.rb @@ -1,7 +1,14 @@ # coding: utf-8 class ContactController < ApplicationController +# skip_before_action :check_xhr, raise: false + skip_before_action :check_xhr, + #:verify_authenticity_token, + #:redirect_to_login_if_required, + raise: false + + def index - Rails.logger.info '🚂 Called the `NotebookController#index` method.' + Rails.logger.info '🚂 Called the `ContactController#index` method.' end end diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index da5175b..174e5ad 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -1,4 +1,11 @@ class ContactsController < ApplicationController + + skip_before_action :check_xhr, + :verify_authenticity_token, + :redirect_to_login_if_required, + raise: false + + def index Rails.logger.info 'Called ContactsController#index' contacts = ContactStore.get_contacts() @@ -21,15 +28,22 @@ def update ContactStore.add_contact(contact_id, contact) - @date=Time.now.strftime('%a, %-d %b %Y %H:%M:%S %z') + @date=Time.now.strftime('%a, %-d %b %Y %H:%M:%S') @mail=" Date: #{@date} -From: #{contact['email']} +From: #{contact['email'] || "unknown@example.com"} To: jons-biography@beta.buildcivitas.com -Subject: #{contact['name']} - #{@date} +Subject: Contact from #{contact['name']} - #{@date} + + +Name: #{contact['name']} +Phone: #{contact['phone']} +Email: #{contact['email']} + +Message: -#{contact['message']}" +> #{contact['message']}" Mail.new(@mail).message_id.presence diff --git a/assets/javascripts/discourse/components/contact-form.hbs b/assets/javascripts/discourse/components/contact-form.hbs new file mode 100644 index 0000000..b920a42 --- /dev/null +++ b/assets/javascripts/discourse/components/contact-form.hbs @@ -0,0 +1,25 @@ +
diff --git a/assets/javascripts/discourse/components/contact-form.js b/assets/javascripts/discourse/components/contact-form.js new file mode 100644 index 0000000..a670834 --- /dev/null +++ b/assets/javascripts/discourse/components/contact-form.js @@ -0,0 +1,47 @@ +import Component from '@ember/component'; +import Controller from '@ember/controller'; + +export default Component.extend({ + init() { + this._super(); + this.set('contacts', []); + this.fetchContacts(); + }, + + fetchContacts() { + this.store.findAll('contact') + .then(result => { + for (const contact of result.content) { + this.contacts.pushObject(contact); + } + }) + .catch(console.error); + }, + + actions: { + createContact(name, email, phone, message) { + + const contactRecord = this.store.createRecord('contact', { + id: Date.now(), + name: name, + email: email, + phone: phone, + message: message + }); + + contactRecord.save() + .then(result => { + this.contacts.pushObject(result.target); + }) + .catch(console.error); + }, + + deleteContact(contact) { + this.store.destroyRecord('contact', contact) + .then(() => { + this.contacts.removeObject(contact); + }) + .catch(console.error); + } + } +}) diff --git a/assets/javascripts/discourse/components/hello.hbs b/assets/javascripts/discourse/components/hello.hbs new file mode 100644 index 0000000..3b2634d --- /dev/null +++ b/assets/javascripts/discourse/components/hello.hbs @@ -0,0 +1 @@ +