inscription newsletters
This commit is contained in:
parent
27d7568a83
commit
8d0139caec
@ -146,5 +146,57 @@ article{
|
||||
background: rgba(250,250,250,1);
|
||||
margin-bottom:20px;
|
||||
|
||||
}
|
||||
.share_in_social{
|
||||
text-align:center;
|
||||
margin:1em;
|
||||
margin-top:2em;
|
||||
border-top:1px solid rgba(250,250,250,1);
|
||||
border-bottom:1px solid rgba(250,250,250,1);
|
||||
padding:10px;
|
||||
|
||||
}
|
||||
.btn{
|
||||
font-family:"jaf-bernino-sans", sans-serif;
|
||||
font-size:1em;
|
||||
padding:8px 15px;
|
||||
border-radius:5px;
|
||||
border:0;
|
||||
color:black;
|
||||
background:transparent;
|
||||
cursor:pointer;
|
||||
|
||||
}
|
||||
|
||||
.input_text, textarea{
|
||||
font-family:"jaf-bernino-sans", sans-serif;
|
||||
font-size:0.9em;
|
||||
padding:8px 15px;
|
||||
border-radius:5px;
|
||||
border:0;
|
||||
color:black;
|
||||
background:white;
|
||||
border:1px solid rgba(131,131,131,1);
|
||||
|
||||
|
||||
}
|
||||
.btn-primary{
|
||||
|
||||
background:rgba(64,138,199,1);
|
||||
color:white;
|
||||
&:hover{
|
||||
background:#357ebd;;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
.infos{
|
||||
margin-top:0;
|
||||
font-size:14px;
|
||||
margin-bottom:1.5em;
|
||||
color:#8D8D8D;
|
||||
|
||||
}
|
49
app/controllers/public/registrants_controller.rb
Normal file
49
app/controllers/public/registrants_controller.rb
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
|
||||
class Public::RegistrantsController < ApplicationController
|
||||
|
||||
layout "public"
|
||||
|
||||
|
||||
|
||||
def create
|
||||
|
||||
@registrant = Registrant.new(params.require(:registrant).permit(:surname, :email))
|
||||
|
||||
test = Registrant.find_by_email(@registrant.email)
|
||||
if test
|
||||
@registrant = test
|
||||
General.confirm_email(@registrant).deliver
|
||||
else
|
||||
|
||||
if @registrant.save
|
||||
General.confirm_email(@registrant).deliver
|
||||
else
|
||||
render :action => :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_e
|
||||
@registrant = Registrant.find_by_token(params[:id])
|
||||
if @registrant
|
||||
@registrant.destroy
|
||||
@message = "<p>Vous avez bien été désinscrit.</p>"
|
||||
else
|
||||
@message = "Votre adresse mail ne figure pas dans notre fichier."
|
||||
end
|
||||
end
|
||||
|
||||
def email_validation
|
||||
@registrant = Registrant.find_by_token(params[:id])
|
||||
if @registrant
|
||||
@registrant.enabled = true
|
||||
@registrant.save
|
||||
@message = "<p>Merci, votre inscription a bien été prise en compte.</p> "
|
||||
else
|
||||
@message = "Votre adresse mail ne figure pas dans le fichier."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
29
app/mailers/general.rb
Normal file
29
app/mailers/general.rb
Normal file
@ -0,0 +1,29 @@
|
||||
class General < ActionMailer::Base
|
||||
default :from => "Nicolas Bally <info@nicolasbally.com>"
|
||||
self.default_url_options = {:host => HOSTNAME}
|
||||
|
||||
|
||||
def send_newsletter(email,newsletter )
|
||||
@newsletter = newsletter
|
||||
if email.kind_of?(String)
|
||||
email = email
|
||||
else
|
||||
@registrant = email
|
||||
email = email.email
|
||||
|
||||
end
|
||||
mail(:to => email, :subject => @newsletter.subject) do |format|
|
||||
format.html { render :action => "send_newsletter"}
|
||||
end
|
||||
end
|
||||
|
||||
def confirm_email(registrant)
|
||||
@registrant = registrant
|
||||
|
||||
mail(:to => @registrant.email, :subject => "Confirmation de votre adresse email.") do |format|
|
||||
format.html { render :action => "confirm_email"}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
13
app/models/newsletter.rb
Normal file
13
app/models/newsletter.rb
Normal file
@ -0,0 +1,13 @@
|
||||
class Newsletter < ActiveRecord::Base
|
||||
after_create :after_creation
|
||||
has_one :block, :as => :blockable
|
||||
|
||||
def after_creation
|
||||
@block = Block.new(:block_name => "Contenu")
|
||||
@block.blockable = self
|
||||
@block.save
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
20
app/models/registrant.rb
Normal file
20
app/models/registrant.rb
Normal file
@ -0,0 +1,20 @@
|
||||
class Registrant < ActiveRecord::Base
|
||||
|
||||
before_validation :verify
|
||||
|
||||
|
||||
validates :email, :presence => true, :uniqueness => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
||||
validates :surname, :presence => true
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def verify(size=16)
|
||||
if !self.token
|
||||
s = ""
|
||||
size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
|
||||
self.token = s
|
||||
end
|
||||
end
|
||||
|
||||
end
|
82
app/views/general/confirm_email.html.erb
Normal file
82
app/views/general/confirm_email.html.erb
Normal file
@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='fr' xml:lang='fr'>
|
||||
<head>
|
||||
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
|
||||
<style type="text/css">
|
||||
body { background-color: white; color:#2d2d2d;font-family: Lucida Grande, arial, sans-serif;}
|
||||
.content{
|
||||
|
||||
margin:auto;
|
||||
margin-top:10px;
|
||||
margin-bottom:10px;
|
||||
|
||||
padding:20px;
|
||||
|
||||
|
||||
position:relative;
|
||||
|
||||
}
|
||||
|
||||
#legaly{
|
||||
text-align:center;
|
||||
width:90%;
|
||||
margin:auto;
|
||||
}
|
||||
.header{
|
||||
text-align:center;
|
||||
width:90%;
|
||||
margin:auto;
|
||||
}
|
||||
|
||||
.portlet.table_content table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.portlet.table_content table td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.portlet.block_content .two_column .column {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.portlet.block_content .two_column .column .block {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="header">
|
||||
<%= image_tag "http://blog.nicolasbally.com/logo.png", :style => "max-width: 300px;" %>
|
||||
|
||||
</div>
|
||||
<div class="content">
|
||||
Merci pour votre inscription !
|
||||
<br /><br />
|
||||
En cliquant sur le lien ci-dessous vous confirmerez votre demande d'inscription à la newsletter.
|
||||
<br /><br />
|
||||
Votre adresse ne sera jamais cédée à des tiers.
|
||||
<br />
|
||||
<br />
|
||||
<%=link_to email_validation_public_registrant_url(:id => @registrant.token) , email_validation_public_registrant_url(:id => @registrant.token) %>
|
||||
<br />
|
||||
<br />
|
||||
(Si vous ne pouvez pas cliquer sur ce lien, merci de bien vouloir le copier et le coller dans la barre d'adresse de votre navigateur.)
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
|
||||
|
76
app/views/general/send_newsletter.html.erb
Normal file
76
app/views/general/send_newsletter.html.erb
Normal file
@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='fr' xml:lang='fr'>
|
||||
<head>
|
||||
<title>La cabane du Lutin</title>
|
||||
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
|
||||
<style type="text/css">
|
||||
body { background-color: white; color:#2d2d2d;font-family: Lucida Grande, arial, sans-serif;}
|
||||
.content{
|
||||
|
||||
margin:auto;
|
||||
margin-top:10px;
|
||||
margin-bottom:10px;
|
||||
|
||||
padding:20px;
|
||||
|
||||
|
||||
position:relative;
|
||||
|
||||
}
|
||||
|
||||
#legaly{
|
||||
text-align:center;
|
||||
width:90%;
|
||||
margin:auto;
|
||||
}
|
||||
.header{
|
||||
text-align:center;
|
||||
width:90%;
|
||||
margin:auto;
|
||||
}
|
||||
|
||||
.portlet.table_content table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.portlet.table_content table td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.portlet.block_content .two_column .column {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.portlet.block_content .two_column .column .block {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="header">
|
||||
<%= image_tag "http://blog.nicolasbally.com/logo.png", :style => "max-width: 300px;" %>
|
||||
</div>
|
||||
<div class="content">
|
||||
<%= render :object => @newsletter.block, :partial => "public/blocks/block" %>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div id="legaly">
|
||||
<hr />
|
||||
Vous recevez cet email car vous êtes abonné à la newsletter du blog <a href="http://blog.nicolasbally.com/">http://blog.nicolasbally.com</a>. Si vous ne souhaitez plus recevoir de mail de notre part, merci de cliquer sur ce lien : <%=link_to destroy_e_public_registrant_url(:id => @registrant.token), destroy_e_public_registrant_url(:id => @registrant.token) if @registrant %>
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
|
||||
|
||||
|
@ -51,9 +51,15 @@
|
||||
#corps{:class => ("article_corps" if @article)}=yield
|
||||
|
||||
%section#sidebar
|
||||
|
||||
|
||||
.newsletter
|
||||
%h3.sidebar_title Restez informés !
|
||||
|
||||
=render :partial => "public/registrants/form"
|
||||
|
||||
=render :partial => "public/articles/sidebar_recents"
|
||||
|
||||
|
||||
|
||||
%h3.sidebar_title Mes activités
|
||||
|
||||
|
||||
|
@ -10,17 +10,17 @@
|
||||
%p
|
||||
=f.label :pseudo, "Pseudo :"
|
||||
|
||||
=f.text_field :pseudo
|
||||
=f.text_field :pseudo, :class => "input_text"
|
||||
|
||||
%p
|
||||
|
||||
=f.label :email, "Email :"
|
||||
=f.text_field :email
|
||||
=f.text_field :email, :class => "input_text"
|
||||
|
||||
%p
|
||||
|
||||
=f.label :website, "Site :"
|
||||
=f.text_field :website
|
||||
=f.text_field :website, :class => "input_text"
|
||||
|
||||
%p
|
||||
|
||||
@ -30,4 +30,4 @@
|
||||
|
||||
|
||||
|
||||
=f.submit "Envoyer", :class => "submit btn"
|
||||
=f.submit "Envoyer", :class => " btn btn-primary"
|
34
app/views/public/registrants/_form.html.haml
Normal file
34
app/views/public/registrants/_form.html.haml
Normal file
@ -0,0 +1,34 @@
|
||||
-@registrant = @registrant || Registrant.new
|
||||
.newsletter_form
|
||||
%p
|
||||
Inscrivez-vous à ma newsletter pour suivre l'actualité de ce blog.
|
||||
|
||||
|
||||
=form_for [:public, @registrant], :remote => true do |f|
|
||||
|
||||
|
||||
|
||||
%p
|
||||
=f.text_field :surname, :placeholder => "Prénom", :class => "input_text"
|
||||
-if f.object.errors[:email].count > 0
|
||||
%p.error
|
||||
Vous devez indiquez votre prénom pour vous inscrire.
|
||||
|
||||
|
||||
|
||||
%p
|
||||
=f.text_field :email, :placeholder => "Email", :class => "input_text"
|
||||
-if f.object.errors[:email].count == 2
|
||||
%p.error
|
||||
Vous devez indiquez un email pour pouvoir vous inscrire.
|
||||
-elsif f.object.errors[:email].count == 1
|
||||
%p.error
|
||||
L'email que vous avez indiqué n'est pas valide.
|
||||
|
||||
|
||||
=f.submit "M'inscrire !", :class => "btn btn-primary"
|
||||
|
||||
%p.infos
|
||||
=i(:lock)
|
||||
|
||||
Votre adresse ne sera pas partagée ou revendue à des tiers.
|
1
app/views/public/registrants/create.js.erb
Normal file
1
app/views/public/registrants/create.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$(".newsletter_form").replaceWith("Merci pour votre inscription ! Vous allez recevoir un mail avec un lien pour confirmer celle-ci.");
|
2
app/views/public/registrants/destroy_e.html.haml
Normal file
2
app/views/public/registrants/destroy_e.html.haml
Normal file
@ -0,0 +1,2 @@
|
||||
.flash_message
|
||||
=raw @message
|
2
app/views/public/registrants/email_validation.html.haml
Normal file
2
app/views/public/registrants/email_validation.html.haml
Normal file
@ -0,0 +1,2 @@
|
||||
.flash_message
|
||||
=raw @message
|
0
app/views/public/registrants/new.html.haml
Normal file
0
app/views/public/registrants/new.html.haml
Normal file
1
app/views/public/registrants/new.js.erb
Normal file
1
app/views/public/registrants/new.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$(".newsletter_form").replaceWith("<%= escape_javascript(render(:partial => "public/registrants/form")) %>");
|
@ -18,6 +18,13 @@ Rails.application.routes.draw do
|
||||
get "sitemap.:f" => "public/sitemap#sitemap"
|
||||
namespace :public do
|
||||
resources :comments
|
||||
resources :registrants do
|
||||
member do
|
||||
get :email_validation
|
||||
get :destroy_e
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
namespace :portlet do
|
||||
|
13
db/migrate/20140710140837_create_registrants.rb
Normal file
13
db/migrate/20140710140837_create_registrants.rb
Normal file
@ -0,0 +1,13 @@
|
||||
class CreateRegistrants < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :registrants do |t|
|
||||
t.string :token
|
||||
t.string :name
|
||||
t.string :surname
|
||||
t.string :email
|
||||
t.boolean :enabled
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
12
db/migrate/20140710144544_create_newsletters.rb
Normal file
12
db/migrate/20140710144544_create_newsletters.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class CreateNewsletters < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :newsletters do |t|
|
||||
t.string :subject
|
||||
t.text :content
|
||||
t.boolean :sended
|
||||
t.boolean :send_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
19
db/schema.rb
19
db/schema.rb
@ -351,6 +351,15 @@ ActiveRecord::Schema.define(version: 20150411203736) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "newsletters", force: :cascade do |t|
|
||||
t.string "subject", limit: 255
|
||||
t.text "content", limit: 65535
|
||||
t.boolean "sended", limit: 1
|
||||
t.boolean "send_at", limit: 1
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "pages", force: :cascade do |t|
|
||||
t.text "title", limit: 65535
|
||||
t.text "description", limit: 65535
|
||||
@ -368,6 +377,16 @@ ActiveRecord::Schema.define(version: 20150411203736) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "registrants", force: :cascade do |t|
|
||||
t.string "token", limit: 255
|
||||
t.string "name", limit: 255
|
||||
t.string "surname", limit: 255
|
||||
t.string "email", limit: 255
|
||||
t.boolean "enabled", limit: 1
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "table_contents", force: :cascade do |t|
|
||||
t.integer "style", limit: 4
|
||||
t.integer "nbr_rows", limit: 4
|
||||
|
Loading…
x
Reference in New Issue
Block a user