suite
This commit is contained in:
parent
3a28915721
commit
a7cb020815
@ -30,6 +30,7 @@ class Admin::AdminsController < ApplicationController
|
||||
|
||||
if @admin.save
|
||||
@admins = Admin.all
|
||||
@admin.generate_mdp_now if @admin.generate_mdp and @admin.generate_mdp != "0"
|
||||
|
||||
else
|
||||
render :action => "new"
|
||||
@ -40,7 +41,7 @@ class Admin::AdminsController < ApplicationController
|
||||
@admin = Admin.find(params[:id])
|
||||
|
||||
if @admin.update_attributes(admin_params)
|
||||
|
||||
@admin.generate_mdp_now if @admin.generate_mdp and @admin.generate_mdp != "0"
|
||||
|
||||
else
|
||||
render :action => "edit"
|
||||
|
55
app/helpers/mail_helper.rb
Normal file
55
app/helpers/mail_helper.rb
Normal file
@ -0,0 +1,55 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MailHelper
|
||||
|
||||
def mail_content(mail_content, lang_slug, arguments = {})
|
||||
|
||||
lang_site = LangSite.find_by_slug(lang_slug)
|
||||
|
||||
|
||||
|
||||
if mail_content.content_type == "blocs" and mail_content.block
|
||||
r = "<div class='render_block'>"+render(:partial => "public/blocks/block", :locals => {:block => mail_content.block})+render(:partial => "public/shared/render_block.html.haml")+"</div>"
|
||||
|
||||
|
||||
else
|
||||
|
||||
if mail_content.message?
|
||||
r= mail_content.message
|
||||
elsif mail_content.mail_type.mail_type_reference
|
||||
r= mail_content.mail_type.mail_type_reference.mail_contents.find_by_lang_site_id(lang_site.id).message.to_s
|
||||
else
|
||||
r= ""
|
||||
end
|
||||
|
||||
r = simple_format(r)
|
||||
|
||||
end
|
||||
|
||||
|
||||
arguments.each_pair do |key, value|
|
||||
r = r.gsub(/\[#{key}\]/, value.to_s)
|
||||
|
||||
end
|
||||
|
||||
if mail_content.mail_template and mail_content.mail_template.template_html?
|
||||
template = mail_content.mail_template.template_html
|
||||
|
||||
|
||||
r = template.gsub(/\[contenu\]/, r)
|
||||
|
||||
|
||||
|
||||
|
||||
raw r
|
||||
|
||||
|
||||
|
||||
else
|
||||
raw r
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
23
app/mailers/general_mailer.rb
Executable file
23
app/mailers/general_mailer.rb
Executable file
@ -0,0 +1,23 @@
|
||||
class GeneralMailer < ActionMailer::Base
|
||||
default from: "n.bally@jipe.fr"
|
||||
|
||||
add_template_helper(MailHelper)
|
||||
|
||||
# Subject can be set in your I18n file at config/locales/en.yml
|
||||
# with the following lookup:
|
||||
#
|
||||
# en.question.deliver.subject
|
||||
#
|
||||
def send_qi_mail(lang_slug, slug, to, options)
|
||||
|
||||
@mail_content = MailContent.find_key(LangSite.find_by_slug(lang_slug), slug)
|
||||
|
||||
@lang_slug = lang_slug
|
||||
|
||||
@options = options
|
||||
|
||||
mail to: to, :subject => "[Jipé] "+@mail_content.subject.to_s
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -4,19 +4,19 @@ class Admin < ActiveRecord::Base
|
||||
|
||||
has_secure_password
|
||||
|
||||
attr_accessor :login
|
||||
attr_accessor :login, :generate_mdp
|
||||
|
||||
validates :password, :presence => true,
|
||||
:confirmation => true,
|
||||
:length => {:within => 6..40},
|
||||
:on => :create
|
||||
|
||||
validates :password, :confirmation => true,
|
||||
validates :password,
|
||||
:length => {:within => 6..40},
|
||||
:allow_blank => true,
|
||||
:on => :update
|
||||
validates :password_confirmation, :presence => true,
|
||||
:unless => Proc.new { |a| a.password.blank? }
|
||||
#validates :password_confirmation, :presence => true,
|
||||
# :unless => Proc.new { |a| a.password.blank? }
|
||||
|
||||
|
||||
validates :email, :presence => true, :uniqueness => true
|
||||
@ -26,6 +26,26 @@ class Admin < ActiveRecord::Base
|
||||
|
||||
before_create { generate_token(:remember_token) }
|
||||
|
||||
def generate_mdp_now
|
||||
ps = SecureRandom.hex(4)
|
||||
self.password = ps
|
||||
self.password_confirmation = ps
|
||||
|
||||
if !self.email?
|
||||
errors.add(:email, "Doit être présent")
|
||||
|
||||
end
|
||||
|
||||
|
||||
if self.save
|
||||
GeneralMailer.send_qi_mail("fr", "generation_mdp", self.email, {"mdp" => ps}).deliver
|
||||
else
|
||||
fgfdggdf = dfgdgf
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def send_password_reset
|
||||
generate_token(:reset_password_token)
|
||||
self.reset_password_sent_at = Time.now
|
||||
|
45
app/models/mail_content.rb
Normal file
45
app/models/mail_content.rb
Normal file
@ -0,0 +1,45 @@
|
||||
class MailContent < ActiveRecord::Base
|
||||
belongs_to :lang_site
|
||||
belongs_to :mail_type
|
||||
|
||||
belongs_to :mail_template
|
||||
|
||||
has_one :block, :as => :blockable
|
||||
|
||||
after_create do
|
||||
generate_block
|
||||
|
||||
end
|
||||
|
||||
def generate_block
|
||||
@block = Block.new(:block_name => "general", :lang_site => self.lang_site)
|
||||
@block.blockable = self
|
||||
@block.save
|
||||
end
|
||||
|
||||
|
||||
def alloweds_types
|
||||
|
||||
{
|
||||
TitleContent: "Titre",
|
||||
TextContent: "Texte",
|
||||
ImageContent: "Image",
|
||||
LinkContent:"Lien",
|
||||
BreakContent: "Séparation",
|
||||
HtmlContent: "Code HTML",
|
||||
DownloadContent: "Téléchargement",
|
||||
|
||||
BlockContent: "Bloc",
|
||||
|
||||
ShareContent: "Ligne partage réseaux",
|
||||
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def self.find_key(lang, slug )
|
||||
|
||||
MailContent.joins(:mail_type).where(:lang_site_id =>lang, :mail_types => { :slug => slug}).first
|
||||
end
|
||||
|
||||
end
|
2
app/models/mail_template.rb
Normal file
2
app/models/mail_template.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class MailTemplate < ActiveRecord::Base
|
||||
end
|
17
app/models/mail_type.rb
Normal file
17
app/models/mail_type.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class MailType < ActiveRecord::Base
|
||||
has_many :mail_contents
|
||||
belongs_to :mail_type_reference, :class_name => "MailType"
|
||||
|
||||
|
||||
|
||||
def self.generate_mail_content(slug)
|
||||
mc = MailType.new(:slug => slug)
|
||||
LangSite.all.each do |ls|
|
||||
|
||||
mc.mail_contents.new(:lang_site_id => ls.id, :content_type => "text")
|
||||
end
|
||||
mc.save
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -10,7 +10,9 @@
|
||||
Ajouter un admin
|
||||
|
||||
= f.inputs do
|
||||
|
||||
|
||||
= f.input :super_admin, :label => "Super admin ?"
|
||||
|
||||
= f.input :email, :label => "Email :"
|
||||
|
||||
|
||||
@ -24,10 +26,11 @@
|
||||
= f.input :firstname, :label => "Prénom :"
|
||||
|
||||
|
||||
= f.input :password, :label => "Mot de passe :"
|
||||
|
||||
|
||||
= f.input :password_confirmation, :label => "Confirmation :"
|
||||
= f.input :generate_mdp, :label => "Forcer la génération d'un nouveau mot de passe ? (un mail sera envoyé à l'utilisateur)", :as => :boolean
|
||||
|
||||
= f.input :password, :label => "Mot de passe :", :input_html => { :autocomplete => "new-password"}
|
||||
|
||||
|
||||
|
||||
= f.input :color, :label => "Couleur pour identification dans contacts"
|
||||
|
||||
|
1
app/views/general_mailer/send_qi_mail.html.haml
Normal file
1
app/views/general_mailer/send_qi_mail.html.haml
Normal file
@ -0,0 +1 @@
|
||||
=mail_content(@mail_content, @lang_slug, @options)
|
@ -96,7 +96,8 @@
|
||||
%b.caret
|
||||
|
||||
%ul.dropdown-menu
|
||||
%li= link_to "Gestion des admins", admin_admins_path
|
||||
-if current_admin.super_admin
|
||||
%li= link_to "Gestion des admins", admin_admins_path
|
||||
%li.divider
|
||||
%li=link_to "Se déconnecter", admin_admin_auth_path(1), method: :delete
|
||||
%li
|
||||
|
11
db/migrate/20180104181313_create_mail_types.rb
Normal file
11
db/migrate/20180104181313_create_mail_types.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class CreateMailTypes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :mail_types do |t|
|
||||
t.string :slug
|
||||
t.string :default_title
|
||||
t.text :default_message
|
||||
t.integer :mail_type_reference_id
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
22
db/migrate/20180104181352_create_mail_contents.rb
Normal file
22
db/migrate/20180104181352_create_mail_contents.rb
Normal file
@ -0,0 +1,22 @@
|
||||
class CreateMailContents < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :mail_contents do |t|
|
||||
t.references :lang_site
|
||||
t.references :mail_type
|
||||
t.string :subject
|
||||
t.text :message
|
||||
|
||||
|
||||
t.timestamps null: false
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
7
db/migrate/20180104181353_add_infos_to_mail_contents.rb
Normal file
7
db/migrate/20180104181353_add_infos_to_mail_contents.rb
Normal file
@ -0,0 +1,7 @@
|
||||
class AddInfosToMailContents < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :mail_contents, :enabled, :boolean
|
||||
add_column :mail_contents, :content_type, :string
|
||||
add_column :mail_contents, :tags, :text
|
||||
end
|
||||
end
|
10
db/migrate/20180501135206_create_mail_templates.rb
Normal file
10
db/migrate/20180501135206_create_mail_templates.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class CreateMailTemplates < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :mail_templates do |t|
|
||||
t.string :title
|
||||
t.text :template_html
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddMailTemplateToMailContents < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :mail_contents, :mail_template
|
||||
end
|
||||
end
|
5
db/migrate/20190424164427_add_super_admin_to_admins.rb
Normal file
5
db/migrate/20190424164427_add_super_admin_to_admins.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddSuperAdminToAdmins < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :admins, :super_admin, :boolean, :default => false
|
||||
end
|
||||
end
|
38
db/schema.rb
38
db/schema.rb
@ -11,15 +11,15 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180628225938) do
|
||||
ActiveRecord::Schema.define(version: 20190424164427) do
|
||||
|
||||
create_table "admins", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.string "firstname", limit: 255
|
||||
t.string "avatar", limit: 255
|
||||
t.string "username", limit: 255, default: "", null: false
|
||||
t.string "email", limit: 255, default: "", null: false
|
||||
t.string "password_digest", limit: 255, default: "", null: false
|
||||
t.string "username", limit: 255, default: "", null: false
|
||||
t.string "email", limit: 255, default: "", null: false
|
||||
t.string "password_digest", limit: 255, default: "", null: false
|
||||
t.string "reset_password_token", limit: 255
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
@ -41,6 +41,7 @@ ActiveRecord::Schema.define(version: 20180628225938) do
|
||||
t.boolean "label_role"
|
||||
t.string "color", limit: 255
|
||||
t.boolean "contact_role"
|
||||
t.boolean "super_admin", default: false
|
||||
end
|
||||
|
||||
create_table "albums", force: :cascade do |t|
|
||||
@ -546,6 +547,19 @@ ActiveRecord::Schema.define(version: 20180628225938) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "mail_contents", force: :cascade do |t|
|
||||
t.integer "lang_site_id", limit: 4
|
||||
t.integer "mail_type_id", limit: 4
|
||||
t.string "subject", limit: 255
|
||||
t.text "message", limit: 65535
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "enabled"
|
||||
t.string "content_type", limit: 255
|
||||
t.text "tags", limit: 65535
|
||||
t.integer "mail_template_id", limit: 4
|
||||
end
|
||||
|
||||
create_table "mail_profiles", force: :cascade do |t|
|
||||
t.string "civilite", limit: 255
|
||||
t.string "firstname", limit: 255
|
||||
@ -565,6 +579,22 @@ ActiveRecord::Schema.define(version: 20180628225938) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "mail_templates", force: :cascade do |t|
|
||||
t.string "title", limit: 255
|
||||
t.text "template_html", limit: 65535
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "mail_types", force: :cascade do |t|
|
||||
t.string "slug", limit: 255
|
||||
t.string "default_title", limit: 255
|
||||
t.text "default_message", limit: 65535
|
||||
t.integer "mail_type_reference_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "map_contents", force: :cascade do |t|
|
||||
t.string "address", limit: 255
|
||||
t.string "name", limit: 255
|
||||
|
Loading…
x
Reference in New Issue
Block a user