Skip to content

Commit

Permalink
TB-2 #time 30m Add admin profile editor
Browse files Browse the repository at this point in the history
  • Loading branch information
marjinal1st committed Apr 6, 2014
1 parent 10e6992 commit 0273c31
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 30 deletions.
60 changes: 30 additions & 30 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
PATH
remote: .
specs:
cybele (1.3.0)
cybele (1.4.0)
bundler (~> 1.5)
rails (~> 4.0)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.2)
actionpack (= 4.0.2)
actionmailer (4.0.4)
actionpack (= 4.0.4)
mail (~> 2.5.4)
actionpack (4.0.2)
activesupport (= 4.0.2)
actionpack (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.2)
activesupport (= 4.0.2)
activemodel (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
activerecord (4.0.2)
activemodel (= 4.0.2)
activerecord (4.0.4)
activemodel (= 4.0.4)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.2)
activesupport (= 4.0.4)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.2)
i18n (~> 0.6, >= 0.6.4)
activesupport (4.0.4)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.1)
atomic (1.1.14)
arel (4.0.2)
atomic (1.1.16)
builder (3.1.4)
erubis (2.7.0)
hike (1.2.3)
Expand All @@ -43,26 +43,26 @@ GEM
treetop (~> 1.4.8)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.2)
polyglot (0.3.3)
multi_json (1.9.2)
polyglot (0.3.4)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.2)
actionmailer (= 4.0.2)
actionpack (= 4.0.2)
activerecord (= 4.0.2)
activesupport (= 4.0.2)
rails (4.0.4)
actionmailer (= 4.0.4)
actionpack (= 4.0.4)
activerecord (= 4.0.4)
activesupport (= 4.0.4)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.2)
railties (= 4.0.4)
sprockets-rails (~> 2.0.0)
railties (4.0.2)
actionpack (= 4.0.2)
activesupport (= 4.0.2)
railties (4.0.4)
actionpack (= 4.0.4)
activesupport (= 4.0.4)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.0.4)
sprockets (2.10.1)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
Expand All @@ -71,14 +71,14 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
thor (0.18.1)
thread_safe (0.1.3)
atomic
thor (0.19.1)
thread_safe (0.3.1)
atomic (>= 1.1.7, < 2)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.38)
tzinfo (0.3.39)

PLATFORMS
ruby
Expand Down
13 changes: 13 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ def generate_hq_namespace
path_names: {sign_in: 'login', sign_out: 'logout', password: 'secret',
confirmation: 'verification'}"
gsub_file 'app/models/admin.rb', /:registerable,/, ''
say 'Configuring profile editors...'
setup_profile_editors
end

def setup_profile_editors
inject_into_file 'config/routes.rb', :after => "namespace :hq do\n" do <<-RUBY
# Routing for admin profile editing
match '/profile', to: 'profile#edit', via: :get
match '/profile', to: 'profile#update', via: [:patch, :put]
RUBY
end

copy_file 'app/views/hq/profile/edit.html.haml', 'app/views/hq/profile/edit.html.haml'
end

def set_time_zone
Expand Down
25 changes: 25 additions & 0 deletions templates/app/controllers/hq/profile_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Hq::ProfileController < Hq::ApplicationController
before_action :set_admin, only: [:edit, :update]

def edit
end

def update
if @admin.valid_password? params[:admin][:current_password] && @admin.update(admin_params)
sign_in @admin
redirect_to hq_dashboard_index_path
else
render 'edit'
end
end

private

def set_admin
@admin = current_admin
end

def admin_params
params.require(:admin).permit(:email, :password, :password_confirmation)
end
end

This comment has been minimized.

Copy link
@adamdilek

adamdilek Apr 14, 2014

Contributor

@marjinal1st We need AdminProfile and UserProfile model. And we must edit it.

17 changes: 17 additions & 0 deletions templates/app/views/hq/profile/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.panel.panel-default
.panel-heading
%i.icon-edit.icon-large
#{t('edit_profile')}
.panel-body
= simple_form_for :admin, method: :put, url: '/hq/profile' do |f|
= f.error_notification

.form-inputs
= f.input :email
= f.input :password
= f.input :password_confirmation
= f.input :current_password

.form-actions
= f.button :submit, class: 'btn btn-default'
= link_to t('cancel'), hq_dashboard_index_path, class: 'btn'

0 comments on commit 0273c31

Please sign in to comment.