ums 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 064961d8ca4ae8073ab7f3b042f19b023d2db79f
4
- data.tar.gz: 1863125d14a533c676be160553898d060ce8eb04
3
+ metadata.gz: 7923f5094754722a2c451d3a951249487bab2668
4
+ data.tar.gz: f362e18f75cf1cd6dd74ecd2559fed18a8f8c100
5
5
  SHA512:
6
- metadata.gz: 0ae519a7a351d85effb442f2769a46512b04e314a6e4474e38d1e500fe98f2d06388baeb479dd2d1ddffe940c40aec64bf7325a7d266967a991a0bb5b912570e
7
- data.tar.gz: 46f7626fb5cc968e598e5a7624b988bcbd418b7b2045fddd485f5b970fbcecf9e0dcd76f1e1d9a66ed9c6c6228733b00820bdd7c2287531b64c1f41aad887ed1
6
+ metadata.gz: 898fdaa99bed7774ce6de88c9cd2930b886f0c5fb3bd8c00aee05cd5fa6d4e56f5bafff02541e0cc5bab982cef293ef6e9906004efe491a1a79336457a1d24ec
7
+ data.tar.gz: 4d26b8df5511a8165a1139361ace7bb3f884ecb04ba1c2be450d5311e24438857c8e23680cf1eef3f0a6825c2f0d943c3ac9d90887b7eab8b731754d777a4129
@@ -28,7 +28,7 @@ class Ums::FunctionsController < ApplicationController
28
28
 
29
29
  respond_to do |format|
30
30
  if @ums_function.save
31
- format.html { redirect_to ums.functions_url, notice: 'Function was successfully created.' }
31
+ format.html { redirect_to ums.functions_url, notice: '功能创建创建成功.' }
32
32
  format.json { render action: 'show', status: :created, location: @ums_function }
33
33
  else
34
34
  format.html { render action: 'new' }
@@ -42,7 +42,7 @@ class Ums::FunctionsController < ApplicationController
42
42
  def update
43
43
  respond_to do |format|
44
44
  if @ums_function.update(ums_function_params)
45
- format.html { redirect_to ums.functions_url, notice: 'Function was successfully updated.' }
45
+ format.html { redirect_to ums.functions_url, notice: '功能修改成功' }
46
46
  format.json { head :no_content }
47
47
  else
48
48
  format.html { render action: 'edit' }
@@ -56,7 +56,7 @@ class Ums::FunctionsController < ApplicationController
56
56
  def destroy
57
57
  @ums_function.destroy
58
58
  respond_to do |format|
59
- format.html { redirect_to ums.functions_url }
59
+ format.html { redirect_to ums.functions_url , notice: '功能删除成功.'}
60
60
  format.json { head :no_content }
61
61
  end
62
62
  end
@@ -29,7 +29,7 @@ class Ums::RolesController < ApplicationController
29
29
 
30
30
  respond_to do |format|
31
31
  if @ums_role.save
32
- format.html { redirect_to ums.roles_url, notice: 'Role was successfully created.' }
32
+ format.html { redirect_to ums.roles_url, notice: '角色创建成功.' }
33
33
  format.json { render action: 'show', status: :created, location: @ums_role }
34
34
  else
35
35
  format.html { render action: 'new' }
@@ -43,7 +43,7 @@ class Ums::RolesController < ApplicationController
43
43
  def update
44
44
  respond_to do |format|
45
45
  if @ums_role.update(ums_role_params)
46
- format.html { redirect_to ums.roles_url, notice: 'Role was successfully updated.' }
46
+ format.html { redirect_to ums.roles_url, notice: '角色修改成功.' }
47
47
  format.json { head :no_content }
48
48
  else
49
49
  format.html { render action: 'edit' }
@@ -61,7 +61,7 @@ class Ums::RolesController < ApplicationController
61
61
  @ums_role.destroy
62
62
  end
63
63
  respond_to do |format|
64
- format.html { redirect_to ums.roles_url }
64
+ format.html { redirect_to ums.roles_url , notice: '角色删除成功.'}
65
65
  format.json { head :no_content }
66
66
  end
67
67
  end
@@ -1,34 +1,42 @@
1
1
  class Ums::UsersController < ApplicationController
2
2
 
3
3
  skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
4
- skip_before_filter :authorize, :only => [:login,:logout,:profile,:password]
4
+ skip_before_filter :authorize, :only => [:login,:logout]
5
5
 
6
6
  before_action :set_ums_user, only: [:show, :edit, :update, :destroy]
7
7
  before_action :set_ums_roles, only: [:new,:edit,:update,:create]
8
8
  # GET /ums/users
9
9
  # GET /ums/users.json
10
10
 
11
- def login
11
+ def welcome
12
+ end
13
+
14
+ def login
12
15
  if request.post?
13
- #account = Account.authenticate(params[:login_name],params[:password])
14
- user = Ums::User.authenticate(params[:login_name],params[:password])
16
+ user = Ums::User.authenticate(params[:account],params[:password])
15
17
  if user
16
18
  login_count = user.login_count
17
19
  login_count = 0 if login_count.nil?
18
20
  login_count += 1
21
+
22
+ session[:last_login_time] = user.last_login_time
23
+ session[:last_login_ip] = user.last_login_ip
24
+ session[:login_count] = login_count
25
+
19
26
  user.last_login_time = Time.now
20
27
  user.last_login_ip = request.remote_ip
21
28
  user.login_count = login_count
22
29
  user.save(validate: false)
23
30
 
24
31
  session[:user_id] = user.id
32
+ session[:user_account] = user.account
25
33
  session[:user_name] = user.name
26
34
 
27
35
  uri = session[:original_uri]
28
36
  session[:original_uri] = nil
29
- log_info("login",params[:login_name] + " login success",request.remote_ip)
37
+ log_info("login",params[:account] + " login success",request.remote_ip)
30
38
 
31
- user_permission = '^redactor_rails|' # 上传组件
39
+ user_permission = '^redactor_rails|welcome|profile|password|' # 上传组件和用户基础操作默认许可
32
40
  user.role.functions.each do |function|
33
41
  if function.action.blank?
34
42
  user_permission += '^' + function.controller
@@ -43,11 +51,11 @@ class Ums::UsersController < ApplicationController
43
51
 
44
52
  respond_to do |format|
45
53
  format.html { redirect_to uri || main_index_path }
46
- format.json { render json: {is_success:"true",message:""} }
54
+ format.json { render json: {is_success:"true",message:"登录成功",user:user} }
47
55
  end
48
56
 
49
57
  else
50
- log_error("login",params[:login_name] + " login failed",request.remote_ip)
58
+ log_error("login",params[:account] + " login failed",request.remote_ip)
51
59
  respond_to do |format|
52
60
  error_info = "无效的账号或密码"
53
61
  format.html { flash.now[:notice] = error_info }
@@ -60,8 +68,11 @@ class Ums::UsersController < ApplicationController
60
68
 
61
69
  def logout
62
70
  session[:user_id] = nil
71
+ session[:user_account] = nil
63
72
  session[:user_name] = nil
64
-
73
+ session[:last_login_time] = nil
74
+ session[:last_login_ip] = nil
75
+ session[:login_count] = nil
65
76
  #flash[:notice] = "已退出"
66
77
  redirect_to '/' #main_index_path
67
78
  end
@@ -127,7 +138,7 @@ class Ums::UsersController < ApplicationController
127
138
 
128
139
  respond_to do |format|
129
140
  if @ums_user.save
130
- format.html { redirect_to ums.users_url, notice: 'User was successfully created.' }
141
+ format.html { redirect_to ums.users_url, notice: '用户创建成功.' }
131
142
  format.json { render action: 'show', status: :created, location: @ums_user }
132
143
  else
133
144
  format.html { render action: 'new' }
@@ -141,7 +152,7 @@ class Ums::UsersController < ApplicationController
141
152
  def update
142
153
  respond_to do |format|
143
154
  if @ums_user.update(ums_user_params)
144
- format.html { redirect_to ums.users_url, notice: 'User was successfully updated.' }
155
+ format.html { redirect_to ums.users_url, notice: '用户修改成功.' }
145
156
  format.json { head :no_content }
146
157
  else
147
158
  format.html { render action: 'edit' }
@@ -155,7 +166,7 @@ class Ums::UsersController < ApplicationController
155
166
  def destroy
156
167
  @ums_user.destroy
157
168
  respond_to do |format|
158
- format.html { redirect_to ums.users_url }
169
+ format.html { redirect_to ums.users_url, notice: '用户删除成功.' }
159
170
  format.json { head :no_content }
160
171
  end
161
172
  end
@@ -168,7 +179,7 @@ class Ums::UsersController < ApplicationController
168
179
 
169
180
  # Never trust parameters from the scary internet, only allow the white list through.
170
181
  def ums_user_params
171
- params.require(:user).permit(:name, :email, :password, :role_id, :is_enabled)
182
+ params.require(:user).permit(:account, :name,:email, :password, :role_id, :is_enabled)
172
183
  end
173
184
 
174
185
  def set_ums_roles
@@ -12,7 +12,7 @@ module Ums
12
12
 
13
13
  path = params[:controller] + "/" + params[:action]
14
14
  unless validate_permission(path)
15
- render status: :forbidden, text: "访问被拒绝"
15
+ render status: :forbidden, text: "对不起,您没有访问该地址的权限"
16
16
  end
17
17
  end
18
18
 
@@ -1,16 +1,17 @@
1
1
  class Ums::User < ActiveRecord::Base
2
2
  belongs_to :role
3
3
 
4
- validates_presence_of :name,:role,:email
5
- validates_uniqueness_of :name
4
+ validates_presence_of :account,:role
5
+ validates_uniqueness_of :account,:name
6
6
 
7
7
  validate :password_non_blank
8
8
 
9
9
 
10
- def self.authenticate(name,password)
11
- user = self.find_by_name(name)
10
+ def self.authenticate(account,password)
11
+ user = self.find_by_account(account)
12
12
  if user
13
13
  expected_password = encrypted_password(password,user.salt)
14
+ #logger.debug("user.hashed_password:" + user.hashed_password + ",expected_password:" + expected_password)
14
15
  if user.hashed_password != expected_password || !user.is_enabled
15
16
  user = nil
16
17
  end
@@ -38,6 +39,12 @@ class Ums::User < ActiveRecord::Base
38
39
  create_salt
39
40
  self.hashed_password = Ums::User.encrypted_password(pwd,self.salt)
40
41
  end
42
+
43
+ def as_json options=nil
44
+ options ||= {}
45
+ options[:except] = [:hashed_password,:salt]
46
+ super options
47
+ end
41
48
 
42
49
  private
43
50
  def password_non_blank
@@ -12,10 +12,13 @@
12
12
  <% end %>
13
13
 
14
14
  <div class="field">
15
- <%= f.label :name ,'用户名'%>
15
+ <%= f.label :account ,'账号'%>
16
+ <%= f.text_field :account %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :name ,'姓名'%>
16
20
  <%= f.text_field :name %>
17
21
  </div>
18
-
19
22
  <div class="field">
20
23
  <%= f.label :password ,"密码" %>
21
24
  <%= f.text_field :password %>
@@ -8,8 +8,8 @@
8
8
  <fieldset>
9
9
  <legend>请登录</legend>
10
10
  <div>
11
- <label for="login_name">账号:</label>
12
- <%= text_field_tag :login_name,params[:login_name] %>
11
+ <label for="account">账号:</label>
12
+ <%= text_field_tag :account,params[:account] %>
13
13
  </div>
14
14
  <div>
15
15
  <label for="password">密码:</label>
@@ -0,0 +1,10 @@
1
+
2
+ <fieldset>
3
+ <legend>欢迎您的登录</legend>
4
+ <div>
5
+ 这是您第<%= session[:login_count]%>次登录.
6
+ <% if session[:login_count] > 1 %>
7
+ 您上次登录时间是: <%= session[:last_login_time].strftime('%Y-%m-%d %H:%M') %>,登录IP为: <%= session[:last_login_ip]%>
8
+ <% end %>
9
+ </div>
10
+ </fieldset>
@@ -1,4 +1,6 @@
1
1
  Ums::Engine.routes.draw do
2
+
3
+ root :to => 'users#welcome'
2
4
  get "users/login"
3
5
  post "users/login"
4
6
  get "users/password"
@@ -6,6 +8,7 @@ Ums::Engine.routes.draw do
6
8
  get "users/profile"
7
9
  patch "users/profile"
8
10
  get "users/logout"
11
+ get "users/welcome"
9
12
  resources :users
10
13
  resources :roles
11
14
  resources :functions
@@ -1,6 +1,7 @@
1
1
  class CreateUmsUsers < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :ums_users do |t|
4
+ t.string :account
4
5
  t.string :name
5
6
  t.string :email
6
7
  t.string :hashed_password
@@ -7,5 +7,6 @@
7
7
  # Mayor.create(name: 'Emanuel', city: cities.first)
8
8
  functions = Ums::Function.create([{name:"用户管理",controller:'ums'}])
9
9
  role = Ums::Role.create(name:'系统管理员',functions:functions)
10
- Ums::User.create(name: "admin",hashed_password: "4b1323850c4283da817ef95f32e0b00f2f31a4b2",
10
+ #初始账号:admin 密码:admin
11
+ Ums::User.create(account: "admin",name: "系统管理员",hashed_password: "4b1323850c4283da817ef95f32e0b00f2f31a4b2",
11
12
  salt: "0.8575214227141923",login_count:0,is_enabled:true,role:role)
@@ -1,5 +1,10 @@
1
1
  module Ums
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Ums
4
+ config.to_prepare do
5
+ Dir.glob(Rails.root + "app/decorators/**/*_decorator*.rb").each do |c|
6
+ require_dependency(c)
7
+ end
8
+ end
4
9
  end
5
10
  end
@@ -1,3 +1,3 @@
1
1
  module Ums
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,72 @@
1
+  (2.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
2
+  (0.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
4
+ Migrating to CreateUmsFunctions (20131016015419)
5
+  (0.1ms) begin transaction
6
+  (0.8ms) CREATE TABLE "ums_functions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "controller" varchar(255), "action" varchar(255), "created_at" datetime, "updated_at" datetime) 
7
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131016015419"]]
8
+  (0.7ms) commit transaction
9
+ Migrating to CreateUmsRoles (20131016015456)
10
+  (0.1ms) begin transaction
11
+  (0.4ms) CREATE TABLE "ums_roles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) 
12
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131016015456"]]
13
+  (0.8ms) commit transaction
14
+ Migrating to CreateUmsUsers (20131016015833)
15
+  (0.1ms) begin transaction
16
+  (1.0ms) CREATE TABLE "ums_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "hashed_password" varchar(255), "salt" varchar(255), "last_login_time" datetime, "last_login_ip" varchar(255), "login_count" integer, "role_id" integer, "is_enabled" boolean, "created_at" datetime, "updated_at" datetime) 
17
+  (0.2ms) CREATE INDEX "index_ums_users_on_role_id" ON "ums_users" ("role_id")
18
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131016015833"]]
19
+  (1.8ms) commit transaction
20
+ Migrating to CreateUmsLogs (20131016020202)
21
+  (0.1ms) begin transaction
22
+  (0.4ms) CREATE TABLE "ums_logs" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "log_type" varchar(255), "level" varchar(255), "data" text, "ip" varchar(255), "created_at" datetime, "updated_at" datetime)
23
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131016020202"]]
24
+  (0.8ms) commit transaction
25
+ Migrating to CreateUmsFunctionsRoles (20131016020423)
26
+  (0.1ms) begin transaction
27
+  (0.5ms) CREATE TABLE "ums_functions_roles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "function_id" integer, "role_id" integer)
28
+  (0.2ms) CREATE INDEX "index_ums_functions_roles_on_function_id" ON "ums_functions_roles" ("function_id")
29
+  (0.1ms) CREATE INDEX "index_ums_functions_roles_on_role_id" ON "ums_functions_roles" ("role_id")
30
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131016020423"]]
31
+  (0.8ms) commit transaction
32
+ Migrating to CreateUmsProductCategories (20131106063317)
33
+  (0.1ms) begin transaction
34
+  (0.6ms) CREATE TABLE "ums_product_categories" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "code" varchar(255), "picture" varchar(255), "created_at" datetime, "updated_at" datetime)
35
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106063317"]]
36
+  (1.0ms) commit transaction
37
+ Migrating to CreateUmsProductColors (20131106063633)
38
+  (0.1ms) begin transaction
39
+  (0.3ms) CREATE TABLE "ums_product_colors" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime)
40
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106063633"]]
41
+  (0.8ms) commit transaction
42
+ Migrating to CreateUmsProductMaterials (20131106063658)
43
+  (0.2ms) begin transaction
44
+  (0.7ms) CREATE TABLE "ums_product_materials" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime)
45
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106063658"]]
46
+  (1.2ms) commit transaction
47
+ Migrating to CreateUmsProductBrands (20131106063719)
48
+  (0.1ms) begin transaction
49
+  (0.7ms) CREATE TABLE "ums_product_brands" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime)
50
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106063719"]]
51
+  (0.8ms) commit transaction
52
+ Migrating to CreateUmsProductSurfaces (20131106064312)
53
+  (0.1ms) begin transaction
54
+  (0.4ms) CREATE TABLE "ums_product_surfaces" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "code" varchar(255), "material" varchar(255), "color" varchar(255), "created_at" datetime, "updated_at" datetime)
55
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106064312"]]
56
+  (0.6ms) commit transaction
57
+ Migrating to CreateUmsProductItems (20131106071449)
58
+  (0.1ms) begin transaction
59
+  (0.7ms) CREATE TABLE "ums_product_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "code" varchar(255), "category_id" integer, "material_id" integer, "length" integer, "width" integer, "height" integer, "depth" integer, "diameter" integer, "brand_id" integer, "stock_price" integer, "sell_price" integer, "description" text, "picture_id" integer, "created_at" datetime, "updated_at" datetime)
60
+  (0.2ms) CREATE INDEX "index_ums_product_items_on_category_id" ON "ums_product_items" ("category_id")
61
+  (0.2ms) CREATE INDEX "index_ums_product_items_on_material_id" ON "ums_product_items" ("material_id")
62
+  (0.2ms) CREATE INDEX "index_ums_product_items_on_brand_id" ON "ums_product_items" ("brand_id")
63
+  (0.3ms) CREATE INDEX "index_ums_product_items_on_picture_id" ON "ums_product_items" ("picture_id")
64
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106071449"]]
65
+  (1.4ms) commit transaction
66
+ Migrating to CreateUmsProductPictrues (20131106071729)
67
+  (0.2ms) begin transaction
68
+  (0.8ms) CREATE TABLE "ums_product_pictrues" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "item_id" integer, "path" varchar(255), "description" text, "created_at" datetime, "updated_at" datetime)
69
+  (0.3ms) CREATE INDEX "index_ums_product_pictrues_on_item_id" ON "ums_product_pictrues" ("item_id")
70
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131106071729"]]
71
+  (0.9ms) commit transaction
72
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ums
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wangfuhai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-03 00:00:00.000000000 Z
11
+ date: 2013-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,7 @@ files:
94
94
  - app/views/ums/users/new.html.erb
95
95
  - app/views/ums/users/password.html.erb
96
96
  - app/views/ums/users/profile.html.erb
97
+ - app/views/ums/users/welcome.html.erb
97
98
  - config/routes.rb
98
99
  - db/migrate/20131016015419_create_ums_functions.rb
99
100
  - db/migrate/20131016015456_create_ums_roles.rb
@@ -133,6 +134,7 @@ files:
133
134
  - test/dummy/config/locales/en.yml
134
135
  - test/dummy/config/routes.rb
135
136
  - test/dummy/config.ru
137
+ - test/dummy/log/development.log
136
138
  - test/dummy/public/404.html
137
139
  - test/dummy/public/422.html
138
140
  - test/dummy/public/500.html
@@ -191,6 +193,7 @@ test_files:
191
193
  - test/dummy/config/locales/en.yml
192
194
  - test/dummy/config/routes.rb
193
195
  - test/dummy/config.ru
196
+ - test/dummy/log/development.log
194
197
  - test/dummy/public/404.html
195
198
  - test/dummy/public/422.html
196
199
  - test/dummy/public/500.html