ums 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/ums/application.js +13 -0
  5. data/app/assets/stylesheets/ums/application.css +13 -0
  6. data/app/controllers/ums/application_controller.rb +5 -0
  7. data/app/controllers/ums/functions_controller.rb +74 -0
  8. data/app/controllers/ums/logs_controller.rb +9 -0
  9. data/app/controllers/ums/roles_controller.rb +86 -0
  10. data/app/controllers/ums/users_controller.rb +177 -0
  11. data/app/helpers/ums/application_helper.rb +46 -0
  12. data/app/helpers/ums/functions_helper.rb +2 -0
  13. data/app/helpers/ums/logs_helper.rb +2 -0
  14. data/app/helpers/ums/roles_helper.rb +2 -0
  15. data/app/helpers/ums/users_helper.rb +2 -0
  16. data/app/models/ums.rb +5 -0
  17. data/app/models/ums/function.rb +5 -0
  18. data/app/models/ums/log.rb +2 -0
  19. data/app/models/ums/role.rb +4 -0
  20. data/app/models/ums/user.rb +53 -0
  21. data/app/views/layouts/ums/application.html.erb +14 -0
  22. data/app/views/ums/functions/_form.html.erb +31 -0
  23. data/app/views/ums/functions/edit.html.erb +3 -0
  24. data/app/views/ums/functions/index.html.erb +33 -0
  25. data/app/views/ums/functions/new.html.erb +5 -0
  26. data/app/views/ums/logs/index.html.erb +29 -0
  27. data/app/views/ums/roles/_form.html.erb +32 -0
  28. data/app/views/ums/roles/edit.html.erb +3 -0
  29. data/app/views/ums/roles/index.html.erb +36 -0
  30. data/app/views/ums/roles/new.html.erb +4 -0
  31. data/app/views/ums/users/_form.html.erb +41 -0
  32. data/app/views/ums/users/edit.html.erb +3 -0
  33. data/app/views/ums/users/index.html.erb +43 -0
  34. data/app/views/ums/users/login.html.erb +22 -0
  35. data/app/views/ums/users/logout.html.erb +2 -0
  36. data/app/views/ums/users/new.html.erb +3 -0
  37. data/app/views/ums/users/password.html.erb +26 -0
  38. data/app/views/ums/users/profile.html.erb +30 -0
  39. data/config/routes.rb +13 -0
  40. data/db/migrate/20131016015419_create_ums_functions.rb +11 -0
  41. data/db/migrate/20131016015456_create_ums_roles.rb +9 -0
  42. data/db/migrate/20131016015833_create_ums_users.rb +17 -0
  43. data/db/migrate/20131016020202_create_ums_logs.rb +12 -0
  44. data/db/migrate/20131016020423_create_ums_functions_roles.rb +8 -0
  45. data/db/seeds.rb +11 -0
  46. data/lib/tasks/ums_tasks.rake +4 -0
  47. data/lib/ums.rb +4 -0
  48. data/lib/ums/engine.rb +5 -0
  49. data/lib/ums/version.rb +3 -0
  50. data/test/dummy/README.rdoc +28 -0
  51. data/test/dummy/Rakefile +6 -0
  52. data/test/dummy/app/assets/javascripts/application.js +13 -0
  53. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  54. data/test/dummy/app/controllers/application_controller.rb +5 -0
  55. data/test/dummy/app/helpers/application_helper.rb +2 -0
  56. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  57. data/test/dummy/bin/bundle +3 -0
  58. data/test/dummy/bin/rails +4 -0
  59. data/test/dummy/bin/rake +4 -0
  60. data/test/dummy/config.ru +4 -0
  61. data/test/dummy/config/application.rb +23 -0
  62. data/test/dummy/config/boot.rb +5 -0
  63. data/test/dummy/config/database.yml +25 -0
  64. data/test/dummy/config/environment.rb +5 -0
  65. data/test/dummy/config/environments/development.rb +29 -0
  66. data/test/dummy/config/environments/production.rb +80 -0
  67. data/test/dummy/config/environments/test.rb +36 -0
  68. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  69. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  70. data/test/dummy/config/initializers/inflections.rb +16 -0
  71. data/test/dummy/config/initializers/mime_types.rb +5 -0
  72. data/test/dummy/config/initializers/secret_token.rb +12 -0
  73. data/test/dummy/config/initializers/session_store.rb +3 -0
  74. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  75. data/test/dummy/config/locales/en.yml +23 -0
  76. data/test/dummy/config/routes.rb +4 -0
  77. data/test/dummy/public/404.html +58 -0
  78. data/test/dummy/public/422.html +58 -0
  79. data/test/dummy/public/500.html +57 -0
  80. data/test/dummy/public/favicon.ico +0 -0
  81. data/test/integration/navigation_test.rb +10 -0
  82. data/test/test_helper.rb +15 -0
  83. data/test/ums_test.rb +7 -0
  84. metadata +201 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 272ed6c390ebe0b96fff511b1e2e3ffe7eda162f
4
+ data.tar.gz: ee84462764d1d8368553dc8c4878dff2c2b665a7
5
+ SHA512:
6
+ metadata.gz: af4f78d9f7651fae64fde42e4e250a2b9797564daf06cfebeb81dbeeb8d37bf7cbbac39c5c632313667b1af0f987c291b2f6acc3cbaa61e5a295b0e68938263d
7
+ data.tar.gz: 6b6db9df31ab86f4e8044e4cbbe105c472b482b34add3bcfd3e62820334d9eb15de0d463e7d8b35acc88dc841b7debf25ab0470a430bcc4cb21cecab45283764
@@ -0,0 +1,3 @@
1
+ = Ums
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ums'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ module Ums
2
+ #class ApplicationController < ActionController::Base
3
+ class Ums::ApplicationController < ApplicationController
4
+ end
5
+ end
@@ -0,0 +1,74 @@
1
+ class Ums::FunctionsController < ApplicationController
2
+ before_action :set_ums_function, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /ums/functions
5
+ # GET /ums/functions.json
6
+ def index
7
+ @ums_functions = Ums::Function.all
8
+ end
9
+
10
+ # GET /ums/functions/1
11
+ # GET /ums/functions/1.json
12
+ def show
13
+ end
14
+
15
+ # GET /ums/functions/new
16
+ def new
17
+ @ums_function = Ums::Function.new
18
+ end
19
+
20
+ # GET /ums/functions/1/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /ums/functions
25
+ # POST /ums/functions.json
26
+ def create
27
+ @ums_function = Ums::Function.new(ums_function_params)
28
+
29
+ respond_to do |format|
30
+ if @ums_function.save
31
+ format.html { redirect_to ums.functions_url, notice: 'Function was successfully created.' }
32
+ format.json { render action: 'show', status: :created, location: @ums_function }
33
+ else
34
+ format.html { render action: 'new' }
35
+ format.json { render json: @ums_function.errors, status: :unprocessable_entity }
36
+ end
37
+ end
38
+ end
39
+
40
+ # PATCH/PUT /ums/functions/1
41
+ # PATCH/PUT /ums/functions/1.json
42
+ def update
43
+ respond_to do |format|
44
+ if @ums_function.update(ums_function_params)
45
+ format.html { redirect_to ums.functions_url, notice: 'Function was successfully updated.' }
46
+ format.json { head :no_content }
47
+ else
48
+ format.html { render action: 'edit' }
49
+ format.json { render json: @ums_function.errors, status: :unprocessable_entity }
50
+ end
51
+ end
52
+ end
53
+
54
+ # DELETE /ums/functions/1
55
+ # DELETE /ums/functions/1.json
56
+ def destroy
57
+ @ums_function.destroy
58
+ respond_to do |format|
59
+ format.html { redirect_to ums.functions_url }
60
+ format.json { head :no_content }
61
+ end
62
+ end
63
+
64
+ private
65
+ # Use callbacks to share common setup or constraints between actions.
66
+ def set_ums_function
67
+ @ums_function = Ums::Function.find(params[:id])
68
+ end
69
+
70
+ # Never trust parameters from the scary internet, only allow the white list through.
71
+ def ums_function_params
72
+ params.require(:function).permit(:name, :controller, :action)
73
+ end
74
+ end
@@ -0,0 +1,9 @@
1
+ class Ums::LogsController < ApplicationController
2
+
3
+ # GET /ums/logs
4
+ # GET /ums/logs.json
5
+ def index
6
+ @ums_logs = Ums::Log.all.page(params[:page]).order("id DESC")
7
+ end
8
+
9
+ end
@@ -0,0 +1,86 @@
1
+ class Ums::RolesController < ApplicationController
2
+ before_action :set_ums_role, only: [:show, :edit, :update, :destroy]
3
+ before_action :set_ums_functions, only: [:new,:edit,:update,:create]
4
+ before_action :init_function_ids, only: [:create, :update]
5
+ # GET /ums/roles
6
+ # GET /ums/roles.json
7
+ def index
8
+ @ums_roles = Ums::Role.all
9
+ end
10
+
11
+ # GET /ums/roles/1
12
+ # GET /ums/roles/1.json
13
+ def show
14
+ end
15
+
16
+ # GET /ums/roles/new
17
+ def new
18
+ @ums_role = Ums::Role.new
19
+ end
20
+
21
+ # GET /ums/roles/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /ums/roles
26
+ # POST /ums/roles.json
27
+ def create
28
+ @ums_role = Ums::Role.new(ums_role_params)
29
+
30
+ respond_to do |format|
31
+ if @ums_role.save
32
+ format.html { redirect_to ums.roles_url, notice: 'Role was successfully created.' }
33
+ format.json { render action: 'show', status: :created, location: @ums_role }
34
+ else
35
+ format.html { render action: 'new' }
36
+ format.json { render json: @ums_role.errors, status: :unprocessable_entity }
37
+ end
38
+ end
39
+ end
40
+
41
+ # PATCH/PUT /ums/roles/1
42
+ # PATCH/PUT /ums/roles/1.json
43
+ def update
44
+ respond_to do |format|
45
+ if @ums_role.update(ums_role_params)
46
+ format.html { redirect_to ums.roles_url, notice: 'Role was successfully updated.' }
47
+ format.json { head :no_content }
48
+ else
49
+ format.html { render action: 'edit' }
50
+ format.json { render json: @ums_role.errors, status: :unprocessable_entity }
51
+ end
52
+ end
53
+ end
54
+
55
+ # DELETE /ums/roles/1
56
+ # DELETE /ums/roles/1.json
57
+ def destroy
58
+ if Ums::User.find_by_role_id(@ums_role.id)
59
+ flash[:error] = "该角色还有关联用户,不能删除"
60
+ else
61
+ @ums_role.destroy
62
+ end
63
+ respond_to do |format|
64
+ format.html { redirect_to ums.roles_url }
65
+ format.json { head :no_content }
66
+ end
67
+ end
68
+
69
+ private
70
+ # Use callbacks to share common setup or constraints between actions.
71
+ def set_ums_role
72
+ @ums_role = Ums::Role.find(params[:id])
73
+ end
74
+
75
+ # Never trust parameters from the scary internet, only allow the white list through.
76
+ def ums_role_params
77
+ params.require(:role).permit(:name,{:function_ids => []})
78
+ end
79
+ def set_ums_functions
80
+ @ums_functions = Ums::Function.all
81
+ end
82
+
83
+ def init_function_ids
84
+ params[:role][:function_ids] ||= []
85
+ end
86
+ end
@@ -0,0 +1,177 @@
1
+ class Ums::UsersController < ApplicationController
2
+
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]
5
+
6
+ before_action :set_ums_user, only: [:show, :edit, :update, :destroy]
7
+ before_action :set_ums_roles, only: [:new,:edit,:update,:create]
8
+ # GET /ums/users
9
+ # GET /ums/users.json
10
+
11
+ def login
12
+ if request.post?
13
+ #account = Account.authenticate(params[:login_name],params[:password])
14
+ user = Ums::User.authenticate(params[:login_name],params[:password])
15
+ if user
16
+ login_count = user.login_count
17
+ login_count = 0 if login_count.nil?
18
+ login_count += 1
19
+ user.last_login_time = Time.now
20
+ user.last_login_ip = request.remote_ip
21
+ user.login_count = login_count
22
+ user.save(validate: false)
23
+
24
+ session[:user_id] = user.id
25
+ session[:user_name] = user.name
26
+
27
+ uri = session[:original_uri]
28
+ session[:original_uri] = nil
29
+ log_info("login",params[:login_name] + " login success",request.remote_ip)
30
+
31
+ user_permission = '^redactor_rails|' # 上传组件
32
+ user.role.functions.each do |function|
33
+ if function.action.blank?
34
+ user_permission += '^' + function.controller
35
+ else
36
+ user_permission += function.controller + "/" + function.action
37
+ end
38
+ user_permission += "|"
39
+ end
40
+
41
+ user_permission.chop! unless user_permission.blank?
42
+ session[:user_permission] = user_permission
43
+
44
+ respond_to do |format|
45
+ format.html { redirect_to uri || main_index_path }
46
+ format.json { render json: {is_success:"true",message:""} }
47
+ end
48
+
49
+ else
50
+ log_error("login",params[:login_name] + " login failed",request.remote_ip)
51
+ respond_to do |format|
52
+ error_info = "无效的账号或密码"
53
+ format.html { flash.now[:notice] = error_info }
54
+ format.json { render json: {is_success:"false",message:error_info} }
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+
61
+ def logout
62
+ session[:user_id] = nil
63
+ session[:user_name] = nil
64
+
65
+ #flash[:notice] = "已退出"
66
+ redirect_to '/' #main_index_path
67
+ end
68
+
69
+ def password
70
+ if request.post?
71
+ if params[:new_password].blank?
72
+ flash.now[:error] = "新密码不能为空"
73
+ return
74
+ end
75
+ if params[:new_password] != params[:re_password]
76
+ flash.now[:error] = "两次新密码输入不一致"
77
+ return
78
+ end
79
+ if params[:new_password].blank?
80
+ flash.now[:error] = "新密码不能为空"
81
+ return
82
+ end
83
+ user = Ums::User.find_by_id(session[:user_id])
84
+ if user.verify_password(params[:old_password])
85
+ user.password=params[:new_password]
86
+ user.save
87
+ flash.now[:notice] = "密码修改成功"
88
+ params.delete(:new_password)
89
+ params.delete(:old_password)
90
+ params.delete(:re_password)
91
+ else
92
+ flash.now[:error] = "旧密码输入错误"
93
+ end
94
+ end
95
+ end
96
+
97
+ def profile
98
+ @ums_user = Ums::User.find_by_id(session[:user_id])
99
+ if request.patch?
100
+ if @ums_user.update(params.require(:user).permit(:email))
101
+ flash.now[:notice] = "资料修改成功"
102
+ else
103
+ flash.now[:error] = "资料修改失败"
104
+ end
105
+ end
106
+ end
107
+
108
+ def index
109
+ @ums_users = Ums::User.all
110
+ end
111
+ def show
112
+ end
113
+ # GET /ums/users/new
114
+ def new
115
+ @ums_user = Ums::User.new
116
+ @ums_user.is_enabled = true
117
+ end
118
+
119
+ # GET /ums/users/1/edit
120
+ def edit
121
+ end
122
+
123
+ # POST /ums/users
124
+ # POST /ums/users.json
125
+ def create
126
+ @ums_user = Ums::User.new(ums_user_params)
127
+
128
+ respond_to do |format|
129
+ if @ums_user.save
130
+ format.html { redirect_to ums.users_url, notice: 'User was successfully created.' }
131
+ format.json { render action: 'show', status: :created, location: @ums_user }
132
+ else
133
+ format.html { render action: 'new' }
134
+ format.json { render json: @ums_user.errors, status: :unprocessable_entity }
135
+ end
136
+ end
137
+ end
138
+
139
+ # PATCH/PUT /ums/users/1
140
+ # PATCH/PUT /ums/users/1.json
141
+ def update
142
+ respond_to do |format|
143
+ if @ums_user.update(ums_user_params)
144
+ format.html { redirect_to ums.users_url, notice: 'User was successfully updated.' }
145
+ format.json { head :no_content }
146
+ else
147
+ format.html { render action: 'edit' }
148
+ format.json { render json: @ums_user.errors, status: :unprocessable_entity }
149
+ end
150
+ end
151
+ end
152
+
153
+ # DELETE /ums/users/1
154
+ # DELETE /ums/users/1.json
155
+ def destroy
156
+ @ums_user.destroy
157
+ respond_to do |format|
158
+ format.html { redirect_to ums.users_url }
159
+ format.json { head :no_content }
160
+ end
161
+ end
162
+
163
+ private
164
+ # Use callbacks to share common setup or constraints between actions.
165
+ def set_ums_user
166
+ @ums_user = Ums::User.find(params[:id])
167
+ end
168
+
169
+ # Never trust parameters from the scary internet, only allow the white list through.
170
+ def ums_user_params
171
+ params.require(:user).permit(:name, :email, :password, :role_id, :is_enabled)
172
+ end
173
+
174
+ def set_ums_roles
175
+ @ums_roles = Ums::Role.all
176
+ end
177
+ end
@@ -0,0 +1,46 @@
1
+ module Ums
2
+ module ApplicationHelper
3
+
4
+ def authorize
5
+ #unless Account.find_by_id(session[:account_id])
6
+ if session[:user_id].nil?
7
+ session[:original_uri] = request.url
8
+ #flash[:notice] = "Please log in"
9
+ redirect_to ums.users_login_url
10
+ return
11
+ end
12
+
13
+ path = params[:controller] + "/" + params[:action]
14
+ unless validate_permission(path)
15
+ render status: :forbidden, text: "访问被拒绝"
16
+ end
17
+ end
18
+
19
+ def log_info(log_type,log_content,log_ip)
20
+ log = Ums::Log.new
21
+ log.level="info"
22
+ log.log_type=log_type
23
+ log.data=log_content
24
+ log.ip=log_ip
25
+ log.save
26
+ end
27
+
28
+ def log_error(log_type,log_content,log_ip)
29
+ log = Ums::Log.new
30
+ log.level="error"
31
+ log.log_type=log_type
32
+ log.data=log_content
33
+ log.ip=log_ip
34
+ log.save
35
+ end
36
+
37
+ def validate_permission(path)
38
+ permission = session[:user_permission]
39
+
40
+ logger.debug("user_permission:" + permission) unless permission.nil?
41
+ logger.debug("user_path:" + path) unless path.nil?
42
+ return false if permission.nil? || path.nil?
43
+ return path.match(permission)
44
+ end
45
+ end
46
+ end