Skip to content

Commit

Permalink
more Rails 5 friendly (removing deprecation messages) + add views for…
Browse files Browse the repository at this point in the history
… password reset
  • Loading branch information
GarPit committed Mar 1, 2017
1 parent 30360b9 commit cfb1151
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/controllers/kms/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

after_filter :set_csrf_cookie_for_ng
after_action :set_csrf_cookie_for_ng

def set_csrf_cookie_for_ng
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/kms/public/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
module Kms
class Public::PagesController < ActionController::Base

before_filter :eval_externals
before_action :eval_externals

def show
page_result = Kms.template_manager.render(@page.register_id, @externals)
# apply typograph to page content
#page_result = EvilFront::Russian.typograph_html(page_result)
result = Kms.template_manager.render(@template.register_id, @externals.
merge(_inner_template: page_result))

render text: result, layout: false
render html: result.html_safe
end

protected
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/kms/compile_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module CompileTemplates
after_commit :compile_templates, on: [:create, :update]
end

def register_id
[self.class.name.parameterize(separator: "_"), id.to_s].join('_')
end

protected

def compiled_templates
Expand Down
3 changes: 0 additions & 3 deletions app/models/kms/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,5 @@ def fetch_item!(slug)
templatable_type.constantize.find_by_slug!(slug)
end

def register_id
"#{self.class.name.parameterize("_")}_#{id}"
end
end
end
3 changes: 0 additions & 3 deletions app/models/kms/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ class Template < ActiveRecord::Base

validates :name, presence: true

def register_id
"#{self.class.name.parameterize("_")}_#{id}"
end
end
end
22 changes: 22 additions & 0 deletions app/views/devise/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="wrapper">

<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { class: 'form-signin', method: :put }) do |f| %>
<h2 class="form-signin-heading">KMS</h2>
<h4>Change your password</h4>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
<% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off", class: 'form-control', placeholder: 'Password' %>
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control', placeholder: 'Password confirmation' %>
<%= f.submit "Change my password", class: "btn btn-lg btn-primary btn-block" %>

<br>
<%= render "devise/shared/links" %>
<% end %>

</div>
15 changes: 15 additions & 0 deletions app/views/devise/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="wrapper">
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { class: 'form-signin', method: :post }) do |f| %>
<h2 class="form-signin-heading">KMS</h2>
<%= devise_error_messages! %>

<h4>Forgot your password?</h4>
<%= f.email_field :email, autofocus: true, class: 'form-control', placeholder: 'Email' %>
<br>
<%= f.submit "Send reset password instructions", class: "btn btn-lg btn-primary btn-block" %>
<br>
<%= render "devise/shared/links" %>
<% end %>

</div>
2 changes: 1 addition & 1 deletion db/migrate/20141027065341_create_pages.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreatePages < ActiveRecord::Migration
class CreatePages < ActiveRecord::Migration[4.2]
def change
create_table :kms_pages do |t|
t.string :title
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141027083603_create_templates.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateTemplates < ActiveRecord::Migration
class CreateTemplates < ActiveRecord::Migration[4.2]
def change
create_table :kms_templates do |t|
t.string :name
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141027083633_add_template_id_to_pages.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddTemplateIdToPages < ActiveRecord::Migration
class AddTemplateIdToPages < ActiveRecord::Migration[4.2]
def change
add_column :kms_pages, :template_id, :integer
add_foreign_key :kms_pages, :kms_templates if respond_to?(:add_foreign_key)
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141029145253_create_assets.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateAssets < ActiveRecord::Migration
class CreateAssets < ActiveRecord::Migration[4.2]
def change
create_table :kms_assets do |t|
t.string :file
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141031125758_add_ancestry_to_pages.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddAncestryToPages < ActiveRecord::Migration
class AddAncestryToPages < ActiveRecord::Migration[4.2]
def change
add_column :kms_pages, :ancestry, :string
add_index :kms_pages, :ancestry
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141031140308_devise_create_users.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeviseCreateUsers < ActiveRecord::Migration
class DeviseCreateUsers < ActiveRecord::Migration[4.2]
def change
create_table(:kms_users) do |t|
## Database authenticatable
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141119084306_add_fullpath_to_pages.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddFullpathToPages < ActiveRecord::Migration
class AddFullpathToPages < ActiveRecord::Migration[4.2]
def change
add_column :kms_pages, :fullpath, :string
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141121112652_add_role_to_users.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddRoleToUsers < ActiveRecord::Migration
class AddRoleToUsers < ActiveRecord::Migration[4.2]
def change
add_column :kms_users, :role, :string
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddTemplatableFieldsToPages < ActiveRecord::Migration
class AddTemplatableFieldsToPages < ActiveRecord::Migration[4.2]
def change
add_column :kms_pages, :templatable, :boolean, default: false
add_column :kms_pages, :templatable_type, :string
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20141209132901_add_hidden_to_page.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddHiddenToPage < ActiveRecord::Migration
class AddHiddenToPage < ActiveRecord::Migration[4.2]
def change
add_column :kms_pages, :hidden, :boolean, default: false
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20150209120632_add_position_to_kms_pages.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddPositionToKmsPages < ActiveRecord::Migration
class AddPositionToKmsPages < ActiveRecord::Migration[4.2]
def change
add_column :kms_pages, :position, :integer, default: 0, null: false
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160129100437_create_kms_snippets.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateKmsSnippets < ActiveRecord::Migration
class CreateKmsSnippets < ActiveRecord::Migration[4.2]
def change
create_table :kms_snippets do |t|
t.string :name
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160712094512_create_kms_settings.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateKmsSettings < ActiveRecord::Migration
class CreateKmsSettings < ActiveRecord::Migration[4.2]
def change
create_table :kms_settings do |t|
t.json :values
Expand Down
1 change: 1 addition & 0 deletions lib/kms/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Engine < ::Rails::Engine
config.to_prepare do
::Devise::SessionsController.layout "kms/devise"
::Devise::RegistrationsController.layout "kms/devise"
::Devise::PasswordsController.layout "kms/devise"
Dir.glob(Rails.root + "kms_*/**/*_decorator*.rb").each do |c|
require_dependency(c)
end
Expand Down

0 comments on commit cfb1151

Please sign in to comment.