Commit 0e1f35bf

mo khan <mo@mokhan.ca>
2014-05-22 04:32:45
move passwords to my/passwords.
1 parent 1ea8b4a
app/controllers/my/passwords_controller.rb
@@ -0,0 +1,24 @@
+module My
+  class PasswordsController < BaseController
+    def index
+      @user = current_user
+    end
+
+    def update
+      ChangePassword.new(self).run(params[:user][:password], params[:user][:password_confirmation])
+    end
+
+    def password_changed(user)
+      @user = user
+      sign_in(@user, bypass: true) unless Rails.env.test?
+      flash[:notice] = t('passwords.updated')
+      render :index
+    end
+
+    def password_changed_failed(user)
+      @user = user
+      flash[:error] = t(:passwords_do_not_match)
+      render :index
+    end
+  end
+end
app/controllers/passwords_controller.rb
@@ -1,24 +0,0 @@
-class PasswordsController < ApplicationController
-  before_filter :authenticate_user!
-
-  def index
-    @user = current_user
-  end
-
-  def update
-    ChangePassword.new(self).run(params[:user][:password], params[:user][:password_confirmation])
-  end
-
-  def password_changed(user)
-    @user = user
-    sign_in(@user, bypass: true) unless Rails.env.test?
-    flash[:notice] = t('passwords.updated')
-    render :index
-  end
-
-  def password_changed_failed(user)
-    @user = user
-    flash[:error] = t(:passwords_do_not_match)
-    render :index
-  end
-end
app/views/passwords/index.html.erb → app/views/my/passwords/index.html.erb
@@ -2,7 +2,7 @@
 
 <div class="row">
   <div class="span12">
-    <%= form_for(@user, :url => pwd_path, :html => { :method => :patch, :class => "form-horizontal" }) do |f| %>
+    <%= form_for(@user, :url => my_password_path(@user), :html => { :method => :patch, :class => "form-horizontal" }) do |f| %>
       <div class="control-group">
         <%= f.label :password, "New password", :class => "control-label" %>
         <div class="controls">
app/views/shared/_account_nav.html.erb
@@ -5,7 +5,7 @@
       <li class="<%= selected == :creations ? "active" : "" %>"><%= link_to "Creations", my_cakes_path %></li>
       <li class="<%= selected == :favorites ? "active" : "" %>"><%= link_to "Favorites", my_favorites_path %></li>
       <li class="<%= selected == :basic_info ? "active" : "" %>"><%= link_to "Settings", my_settings_path %></li>
-      <li class="<%= selected == :password ? "active" : "" %>"><%= link_to "Password", pwd_path %></li>
+      <li class="<%= selected == :password ? "active" : "" %>"><%= link_to "Password", my_passwords_path %></li>
       <li class="<%= selected == :picture ? "active" : "" %>"><%= link_to "Picture", edit_avatar_path(current_user) %></li>
       <li class="pull-right"><%= link_to t('.logout'), destroy_user_session_path, class: "btn btn-inverse" %></li>
       <% if current_user.is_admin? %>
config/routes.rb
@@ -44,8 +44,6 @@ Cake::Application.routes.draw do
   get "/sitemap.xml", :to => "sitemap#index", :defaults => {:format => :xml}
 
   resources :avatars, :only => [:edit, :update]
-  get 'pwd' => "passwords#index"
-  patch 'pwd' => "passwords#update"
 
   root :to => "creations#index"
 
@@ -69,6 +67,9 @@ Cake::Application.routes.draw do
     get 'dashboard', to: 'dashboard#index'
     resources :cakes, only: [:index]
     resources :favorites, only: [:index]
-    resources :settings, :only => [:index, :update]
+    resources :settings, only: [:index, :update]
+    resources :passwords, only: [:index, :update]
+    #get 'pwd' => "passwords#index"
+    #patch 'pwd' => "passwords#update"
   end
 end
spec/controllers/passwords_controller_spec.rb → spec/controllers/my/passwords_controller_spec.rb
@@ -1,6 +1,6 @@
 require "spec_helper"
 
-describe PasswordsController do
+describe My::PasswordsController do
   describe :update do
     context "when not logged in" do
       let(:user) { create(:user) }