Change user management. just manage password for admin user

This commit is contained in:
uu59 2014-05-22 11:04:24 +09:00
parent c4d05bd1fb
commit 80875d0b11
9 changed files with 70 additions and 25 deletions

View File

@ -1,7 +1,28 @@
class UsersController < ApplicationController
before_action :login_required
before_action :find_user
def index
@users = User.all
def show
end
def update
unless @user.authenticate(user_params[:current_password])
@user.errors.add(:current_password, :wrong_password)
return render :show
end
unless @user.update_attributes(user_params)
return render :show
end
redirect_to misc_user_path
end
private
def find_user
@user = User.first # user is only "admin"
end
def user_params
params.require(:user).permit(:current_password, :password, :password_confirmation)
end
end

View File

@ -1,8 +1,11 @@
class User < ActiveRecord::Base
has_secure_password
attr_accessor :current_password
validates :name, uniqueness: true, presence: true
validates :remember_token, uniqueness: true, allow_nil: true
validates :password, length: { minimum: 8 }
def generate_remember_token
begin

View File

@ -24,7 +24,7 @@
<%= link_to_other t("miscs.information.page_title"), information_misc_path %>
</li>
<li>
<%= link_to_other t('miscs.users.page_title'), misc_users_path %>
<%= link_to_other t('users.show.page_title'), misc_user_path %>
</li>
</ul>
<!-- /.nav-second-level -->

View File

@ -1,3 +0,0 @@
%ul
- @users.each do |user|
%li= user.name

View File

@ -0,0 +1,22 @@
- page_title t('.page_title')
%div.col-lg-6
- @user.errors.full_messages.each do |e|
= e
= form_for(:user, url: misc_user_path, method: :patch) do |f|
%div.form-group
= f.label :name
= f.text_field :name, class: "form-control", disabled: true
%div.form-group
= f.label :current_password
= f.password_field :current_password, class: "form-control"
%div.form-group
= f.label :password
= f.password_field :password, class: "form-control"
%div.form-group
= f.label :password_confirmation
= f.password_field :password_confirmation, class: "form-control"
= f.submit

View File

@ -17,7 +17,7 @@ ja:
no_alert: なし
plugins:
common: &common
common: &plugin_common
<<: *terms
name: プラグイン名
status: 状態
@ -30,23 +30,25 @@ ja:
recommended: &recommended おすすめプラグイン
updated: &updated 更新のあったプラグイン
installed:
<<: *common
<<: *plugin_common
page_title: *installed
recommended:
<<: *common
<<: *plugin_common
page_title: *recommended
updated:
<<: *common
<<: *plugin_common
page_title: *updated
miscs:
common: &common
<<: *terms
users:
<<: *common
users: &users
<<: *terms
show:
page_title: ユーザー管理
miscs:
common: &misc_common
<<: *terms
information:
<<: *common
<<: *misc_common
env: 環境変数
env_key: キー
env_value:
@ -60,6 +62,10 @@ ja:
login_failed: ログインに失敗しました。
activerecord:
errors:
messages:
wrong_password: が違います
models:
user: user #g
@ -68,3 +74,6 @@ ja:
name: name #g
password_digest: password_digest #g
remember_token: remember_token #g
current_password: 現在のパスワード
password: パスワード
password_confirmation: パスワード(確認)

View File

@ -12,7 +12,6 @@ Rails.application.routes.draw do
end
end
resources :users
resource :sessions
resources :plugins do
@ -29,7 +28,6 @@ Rails.application.routes.draw do
resource :misc do
get "information"
resources :users do
end
resource :user, only: [:show, :edit, :update]
end
end

View File

@ -6,4 +6,4 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
User.create(name: "admin", password: "changeme")
User.create!(name: "admin", password: "changeme")

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe UsersController do
end