unidom-visitor 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e641cf324c2fb45f41dfce8e6f372008f43acc90
4
+ data.tar.gz: cd1ff7e5604974336ff574488ca4d526f4d23569
5
+ SHA512:
6
+ metadata.gz: 2bdda625df72006e1e1770aa82d5520de0bf2ce657bbbf2499e2d97616fd484c1dd3c9215dbd378d673c8d4861fb7c79032be4aea7799e7630ebbe2da153575f
7
+ data.tar.gz: 46aad786b8be29d8ba8c244b674813f76f2de6a9808bbd2578f5f1534b76cf99481170ca6b223d08741a08a26a6e3e81eaae3fb4caa08f2660aacea035464d61
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Topbit Du
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # Unidom Visitor
2
+
3
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
+
5
+ Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Visitor domain model engine includes User, Guest, Administrator, and Password models.
6
+ Unidom (统一领域对象模型)是一系列的领域模型引擎。访问者领域模型引擎包括用户、游客、管理员和密码的模型。
7
+
8
+ ## Usage in Gemfile:
9
+ ```ruby
10
+ gem 'unidom-visitor'
11
+ ```
12
+
13
+ ## Run the Database Migration:
14
+ ```shell
15
+ rake db:migrate
16
+ ```
17
+
18
+ ## Call the Model:
19
+ ```ruby
20
+ Unidom::Visitor::User.valid_at.alive.first
21
+ Unidom::Visitor::Guest.valid_at.alive.first
22
+ Unidom::Visitor::User.valid_at.alive.first.passwords.valid_at.alive.first.merge(Unidom::Visitor::Authenticating.valid_at.alive).first
23
+ ```
@@ -0,0 +1,24 @@
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 = 'Visitor'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -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 any plugin's vendor/assets/javascripts directory 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/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class Unidom::Visitor::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module Unidom::Visitor::ApplicationHelper
2
+ end
@@ -0,0 +1,21 @@
1
+ # Authenticating 是身份鉴定,存储访问者(visitor)和信任状(credential)之间的关系。
2
+ # flag_code 有4个枚举值:RQRD (required)、SFCT (sufficient)、RQST (requisite)、OPTN (optional)。
3
+ # 各枚举值的含义见: http://docs.oracle.com/javase/8/docs/technotes/guides/security/jaas/JAASRefGuide.html 。
4
+
5
+ class Unidom::Visitor::Authenticating < ActiveRecord::Base
6
+
7
+ self.table_name = 'unidom_authenticatings'
8
+
9
+ belongs_to :visitor, polymorphic: true
10
+ belongs_to :credential, polymorphic: true
11
+
12
+ scope :visitor_is, ->(visitor) { where visitor: visitor }
13
+ scope :credential_is, ->(credential) { where credential: credential }
14
+
15
+ include ::Unidom::Common::Concerns::ModelExtension
16
+
17
+ def self.authenticate(visitor, credential)
18
+ self.create! visitor: visitor, credential: credential, opened_at: Time.now
19
+ end
20
+
21
+ end
@@ -0,0 +1,13 @@
1
+ # Guest 是系统访客。
2
+
3
+ class Unidom::Visitor::Guest < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_guests'
6
+
7
+ validates :platform_specific_identification, presence: true, length: { in: 2..self.columns_hash['platform_specific_identification'].limit }
8
+
9
+ scope :platform_specific_identification_is, ->(platform_specific_identification) { where platform_specific_identification: platform_specific_identification }
10
+
11
+ include ::Unidom::Common::Concerns::ModelExtension
12
+
13
+ end
@@ -0,0 +1,23 @@
1
+ # Identificating 是身份关联,存储身份(identity)和访问者(visitor)之间的关联关系。
2
+
3
+ class Unidom::Visitor::Identificating < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_identificatings'
6
+
7
+ belongs_to :identity, polymorphic: true
8
+ belongs_to :visitor, polymorphic: true
9
+
10
+ scope :identity_is, ->(identity) { where identity: identity }
11
+ scope :visitor_is, ->(visitor) { where visitor: visitor }
12
+
13
+ include ::Unidom::Common::Concerns::ModelExtension
14
+
15
+ def self.find_identity(visitor)
16
+ visitor_is(visitor).first.try :identity
17
+ end
18
+
19
+ def self.identificate(visitor, identity)
20
+ self.visitor_is(visitor).identity_is(identity).valid_at.alive.first_or_create opened_at: Time.now
21
+ end
22
+
23
+ end
@@ -0,0 +1,45 @@
1
+ # Password 是密码。
2
+
3
+ class Unidom::Visitor::Password < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_passwords'
6
+
7
+ has_one :authenticating, class_name: 'Unidom::Visitor::Authenticating', as: :credential
8
+
9
+ include ::Unidom::Common::Concerns::ModelExtension
10
+
11
+ def generate_pepper_content
12
+ self.pepper_content = self.pepper_content||::SecureRandom.hex(self.class.columns_hash['pepper_content'].limit/2)
13
+ end
14
+
15
+ def clear_text
16
+ ''
17
+ end
18
+
19
+ def clear_text=(password)
20
+ generate_pepper_content
21
+ self.hashed_content = hash password
22
+ end
23
+
24
+ def matched?(password)
25
+ hash(password)==self.hashed_content
26
+ end
27
+
28
+ def hash(clear_text)
29
+ Digest::SHA512.hexdigest "#{::Rails.application.secrets[:secret_key_base]}#{clear_text}#{self.pepper_content}"
30
+ end
31
+
32
+ def change_to(new_password)
33
+ visitor = authenticating.visitor
34
+ soft_destroy
35
+ password = Password.new clear_text: new_password
36
+ if password.save
37
+ Authenticating.authenticate user, password
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ private :hash
44
+
45
+ end
@@ -0,0 +1,21 @@
1
+ # Recognization 是访问者识别,用于维护访问者和参与者的对应关系。
2
+
3
+ class Unidom::Visitor::Recognization < ActiveRecord::Base
4
+
5
+ self.table = 'unidom_recognizations'
6
+
7
+ belongs_to :visitor, polymorphic: true
8
+ belongs_to :party, polymorphic: true
9
+
10
+ scope :visitor_is, ->(visitor) { where visitor: visitor }
11
+ scope :party_is, ->(party) { where party: party }
12
+
13
+ include ::Unidom::Common::Concerns::ModelExtension
14
+
15
+ def self.cognize(visitor, party)
16
+ raise 'Visitor can not be null.' if visitor.blank?
17
+ raise 'Party can not be null.' if party.blank?
18
+ recognization = visitor_is(visitor).party_is(party).first_or_create elemental: true, opened_at: Time.now
19
+ end
20
+
21
+ end
@@ -0,0 +1,33 @@
1
+ # User 是系统用户。
2
+
3
+ class Unidom::Visitor::User < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_users'
6
+
7
+ has_many :identificatings, class_name: 'Unidom::Visitor::Identificating', as: :visitor
8
+
9
+ has_many :authenticatings, class_name: 'Unidom::Visitor::Authenticating', as: :visitor
10
+ has_many :passwords, through: :authenticatings, source: :credential, source_type: 'Unidom::Visitor::Password'
11
+
12
+ has_many :recognizations, class_name: 'Unidom::Visitor::Recognization', as: :visitor
13
+
14
+ scope :identified_by, ->(identity) { joins(:identificatings).merge(::Unidom::Visitor::Identificating.identity_is identity) }
15
+
16
+ include ::Unidom::Common::Concerns::ModelExtension
17
+
18
+ def self.sign_up(identity, password)
19
+
20
+ return false if identified_by(identity).valid_at.alive.merge(::Identificating.valid_at.alive).count>0
21
+
22
+ now = Time.now
23
+ user = self.create! opened_at: now
24
+ credential = ::Unidom::Visitor::Password.create! clear_text: password, opened_at: now
25
+
26
+ identificating = ::Unidom::Visitor::Identificating.identificate user, identity
27
+ authenticating = ::Unidom::Visitor::Authenticating.authenticate user, credential
28
+
29
+ user
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Unidom Visitor</title>
5
+ <%= stylesheet_link_tag 'unidom/visitor/application', media: 'all' %>
6
+ <%= javascript_include_tag 'unidom/visitor/application' %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ Unidom::Visitor::Engine.routes.draw do
2
+ end
@@ -0,0 +1,27 @@
1
+ class CreateUnidomIdentificatings < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_identificatings, id: :uuid do |t|
6
+
7
+ t.references :identity, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+ t.references :visitor, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+
12
+ t.column :state, 'char(1)', null: false, default: 'C'
13
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
14
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
15
+ t.boolean :defunct, null: false, default: false
16
+ t.jsonb :notation, null: false, default: {}
17
+
18
+ t.timestamps null: false
19
+
20
+ end
21
+
22
+ add_index :unidom_identificatings, :identity_id
23
+ add_index :unidom_identificatings, :visitor_id
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,29 @@
1
+ class CreateUnidomAuthenticatings < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_authenticatings, id: :uuid do |t|
6
+
7
+ t.references :visitor, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+ t.references :credential, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+
12
+ t.column :flag_code, 'char(4)', null: false, default: 'RQRD'
13
+
14
+ t.column :state, 'char(1)', null: false, default: 'C'
15
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
16
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
17
+ t.boolean :defunct, null: false, default: false
18
+ t.jsonb :notation, null: false, default: {}
19
+
20
+ t.timestamps null: false
21
+
22
+ end
23
+
24
+ add_index :unidom_authenticatings, :visitor_id
25
+ add_index :unidom_authenticatings, :credential_id
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ class CreateUnidomRecognizations < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_recognizations, id: :uuid do |t|
6
+
7
+ t.references :visitor, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+ t.references :party, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+
12
+ t.boolean :elemental, null: false, default: false
13
+
14
+ t.column :state, 'char(1)', null: false, default: 'C'
15
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
16
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
17
+ t.boolean :defunct, null: false, default: false
18
+ t.jsonb :notation, null: false, default: {}
19
+
20
+ t.timestamps null: false
21
+
22
+ end
23
+
24
+ add_index :unidom_recognizations, :visitor_id
25
+ add_index :unidom_recognizations, :party_id
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,24 @@
1
+ class CreateUnidomGuests < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_guests, id: :uuid do |t|
6
+
7
+ t.column :platform_code, 'char(4)', null: false, default: 'SITE'
8
+ t.string :platform_specific_identification, null: false, default: '', limit: 200
9
+
10
+ t.column :state, 'char(1)', null: false, default: 'C'
11
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
12
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
13
+ t.boolean :defunct, null: false, default: false
14
+ t.jsonb :notation, null: false, default: {}
15
+
16
+ t.timestamps null: false
17
+
18
+ end
19
+
20
+ add_index :unidom_guests, [ :platform_specific_identification, :platform_code ], unique: true, name: :index_guests_on_platform_identification
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ class CreateUnidomUsers < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_users, id: :uuid do |t|
6
+
7
+ t.column :state, 'char(1)', null: false, default: 'C'
8
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
9
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
10
+ t.boolean :defunct, null: false, default: false
11
+ t.jsonb :notation, null: false, default: {}
12
+
13
+ t.timestamps null: false
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,24 @@
1
+ class CreateUnidomPasswords < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_passwords, id: :uuid do |t|
6
+
7
+ t.column :hashed_content, 'char(128)', null: false
8
+ t.column :pepper_content, 'char(128)', null: false
9
+
10
+ t.column :state, 'char(1)', null: false, default: 'C'
11
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
12
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
13
+ t.boolean :defunct, null: false, default: false
14
+ t.jsonb :notation, null: false, default: {}
15
+
16
+ t.timestamps null: false
17
+
18
+ end
19
+
20
+ add_index :unidom_passwords, :hashed_content
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :visitor do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ require 'unidom/visitor/engine'
2
+
3
+ module Unidom
4
+ module Visitor
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module Unidom
2
+ module Visitor
3
+
4
+ class Engine < ::Rails::Engine
5
+
6
+ isolate_namespace ::Unidom::Visitor
7
+
8
+ initializer :append_migrations do |app|
9
+ config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless app.root.to_s.match root.to_s
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Unidom
2
+ module Visitor
3
+ VERSION = '0.1'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unidom-visitor
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unidom-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
+ The Visitor domain model engine includes User, Guest, Administrator, and Password
29
+ models. Unidom (统一领域对象模型)是一系列的领域模型引擎。访问者领域模型引擎包括用户、游客、管理员和密码的模型。
30
+ email:
31
+ - topbit.du@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - app/assets/javascripts/unidom/visitor/application.js
40
+ - app/assets/stylesheets/unidom/visitor/application.css
41
+ - app/controllers/unidom/visitor/application_controller.rb
42
+ - app/helpers/unidom/visitor/application_helper.rb
43
+ - app/models/unidom/visitor/authenticating.rb
44
+ - app/models/unidom/visitor/guest.rb
45
+ - app/models/unidom/visitor/identificating.rb
46
+ - app/models/unidom/visitor/password.rb
47
+ - app/models/unidom/visitor/recognization.rb
48
+ - app/models/unidom/visitor/user.rb
49
+ - app/views/layouts/unidom/visitor/application.html.erb
50
+ - config/routes.rb
51
+ - db/migrate/20000201000000_create_unidom_identificatings.rb
52
+ - db/migrate/20000202000000_create_unidom_authenticatings.rb
53
+ - db/migrate/20000203000000_create_unidom_recognizations.rb
54
+ - db/migrate/20000210000000_create_unidom_guests.rb
55
+ - db/migrate/20000211000000_create_unidom_users.rb
56
+ - db/migrate/20000220000000_create_unidom_passwords.rb
57
+ - lib/tasks/visitor_tasks.rake
58
+ - lib/unidom/visitor.rb
59
+ - lib/unidom/visitor/engine.rb
60
+ - lib/unidom/visitor/version.rb
61
+ homepage: https://github.com/topbitdu/unidom-visitor
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.5.1
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: The Visitor domain model engine includes User, Guest, Administrator, and
85
+ Password models.
86
+ test_files: []