Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.7 KiB
Ruby
64 lines
1.7 KiB
Ruby
class MailIdentitiesController < ApplicationController
|
|
before_action :require_admin
|
|
before_action :set_identity, only: %i[edit update destroy]
|
|
|
|
def index
|
|
@page_title = "Account email"
|
|
@mail_identities = MailIdentity.ordered
|
|
end
|
|
|
|
def new
|
|
@page_title = "Nuovo account email"
|
|
@mail_identity = MailIdentity.new(smtp_port: 587, encryption: "starttls", smtp_authentication: "plain", active: true, verify_ssl: true)
|
|
end
|
|
|
|
def create
|
|
@mail_identity = MailIdentity.new(identity_params)
|
|
if @mail_identity.save
|
|
redirect_to mail_identities_path, notice: "Account email creato. Da qui partono gli invii."
|
|
else
|
|
@page_title = "Nuovo account email"
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@page_title = "Modifica account email"
|
|
end
|
|
|
|
def update
|
|
attrs = identity_params
|
|
attrs.delete(:smtp_password) if attrs[:smtp_password].blank?
|
|
if @mail_identity.update(attrs)
|
|
redirect_to mail_identities_path, notice: "Account email aggiornato."
|
|
else
|
|
@page_title = "Modifica account email"
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @mail_identity.mailings.exists?
|
|
redirect_to mail_identities_path, alert: "Non puoi eliminare un account già usato in un invio. Disattivalo."
|
|
return
|
|
end
|
|
|
|
@mail_identity.destroy!
|
|
redirect_to mail_identities_path, notice: "Account email eliminato."
|
|
end
|
|
|
|
private
|
|
|
|
def set_identity
|
|
@mail_identity = MailIdentity.find(params[:id])
|
|
end
|
|
|
|
def identity_params
|
|
params.require(:mail_identity).permit(
|
|
:name, :from_name, :from_email, :reply_to, :smtp_host, :smtp_port,
|
|
:smtp_username, :smtp_password, :smtp_authentication, :encryption,
|
|
:verify_ssl, :active
|
|
)
|
|
end
|
|
end
|