monban-repository 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.envrc +5 -0
- data/.git_release_request.rc.sh +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +12 -0
- data/.travis.yml +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +21 -0
- data/README.md +49 -0
- data/Rakefile +10 -0
- data/db/migrations/001_create_account_tables.rb +94 -0
- data/lib/monban/repository/account.rb +173 -0
- data/lib/monban/repository/account/search.rb +71 -0
- data/lib/monban/repository/auth.rb +181 -0
- data/lib/monban/repository/version.rb +5 -0
- data/monban-repository.gemspec +38 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a84fd086512207130b39cd7dfc1bcfc69199570dd9e547390f5428eb7c7ab598
|
4
|
+
data.tar.gz: 6bf11c038378c5510e9db251a20c28449899a2fec1e9e08743353eabaf25cfa4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0976737e267cb290f0c204f8b124b5728fd9957bb2fbbc46ffff2b38eecea16d6aeed5edba84a9030d82c24b7cb1dc6d578b35e1ff1017b23034d8351773291d
|
7
|
+
data.tar.gz: 1d062a203904569c671f8ba7f3e2004d6f37d7d64d4c83ceb60f66793b7017190b20099deacaa4ab0a7ed6348863cd9f2148ed01d2b58b343bf0ecbeb8e749bf
|
data/.envrc
ADDED
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.5.1
|
5
|
+
before_install: gem install bundler -v 1.16.2
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
gem: monban-repository
|
9
|
+
on:
|
10
|
+
tags: true
|
11
|
+
api_key:
|
12
|
+
secure: "F4xwXKdn2jwnfomfXfUkj4eQ0vdztXhGr63mQRoB5DfHRxv63iqG5mRxYqOzge77JLhJHOIiWp1OO2tweeRXssbNqOtdOUXsEnmzSe+PVJu6X+jD0/8WIMRkINSYQAH1fgVYAVlFvf2Z5S3c8iSP3KgacmpV+NEehPumsw4QIfE/y8AlH+tUjd2QKTTzIuJM/JSen4kxFtziUIoc1ejbB/tZW3+HU3Cv2BfOb0UXm/ZzCylYrYKUJM836vo0529EP2LBg3/V2wLzh+jJEQdU2+VJoAY5tVj3rS1ciEgZuMVgIPVMAYO45GAVXEDHJkm+YzC5VVTKAv6L+BZ4pWY1xFLjYc80nWM/syDJ/RDFhfGueDD90aIq3h4uB91+A4/LCsK7ZxONakn/wNvBE5vo67uyWKp7ADKzAZON3STuhb9yBN6uHIad5wdup8NbRpUy7aTlrEABMwq6MfSgFiM9/mB7e81DE672274qr2bO4iRlydyp33wciiroyBvUwIckMtel9N8xQ9q/j3kiBvXKqSswY8lh8AN5py26wr13F/yt6yJ5OI0vt0jdKZ+f5K4XLVNv/9VGTOkjM/4H9EF5YHKrofg6GH2cGObXfccx6PNoGVnnMaRcReRXaguv6ausbZEEQu+Z1kjQQcyqJM0E02ACg4yERo3LONYG12i7g5o="
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
monban-repository (0.1.0)
|
5
|
+
getto-initialize_with (~> 1.0)
|
6
|
+
getto-repository-sequel (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
docile (1.3.1)
|
12
|
+
getto-initialize_with (1.0.1)
|
13
|
+
getto-repository (1.0.1)
|
14
|
+
getto-repository-sequel (1.0.1)
|
15
|
+
getto-repository (~> 1.0.0)
|
16
|
+
sequel (~> 5.13.0)
|
17
|
+
json (2.1.0)
|
18
|
+
minitest (5.11.3)
|
19
|
+
rake (10.5.0)
|
20
|
+
sequel (5.13.0)
|
21
|
+
simplecov (0.16.1)
|
22
|
+
docile (~> 1.1)
|
23
|
+
json (>= 1.8, < 3)
|
24
|
+
simplecov-html (~> 0.10.0)
|
25
|
+
simplecov-html (0.10.2)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.16)
|
32
|
+
minitest (~> 5.0)
|
33
|
+
monban-repository!
|
34
|
+
rake (~> 10.0)
|
35
|
+
simplecov (~> 0.16)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.16.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 shun@getto.systems
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# monban-repository
|
2
|
+
|
3
|
+
[rubygems: monban-repository](https://rubygems.org/gems/monban-repository)
|
4
|
+
|
5
|
+
[Monban](https://github.com/getto-systems/rubygems-monban-repository) - repository implementation
|
6
|
+
|
7
|
+
|
8
|
+
###### Table of Contents
|
9
|
+
|
10
|
+
- [Requirements](#Requirements)
|
11
|
+
- [Usage](#Usage)
|
12
|
+
- [License](#License)
|
13
|
+
|
14
|
+
<a id="Requirements"></a>
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
- developed on ruby: 2.5.1
|
18
|
+
|
19
|
+
|
20
|
+
<a id="Usage"></a>
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
## Install
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'monban-repository'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
```
|
34
|
+
$ bundle
|
35
|
+
```
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
```
|
40
|
+
$ gem install monban-repository
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
<a id="License"></a>
|
45
|
+
## License
|
46
|
+
|
47
|
+
monban/repository is licensed under the [MIT](LICENSE) license.
|
48
|
+
|
49
|
+
Copyright © since 2018 shun@getto.systems
|
data/Rakefile
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
transaction
|
3
|
+
|
4
|
+
up do
|
5
|
+
create_table(:accounts) do
|
6
|
+
primary_key :id, type: :Bignum
|
7
|
+
|
8
|
+
DateTime :created_at, null: false
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table(:account_login_ids) do
|
12
|
+
foreign_key :account_id, :accounts, primary_key: true, type: :Bignum
|
13
|
+
|
14
|
+
String :login_id, null: false
|
15
|
+
|
16
|
+
DateTime :created_at, null: false
|
17
|
+
DateTime :updated_at, null: false
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table(:account_public_ids) do
|
21
|
+
primary_key :id, type: :Bignum
|
22
|
+
foreign_key :account_id, :accounts, type: :Bignum
|
23
|
+
|
24
|
+
String :public_id, null: false
|
25
|
+
|
26
|
+
DateTime :created_at, null: false
|
27
|
+
DateTime :expired_at, null: false
|
28
|
+
DateTime :original_created_at, null: false
|
29
|
+
|
30
|
+
index :public_id, unique: true
|
31
|
+
end
|
32
|
+
|
33
|
+
create_table(:account_roles) do
|
34
|
+
primary_key :id, type: :Bignum
|
35
|
+
foreign_key :account_id, :accounts, type: :Bignum
|
36
|
+
|
37
|
+
String :role, null: false
|
38
|
+
|
39
|
+
DateTime :created_at, null: false
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table(:account_password_hashes) do
|
43
|
+
foreign_key :account_id, :accounts, primary_key: true, type: :Bignum
|
44
|
+
|
45
|
+
String :password_hash, null: false
|
46
|
+
|
47
|
+
DateTime :created_at, null: false
|
48
|
+
DateTime :updated_at, null: false
|
49
|
+
|
50
|
+
index :password_hash
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table(:account_authy_ids) do
|
54
|
+
foreign_key :account_id, :accounts, primary_key: true, type: :Bignum
|
55
|
+
|
56
|
+
Bignum :authy_id, null: false
|
57
|
+
|
58
|
+
DateTime :created_at, null: true
|
59
|
+
DateTime :updated_at, null: true
|
60
|
+
end
|
61
|
+
|
62
|
+
create_table(:account_reset_password_emails) do
|
63
|
+
foreign_key :account_id, :accounts, primary_key: true, type: :Bignum
|
64
|
+
|
65
|
+
String :email, null: false
|
66
|
+
|
67
|
+
DateTime :created_at, null: false
|
68
|
+
DateTime :updated_at, null: false
|
69
|
+
end
|
70
|
+
|
71
|
+
create_table(:account_reset_password_tokens) do
|
72
|
+
primary_key :id, type: :Bignum
|
73
|
+
foreign_key :account_id, :accounts, type: :Bignum
|
74
|
+
|
75
|
+
String :reset_token, null: false
|
76
|
+
|
77
|
+
DateTime :created_at, null: false
|
78
|
+
DateTime :expired_at, null: false
|
79
|
+
|
80
|
+
index :reset_token, unique: true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
down do
|
85
|
+
drop_table(:account_reset_password_tokens,
|
86
|
+
:account_reset_password_emails,
|
87
|
+
:account_authy_ids,
|
88
|
+
:account_password_hashes,
|
89
|
+
:account_roles,
|
90
|
+
:account_public_ids,
|
91
|
+
:account_login_ids,
|
92
|
+
:accounts)
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require "getto/repository/sequel"
|
2
|
+
|
3
|
+
module Monban
|
4
|
+
# :nocov:
|
5
|
+
module Repository
|
6
|
+
module Account
|
7
|
+
|
8
|
+
class Sequel < Getto::Repository::Sequel
|
9
|
+
|
10
|
+
def account_exists?(account_id:)
|
11
|
+
not db[:accounts]
|
12
|
+
.where(id: account_id)
|
13
|
+
.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def login_id_exists?(login_id:)
|
17
|
+
not db[:account_login_ids]
|
18
|
+
.where(login_id: login_id)
|
19
|
+
.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
def login_id_account(login_id:)
|
23
|
+
db[:account_login_ids]
|
24
|
+
.where(login_id: login_id)
|
25
|
+
.select(:account_id)
|
26
|
+
.map{|hash| hash[:account_id]}.first
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset_password_email_account(email:)
|
30
|
+
db[:account_reset_password_emails]
|
31
|
+
.where(email: email)
|
32
|
+
.select(:account_id)
|
33
|
+
.map{|hash| hash[:account_id]}.first
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def login_id(account_id:)
|
38
|
+
db[:account_login_ids]
|
39
|
+
.where(account_id: account_id)
|
40
|
+
.select(:login_id)
|
41
|
+
.map{|hash| hash[:login_id]}.first
|
42
|
+
end
|
43
|
+
|
44
|
+
def roles(account_id:)
|
45
|
+
db[:account_roles]
|
46
|
+
.where(account_id: account_id)
|
47
|
+
.select(:role)
|
48
|
+
.map{|r| r[:role]}
|
49
|
+
end
|
50
|
+
|
51
|
+
def reset_password_email(account_id:)
|
52
|
+
db[:account_reset_password_emails]
|
53
|
+
.where(account_id: account_id)
|
54
|
+
.select(:email)
|
55
|
+
.map{|hash| hash[:email]}.first
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def insert_account(now:)
|
60
|
+
db[:accounts].insert(
|
61
|
+
created_at: now,
|
62
|
+
)
|
63
|
+
last_insert_id
|
64
|
+
end
|
65
|
+
|
66
|
+
def insert_login_id(account_id:, login_id:, now:)
|
67
|
+
db[:account_login_ids].insert(
|
68
|
+
account_id: account_id,
|
69
|
+
login_id: login_id,
|
70
|
+
created_at: now,
|
71
|
+
updated_at: now,
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def update_reset_password_email(account_id:, email:, now:)
|
77
|
+
where = {
|
78
|
+
account_id: account_id,
|
79
|
+
}
|
80
|
+
if db[:account_reset_password_emails].where(where).empty?
|
81
|
+
db[:account_reset_password_emails].insert(
|
82
|
+
account_id: account_id,
|
83
|
+
email: email,
|
84
|
+
created_at: now,
|
85
|
+
updated_at: now,
|
86
|
+
)
|
87
|
+
else
|
88
|
+
db[:account_reset_password_emails].where(where).update(
|
89
|
+
email: email,
|
90
|
+
updated_at: now,
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def update_login_id(account_id:, login_id:, now:)
|
96
|
+
where = {
|
97
|
+
account_id: account_id,
|
98
|
+
}
|
99
|
+
if login_id.empty?
|
100
|
+
db[:account_login_ids].where(where).delete
|
101
|
+
else
|
102
|
+
if db[:account_login_ids].where(where).empty?
|
103
|
+
db[:account_login_ids].insert(
|
104
|
+
account_id: account_id,
|
105
|
+
login_id: login_id,
|
106
|
+
updated_at: now,
|
107
|
+
created_at: now,
|
108
|
+
)
|
109
|
+
else
|
110
|
+
db[:account_login_ids]
|
111
|
+
.where(account_id: account_id)
|
112
|
+
.update(
|
113
|
+
login_id: login_id,
|
114
|
+
updated_at: now,
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def update_roles(account_id:, roles:, now:)
|
121
|
+
old_roles = db[:account_roles]
|
122
|
+
.where(account_id: account_id)
|
123
|
+
.select(:role)
|
124
|
+
.map{|hash| hash[:role]}
|
125
|
+
|
126
|
+
roles.each do |role|
|
127
|
+
unless old_roles.delete(role.to_s)
|
128
|
+
db[:account_roles].insert(
|
129
|
+
account_id: account_id,
|
130
|
+
role: role.to_s,
|
131
|
+
created_at: now,
|
132
|
+
)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
old_roles.each do |role|
|
137
|
+
db[:account_roles]
|
138
|
+
.where(
|
139
|
+
account_id: account_id,
|
140
|
+
role: role,
|
141
|
+
)
|
142
|
+
.delete
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def delete_account(account_id:)
|
148
|
+
[
|
149
|
+
#:account_public_ids, # DO NOT DELETE public_id
|
150
|
+
:account_login_ids,
|
151
|
+
:account_authy_ids,
|
152
|
+
:account_password_hashes,
|
153
|
+
:account_reset_password_tokens,
|
154
|
+
:account_roles,
|
155
|
+
:account_reset_password_emails,
|
156
|
+
].each do |table|
|
157
|
+
db[table].where(account_id: account_id).delete
|
158
|
+
end
|
159
|
+
|
160
|
+
# nullify account_id instead of delete rows
|
161
|
+
db[:account_public_ids]
|
162
|
+
.where(account_id: account_id)
|
163
|
+
.update(account_id: nil)
|
164
|
+
|
165
|
+
db[:accounts].where(id: account_id).delete
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
# :nocov:
|
173
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "getto/repository/sequel"
|
2
|
+
require "getto/repository/sequel/search"
|
3
|
+
|
4
|
+
module Monban
|
5
|
+
# :nocov:
|
6
|
+
module Repository
|
7
|
+
module Account
|
8
|
+
module Search
|
9
|
+
|
10
|
+
class Sequel < Getto::Repository::Sequel
|
11
|
+
def search(limit:, offset:, sort:, query:)
|
12
|
+
search = Getto::Repository::Sequel::Search.new(limit: limit, sort: sort, query: query)
|
13
|
+
|
14
|
+
where = search.where do |w|
|
15
|
+
w.search "login_id.cont", &w.cont(::Sequel[:account_login_ids][:login_id])
|
16
|
+
end
|
17
|
+
order = search.order do |o|
|
18
|
+
o.order :login_id, ::Sequel[:account_login_ids][:login_id]
|
19
|
+
|
20
|
+
o.force ::Sequel[:account_login_ids][:login_id]
|
21
|
+
end
|
22
|
+
|
23
|
+
pages = search.pages(
|
24
|
+
db[:accounts]
|
25
|
+
.where(where)
|
26
|
+
.count
|
27
|
+
)
|
28
|
+
|
29
|
+
accounts =
|
30
|
+
db[:accounts]
|
31
|
+
.left_join(:account_login_ids, account_id: :id)
|
32
|
+
.where(where)
|
33
|
+
.limit(limit)
|
34
|
+
.offset(offset)
|
35
|
+
.order(*order)
|
36
|
+
.select(
|
37
|
+
::Sequel[:accounts][:id],
|
38
|
+
::Sequel[:account_login_ids][:login_id],
|
39
|
+
)
|
40
|
+
.all
|
41
|
+
|
42
|
+
emails = db[:account_reset_password_emails]
|
43
|
+
.where(account_id: accounts.map{|row| row[:id]})
|
44
|
+
.group_and_count(:account_id)
|
45
|
+
.map{|email| [email[:account_id], email[:count] > 0] }.to_h
|
46
|
+
|
47
|
+
roles = db[:account_roles]
|
48
|
+
.where(account_id: accounts.map{|row| row[:id]})
|
49
|
+
.select(:account_id,:role)
|
50
|
+
.all.group_by{|role| role[:account_id]}
|
51
|
+
.map{|id,rows| [id, rows.map{|role| role[:role]}] }.to_h
|
52
|
+
|
53
|
+
{
|
54
|
+
pages: pages,
|
55
|
+
accounts: accounts.map{|account|
|
56
|
+
account.tap{
|
57
|
+
id = account[:id]
|
58
|
+
account[:reset] = !!emails[id]
|
59
|
+
account[:roles] = roles[id] || []
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
# :nocov:
|
71
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require "getto/repository/sequel"
|
2
|
+
|
3
|
+
module Monban
|
4
|
+
# :nocov:
|
5
|
+
module Repository
|
6
|
+
module Auth
|
7
|
+
|
8
|
+
class Sequel < Getto::Repository::Sequel
|
9
|
+
|
10
|
+
def account_id_by_public_id(public_id:, now:)
|
11
|
+
db[:account_public_ids]
|
12
|
+
.where(public_id: public_id)
|
13
|
+
.where(::Sequel[:account_public_ids][:expired_at] > now)
|
14
|
+
.select(:account_id)
|
15
|
+
.map{|hash| hash[:account_id] }.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def account_id_by_email(email:)
|
19
|
+
db[:account_reset_password_emails]
|
20
|
+
.where(email: email)
|
21
|
+
.select(:account_id)
|
22
|
+
.map{|hash| hash[:account_id] }.first
|
23
|
+
end
|
24
|
+
|
25
|
+
def account_id_by_login_id(login_id:)
|
26
|
+
db[:account_login_ids]
|
27
|
+
.where(login_id: login_id)
|
28
|
+
.select(:account_id)
|
29
|
+
.map{|hash| hash[:account_id] }.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def login_id(account_id:)
|
33
|
+
db[:account_login_ids]
|
34
|
+
.where(account_id: account_id)
|
35
|
+
.select(:login_id)
|
36
|
+
.map{|hash| hash[:login_id]}.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def roles(account_id:)
|
40
|
+
db[:account_roles]
|
41
|
+
.where(account_id: account_id)
|
42
|
+
.select(:role)
|
43
|
+
.map{|r| r[:role]}
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def public_id_renew_enabled?(public_id:, original_created_at:)
|
48
|
+
not db[:account_public_ids]
|
49
|
+
.where(public_id: public_id)
|
50
|
+
.where(::Sequel[:account_public_ids][:original_created_at] > original_created_at)
|
51
|
+
.empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def public_id_original_created_at(public_id:)
|
55
|
+
db[:account_public_ids]
|
56
|
+
.where(public_id: public_id)
|
57
|
+
.select(:original_created_at)
|
58
|
+
.map{|hash| hash[:original_created_at]}.first
|
59
|
+
end
|
60
|
+
|
61
|
+
def preserve_public_id_original_created_at(public_id:, original_created_at:)
|
62
|
+
db[:account_public_ids]
|
63
|
+
.where(public_id: public_id)
|
64
|
+
.update(
|
65
|
+
original_created_at: original_created_at,
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def public_id_exists?(public_id:)
|
70
|
+
not db[:account_public_ids]
|
71
|
+
.where(public_id: public_id)
|
72
|
+
.empty?
|
73
|
+
end
|
74
|
+
|
75
|
+
def insert_public_id(account_id:, public_id:, created_at:, expired_at:)
|
76
|
+
db[:account_public_ids].insert(
|
77
|
+
account_id: account_id,
|
78
|
+
public_id: public_id,
|
79
|
+
created_at: created_at,
|
80
|
+
expired_at: expired_at,
|
81
|
+
original_created_at: created_at,
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def authy_id(account_id:)
|
87
|
+
db[:account_authy_ids]
|
88
|
+
.where(account_id: account_id)
|
89
|
+
.select(:authy_id)
|
90
|
+
.map{|hash| hash[:authy_id]}.first
|
91
|
+
end
|
92
|
+
|
93
|
+
def update_authy_id(account_id:, authy_id:, now:)
|
94
|
+
if db[:account_authy_ids].where(account_id: account_id).empty?
|
95
|
+
db[:account_authy_ids].insert(
|
96
|
+
account_id: account_id,
|
97
|
+
authy_id: authy_id,
|
98
|
+
created_at: now,
|
99
|
+
)
|
100
|
+
else
|
101
|
+
db[:account_authy_ids].where(account_id: account_id).update(
|
102
|
+
authy_id: authy_id,
|
103
|
+
created_at: now,
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def delete_reset_password_token(account_id:)
|
110
|
+
db[:account_reset_password_tokens]
|
111
|
+
.where(account_id: account_id)
|
112
|
+
.delete
|
113
|
+
end
|
114
|
+
|
115
|
+
def reset_password_token_exists?(reset_token:)
|
116
|
+
not db[:account_reset_password_tokens]
|
117
|
+
.where(reset_token: reset_token)
|
118
|
+
.empty?
|
119
|
+
end
|
120
|
+
|
121
|
+
def insert_reset_password_token(account_id:, reset_token:, created_at:, expired_at:)
|
122
|
+
db[:account_reset_password_tokens].insert(
|
123
|
+
account_id: account_id,
|
124
|
+
reset_token: reset_token,
|
125
|
+
created_at: created_at,
|
126
|
+
expired_at: expired_at,
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def wipe_old_reset_password_token(now:)
|
131
|
+
db[:account_reset_password_tokens]
|
132
|
+
.where(::Sequel[:account_reset_password_tokens][:expired_at] <= now)
|
133
|
+
.delete
|
134
|
+
end
|
135
|
+
|
136
|
+
def valid_reset_password_token?(account_id:, reset_token:, now:)
|
137
|
+
not db[:account_reset_password_tokens]
|
138
|
+
.where(
|
139
|
+
account_id: account_id,
|
140
|
+
reset_token: reset_token,
|
141
|
+
)
|
142
|
+
.where(::Sequel[:account_reset_password_tokens][:expired_at] > now)
|
143
|
+
.empty?
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def password_salt(account_id:)
|
148
|
+
db[:account_password_hashes]
|
149
|
+
.select(::Sequel.function(:substring, ::Sequel[:password_hash], 1, 30).as(:salt))
|
150
|
+
.where(account_id: account_id)
|
151
|
+
.map{|hash| hash[:salt]}.first
|
152
|
+
end
|
153
|
+
|
154
|
+
def password_hash_match?(account_id:, password_hash:)
|
155
|
+
not db[:account_password_hashes]
|
156
|
+
.where(account_id: account_id, password_hash: password_hash)
|
157
|
+
.empty?
|
158
|
+
end
|
159
|
+
|
160
|
+
def update_password_hash(account_id:, password_hash:, now:)
|
161
|
+
if db[:account_password_hashes].where(account_id: account_id).empty?
|
162
|
+
db[:account_password_hashes].insert(
|
163
|
+
account_id: account_id,
|
164
|
+
password_hash: password_hash,
|
165
|
+
created_at: now,
|
166
|
+
updated_at: now,
|
167
|
+
)
|
168
|
+
else
|
169
|
+
db[:account_password_hashes].where(account_id: account_id).update(
|
170
|
+
password_hash: password_hash,
|
171
|
+
updated_at: now,
|
172
|
+
)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
# :nocov:
|
181
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "monban/repository/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = ">= 2.5.1"
|
7
|
+
|
8
|
+
spec.name = "monban-repository"
|
9
|
+
spec.version = Monban::Repository::VERSION
|
10
|
+
spec.authors = ["shun@getto.systems"]
|
11
|
+
spec.email = ["shun@getto.systems"]
|
12
|
+
|
13
|
+
spec.summary = %q{paging helper}
|
14
|
+
spec.description = %q{Repository helpers: Page}
|
15
|
+
spec.homepage = "https://github.com/getto-systems/rubygems-monban-repository"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
|
28
|
+
spec.extra_rdoc_files = ['README.md', 'LICENSE']
|
29
|
+
spec.rdoc_options = %w[--title Monban::Repository --main README.md]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "getto-initialize_with", "~> 1.0"
|
32
|
+
spec.add_runtime_dependency "getto-repository-sequel", "~> 1.0"
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
37
|
+
spec.add_development_dependency "simplecov", "~> 0.16"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monban-repository
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shun@getto.systems
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: getto-initialize_with
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: getto-repository-sequel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.16'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.16'
|
97
|
+
description: 'Repository helpers: Page'
|
98
|
+
email:
|
99
|
+
- shun@getto.systems
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- README.md
|
104
|
+
- LICENSE
|
105
|
+
files:
|
106
|
+
- ".envrc"
|
107
|
+
- ".git_release_request.rc.sh"
|
108
|
+
- ".gitignore"
|
109
|
+
- ".gitlab-ci.yml"
|
110
|
+
- ".travis.yml"
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- LICENSE
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- db/migrations/001_create_account_tables.rb
|
117
|
+
- lib/monban/repository/account.rb
|
118
|
+
- lib/monban/repository/account/search.rb
|
119
|
+
- lib/monban/repository/auth.rb
|
120
|
+
- lib/monban/repository/version.rb
|
121
|
+
- monban-repository.gemspec
|
122
|
+
homepage: https://github.com/getto-systems/rubygems-monban-repository
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options:
|
128
|
+
- "--title"
|
129
|
+
- Monban::Repository
|
130
|
+
- "--main"
|
131
|
+
- README.md
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.5.1
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.7.7
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: paging helper
|
150
|
+
test_files: []
|