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,2 @@
1
+ module Ums::FunctionsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Ums::LogsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Ums::RolesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Ums::UsersHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ module Ums
2
+ def self.table_name_prefix
3
+ 'ums_'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Ums::Function < ActiveRecord::Base
2
+ has_and_belongs_to_many :roles
3
+ validates_presence_of :name
4
+ validates_presence_of :controller
5
+ end
@@ -0,0 +1,2 @@
1
+ class Ums::Log < ActiveRecord::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class Ums::Role < ActiveRecord::Base
2
+ has_and_belongs_to_many :functions
3
+ validates_presence_of :name
4
+ end
@@ -0,0 +1,53 @@
1
+ class Ums::User < ActiveRecord::Base
2
+ belongs_to :role
3
+
4
+ validates_presence_of :name,:role,:email
5
+ validates_uniqueness_of :name
6
+
7
+ validate :password_non_blank
8
+
9
+
10
+ def self.authenticate(name,password)
11
+ user = self.find_by_name(name)
12
+ if user
13
+ expected_password = encrypted_password(password,user.salt)
14
+ if user.hashed_password != expected_password || !user.is_enabled
15
+ user = nil
16
+ end
17
+ end
18
+ user
19
+ end
20
+
21
+ def verify_password(password)
22
+ expected_password = Ums::User.encrypted_password(password,self.salt)
23
+ logger.debug("expected_password:"+expected_password+",hashed_password:"+self.hashed_password)
24
+ if self.hashed_password == expected_password
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ def password
32
+ @password
33
+ end
34
+
35
+ def password=(pwd)
36
+ @password = pwd
37
+ return if pwd.blank?
38
+ create_salt
39
+ self.hashed_password = Ums::User.encrypted_password(pwd,self.salt)
40
+ end
41
+
42
+ private
43
+ def password_non_blank
44
+ errors.add(:password,"missing password") if hashed_password.blank?
45
+
46
+ end
47
+ def self.encrypted_password(password,slat)
48
+ Digest::SHA1.hexdigest(password+slat)
49
+ end
50
+ def create_salt
51
+ self.salt = rand.to_s
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ums</title>
5
+ <%= stylesheet_link_tag "ums/application", media: "all" %>
6
+ <%= javascript_include_tag "ums/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,31 @@
1
+ <%= form_for(@ums_function) do |f| %>
2
+ <% if @ums_function.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@ums_function.errors.count, "error") %> prohibited this ums_function from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @ums_function.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name ,'功能名称'%>
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :controller,'模块名称'%>
20
+ <%= f.text_field :controller %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :action ,'操作名称'%>
24
+ <%= f.text_field :action %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit ' 保存 ',:class => 'btn btn-primary'%>
28
+ &nbsp;&nbsp;
29
+ <%= link_to ' 返回 ', ums.functions_path,:class => "btn btn-default" %>
30
+ </div>
31
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <h1>修改功能</h1>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,33 @@
1
+ <h1>功能列表
2
+ <small><%= link_to '新建功能', ums.new_function_path ,:class => "btn btn-primary" %></small>
3
+ </h1>
4
+ <% if flash[:notice] || flash[:error] %>
5
+ <div class="alert <%= "alert-success" if flash[:notice] %> <%= "alert-danger" if flash[:error] %>">
6
+ <a class="close" data-dismiss="alert">×</a>
7
+ <%= flash[:notice] %><%= flash[:error] %>
8
+ </div>
9
+ <% end %>
10
+ <table class="table table-striped table-bordered table-condensed">
11
+ <thead>
12
+ <tr>
13
+ <th>功能名称</th>
14
+ <th>模块名称</th>
15
+ <th>操作名称</th>
16
+ <th></th>
17
+ <th></th>
18
+ </tr>
19
+ </thead>
20
+
21
+ <tbody>
22
+ <% @ums_functions.each do |ums_function| %>
23
+ <tr>
24
+ <td><%= ums_function.name %></td>
25
+ <td><%= ums_function.controller %></td>
26
+ <td><%= ums_function.action %></td>
27
+ <td><%= link_to '修改', ums.edit_function_path(ums_function) %></td>
28
+ <td><%= link_to '删除', ums_function, method: :delete, data: { confirm: 'Are you sure?' } %></td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+
@@ -0,0 +1,5 @@
1
+ <h1>新建功能</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+
@@ -0,0 +1,29 @@
1
+ <h1>日志列表</h1>
2
+
3
+ <table class="table table-striped table-bordered table-condensed">
4
+ <thead>
5
+ <tr>
6
+ <th>日志类型</th>
7
+ <th>日志级别</th>
8
+ <th>日志内容</th>
9
+ <th>操作IP</th>
10
+ <th>操作时间</th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @ums_logs.each do |ums_log| %>
16
+ <tr>
17
+ <td><%= ums_log.log_type %></td>
18
+ <td><%= ums_log.level %></td>
19
+ <td><%= ums_log.data %></td>
20
+ <td><%= ums_log.ip %></td>
21
+ <td><%= ums_log.created_at.strftime('%Y-%m-%d %H:%M:%S') %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+ <div class="apple_pagination">
27
+ <%= page_entries_info @ums_logs %>
28
+ <%= will_paginate @ums_logs ,:container => false%>
29
+ </div>
@@ -0,0 +1,32 @@
1
+ <%= form_for(@ums_role) do |f| %>
2
+ <% if @ums_role.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@ums_role.errors.count, "error") %> prohibited this ums_role from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @ums_role.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name %>
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :functions ,'相关功能'%>
20
+ <% @ums_functions.each do |function| %>
21
+ <div>
22
+ <%= check_box_tag "role[function_ids][]", function.id, @ums_role.functions.include?(function) %>
23
+ <%= function.name %>
24
+ </div>
25
+ <% end %>
26
+ </div>
27
+ <div class="actions">
28
+ <%= f.submit ' 保存 ',:class => 'btn btn-primary'%>
29
+ &nbsp;&nbsp;
30
+ <%= link_to ' 返回 ', ums.roles_path,:class => "btn btn-default" %>
31
+ </div>
32
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <h1>修改角色</h1>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,36 @@
1
+ <h1>角色列表
2
+ <small><%= link_to '新建角色', ums.new_role_path ,:class => "btn btn-primary" %></small>
3
+ </h1>
4
+ <% if flash[:notice] || flash[:error] %>
5
+ <div class="alert <%= "alert-success" if flash[:notice] %> <%= "alert-danger" if flash[:error] %>">
6
+ <a class="close" data-dismiss="alert">×</a>
7
+ <%= flash[:notice] %><%= flash[:error] %>
8
+ </div>
9
+ <% end %>
10
+ <table class="table table-striped table-bordered table-condensed">
11
+ <thead>
12
+ <tr>
13
+ <th>角色名称</th>
14
+ <th>相关功能</th>
15
+ <th></th>
16
+ <th></th>
17
+ </tr>
18
+ </thead>
19
+
20
+ <tbody>
21
+ <% @ums_roles.each do |ums_role| %>
22
+ <tr>
23
+ <td><%= ums_role.name %></td>
24
+ <td>
25
+ <% ums_role.functions.each_with_index do | function,index |
26
+ concat function.name
27
+ concat "," if index + 1 < ums_role.functions.length
28
+ end
29
+ %>
30
+ </td>
31
+ <td><%= link_to '修改', ums.edit_role_path(ums_role) %></td>
32
+ <td><%= link_to '删除', ums_role, method: :delete, data: { confirm: 'Are you sure?' } %></td>
33
+ </tr>
34
+ <% end %>
35
+ </tbody>
36
+ </table>
@@ -0,0 +1,4 @@
1
+ <h1>新建角色</h1>
2
+
3
+ <%= render 'form' %>
4
+
@@ -0,0 +1,41 @@
1
+ <%= form_for(@ums_user) do |f| %>
2
+ <% if @ums_user.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@ums_user.errors.count, "error") %> prohibited this ums_user from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @ums_user.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name ,'用户名'%>
16
+ <%= f.text_field :name %>
17
+ </div>
18
+
19
+ <div class="field">
20
+ <%= f.label :password ,"密码" %>
21
+ <%= f.text_field :password %>
22
+ </div>
23
+ <div class="field">
24
+ <%= f.label :email ,'邮箱'%>
25
+ <%= f.text_field :email %>
26
+ </div>
27
+ <div class="field">
28
+ <%= f.label :role ,"角色"%>
29
+ <%= f.select :role_id, @ums_roles.collect {|p| [ p.name, p.id ] }%>
30
+ </div>
31
+ <div class="field">
32
+ <%= f.label :is_enabled ,'是否可用'%>
33
+ <%= f.check_box :is_enabled %>
34
+ </div>
35
+ <div class="actions">
36
+ <%= f.submit ' 保存 ',:class => 'btn btn-primary'%>
37
+ &nbsp;&nbsp;
38
+ <%= link_to ' 返回 ', ums.users_path,:class => "btn btn-default" %>
39
+ </div>
40
+ <% end %>
41
+
@@ -0,0 +1,3 @@
1
+ <h1>修改用户</h1>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,43 @@
1
+ <h1>用户列表
2
+ <small><%= link_to '新建用户', ums.new_user_path ,:class => "btn btn-primary" %></small>
3
+ </h1>
4
+ <% if flash[:notice] || flash[:error] %>
5
+ <div class="alert <%= "alert-success" if flash[:notice] %> <%= "alert-danger" if flash[:error] %>">
6
+ <a class="close" data-dismiss="alert">×</a>
7
+ <%= flash[:notice] %><%= flash[:error] %>
8
+ </div>
9
+ <% end %>
10
+ <table class="table table-striped table-bordered table-condensed">
11
+ <thead>
12
+ <tr>
13
+ <th>用户名</th>
14
+ <th>邮箱</th>
15
+ <th>上次登录时间</th>
16
+ <th>上次登录IP</th>
17
+ <th>登录次数</th>
18
+ <th>角色</th>
19
+ <th>是否可用</th>
20
+ <th></th>
21
+ <th></th>
22
+ </tr>
23
+ </thead>
24
+
25
+ <tbody>
26
+ <% @ums_users.each do |ums_user| %>
27
+ <tr>
28
+ <td><%= ums_user.name %></td>
29
+ <td><%= ums_user.email %></td>
30
+ <td><%= ums_user.last_login_time.strftime('%Y-%m-%d %H:%M:%S') if ums_user.last_login_time %></td>
31
+ <td><%= ums_user.last_login_ip %></td>
32
+ <td><%= ums_user.login_count %></td>
33
+ <td><%= ums_user.role.name %></td>
34
+ <td><span class="label <%= ums_user.is_enabled ? 'label-success' : 'label-default' %>">
35
+ <%= ums_user.is_enabled ? '是' : '否' %>
36
+ </span></td>
37
+ <td><%= link_to '修改', ums.edit_user_path(ums_user) %></td>
38
+ <td><%= link_to '删除', ums_user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
39
+ </tr>
40
+ <% end %>
41
+ </tbody>
42
+ </table>
43
+
@@ -0,0 +1,22 @@
1
+ <% if flash[:notice] || flash[:error] %>
2
+ <div class="alert <%= "alert-success" if flash[:notice] %> <%= "alert-error" if flash[:error] %>">
3
+ <a class="close" data-dismiss="alert">×</a>
4
+ <%= flash[:notice] %><%= flash[:error] %>
5
+ </div>
6
+ <% end %>
7
+ <%= form_tag do %>
8
+ <fieldset>
9
+ <legend>请登录</legend>
10
+ <div>
11
+ <label for="login_name">账号:</label>
12
+ <%= text_field_tag :login_name,params[:login_name] %>
13
+ </div>
14
+ <div>
15
+ <label for="password">密码:</label>
16
+ <%= password_field_tag :password,params[:password] %>
17
+ </div>
18
+ <div>
19
+ <%= submit_tag "登录" ,:class => "btn btn-primary" %>
20
+ </div>
21
+ </fieldset>
22
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <h1>退出登录</h1>
2
+
@@ -0,0 +1,3 @@
1
+ <h1>新建用户</h1>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,26 @@
1
+ <h1>修改密码</h1>
2
+ <% if flash[:notice] || flash[:error] %>
3
+ <div class="alert <%= "alert-success" if flash[:notice] %> <%= "alert-danger" if flash[:error] %>">
4
+ <a class="close" data-dismiss="alert">×</a>
5
+ <%= flash[:notice] %><%= flash[:error] %>
6
+ </div>
7
+ <% end %>
8
+ <%= form_tag do %>
9
+ <fieldset>
10
+ <div>
11
+ <label for="old_password">输入旧密码:</label>
12
+ <%= password_field_tag :old_password,params[:old_password] %>
13
+ </div>
14
+ <div>
15
+ <label for="new_password">输入新密码:</label>
16
+ <%= password_field_tag :new_password,params[:new_password] %>
17
+ </div>
18
+ <div>
19
+ <label for="re_password">重复新密码:</label>
20
+ <%= password_field_tag :re_password,params[:re_password] %>
21
+ </div>
22
+ <div>
23
+ <%= submit_tag "修改" ,:class => "btn btn-primary" %>
24
+ </div>
25
+ </fieldset>
26
+ <% end %>