vxod 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +23 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +21 -0
- data/example/app.rb +44 -0
- data/example/config.ru +3 -0
- data/example/config_app.rb +27 -0
- data/example/mongoid.yml +85 -0
- data/lib/vxod.rb +15 -0
- data/lib/vxod/api.rb +56 -0
- data/lib/vxod/api_static.rb +11 -0
- data/lib/vxod/app.rb +68 -0
- data/lib/vxod/assets/css/bootstrap.css +5785 -0
- data/lib/vxod/assets/css/common.sass +54 -0
- data/lib/vxod/assets/img/.gitkeep +0 -0
- data/lib/vxod/assets/js/bootstrap.js +1951 -0
- data/lib/vxod/assets/js/jquery.js +9111 -0
- data/lib/vxod/assets/js/prefixfree.min.js +5 -0
- data/lib/vxod/back_path.rb +27 -0
- data/lib/vxod/config.rb +12 -0
- data/lib/vxod/db.rb +24 -0
- data/lib/vxod/db/mongoid.rb +47 -0
- data/lib/vxod/email.rb +7 -0
- data/lib/vxod/login_with_openid.rb +78 -0
- data/lib/vxod/middleware.rb +67 -0
- data/lib/vxod/omni_auth_provider.rb +40 -0
- data/lib/vxod/public/vxod/font-awesome/css/font-awesome.css +4 -0
- data/lib/vxod/public/vxod/font-awesome/fonts/FontAwesome.otf +0 -0
- data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.eot +0 -0
- data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.svg +414 -0
- data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.woff +0 -0
- data/lib/vxod/version.rb +3 -0
- data/lib/vxod/views/fill_user_data.slim +28 -0
- data/lib/vxod/views/login.slim +48 -0
- data/lib/vxod/views/parts/head.slim +10 -0
- data/lib/vxod/views/parts/nav.slim +3 -0
- data/spec/features/login_with_openid_spec.rb +27 -0
- data/spec/lib/api_spec.rb +45 -0
- data/spec/lib/app_spec.rb +43 -0
- data/spec/lib/back_path_spec.rb +21 -0
- data/spec/lib/config_spec.rb +11 -0
- data/spec/lib/db_spec.rb +27 -0
- data/spec/lib/login_with_openid_spec.rb +157 -0
- data/spec/lib/middleware_spec.rb +4 -0
- data/spec/lib/vxod_spec.rb +12 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/random.rb +16 -0
- data/vxod.gemspec +47 -0
- metadata +343 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 008aab422391d21d786d637e7722ec0131c8a775
|
4
|
+
data.tar.gz: 8da28065880c08f5d822a016019cc9a38463be31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edcbc89295904c86953c8290fc4d1378f81747deab0f98fcfa9f8ee9898452b5735e835efb30e9c37e423b73b84ddfec63c150fd234ade6b263c80a19941785f
|
7
|
+
data.tar.gz: 4abbf46e19d202846411063f92df7f8ce3be40e61dbf976125e053a51c58a65a7e425583d64d6cffdb1dfbebac2287508b0eece6fa62903e6828c6d871886945
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
.DS_Store
|
20
|
+
.sass-cache
|
21
|
+
|
22
|
+
config_env.rb
|
23
|
+
capybara-*.html
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
vxod
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sergey Makridenkov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Vxod
|
2
|
+
|
3
|
+
Social and password authorization solution
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/SergXIIIth/vxod.svg?branch=master)](https://travis-ci.org/SergXIIIth/vxod)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/SergXIIIth/vxod.png)](https://codeclimate.com/github/SergXIIIth/vxod)
|
7
|
+
[![Dependency Status](https://gemnasium.com/SergXIIIth/vxod.svg)](https://gemnasium.com/SergXIIIth/vxod)
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/vxod.png)](http://badge.fury.io/rb/vxod)
|
9
|
+
|
10
|
+
# Features
|
11
|
+
|
12
|
+
- + social registration/login
|
13
|
+
- password base registration/login,
|
14
|
+
- checkbox auto-generated password send to email
|
15
|
+
- optional require email in social registration
|
16
|
+
- reset password
|
17
|
+
|
18
|
+
Future
|
19
|
+
|
20
|
+
- profile with password reset, link other social servises to user
|
21
|
+
- adminka for user management
|
22
|
+
- support Sinatra, Mongoid, Rails, ActiveRecord, any Rack app, any DB
|
23
|
+
|
24
|
+
|
25
|
+
# Installation
|
26
|
+
|
27
|
+
- gem 'vxod'
|
28
|
+
- configure email
|
29
|
+
- provide key for open auth
|
30
|
+
- provide layout to inject views
|
31
|
+
|
32
|
+
## Config OmniAuth
|
33
|
+
|
34
|
+
Gems
|
35
|
+
|
36
|
+
gem 'omniauth'
|
37
|
+
gem 'omniauth-twitter'
|
38
|
+
gem 'omniauth-vkontakte'
|
39
|
+
gem 'omniauth-facebook'
|
40
|
+
gem 'omniauth-google_oauth2'
|
41
|
+
gem 'omniauth-github'
|
42
|
+
|
43
|
+
App
|
44
|
+
|
45
|
+
enable :sessions
|
46
|
+
set :sessions, secret: ENV['secret_secret']
|
47
|
+
|
48
|
+
use OmniAuth::Builder do
|
49
|
+
provider :twitter, ENV['omniauth.twitter'], ENV['omniauth.twitter_x']
|
50
|
+
provider :vkontakte, ENV['omniauth.vkontakte'], ENV['omniauth.vkontakte_x']
|
51
|
+
provider :facebook, ENV['omniauth.facebook'], ENV['omniauth.facebook_x']
|
52
|
+
provider :google_oauth2, ENV['omniauth.google'], ENV['omniauth.google_x']
|
53
|
+
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
|
54
|
+
end
|
55
|
+
|
56
|
+
use Vxod::Middleware # put it after use OmniAuth
|
57
|
+
|
58
|
+
## Config Db
|
59
|
+
|
60
|
+
require 'vxod/db/mongoid'
|
61
|
+
|
62
|
+
Vxod::Db.identity = Vxod::Db::Mongoid::Identity
|
63
|
+
Vxod::Db.user = Vxod::Db::Mongoid::User
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# Usage
|
68
|
+
|
69
|
+
TODO: Write usage instructions here
|
70
|
+
|
71
|
+
# Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Run web server for example app'
|
4
|
+
task 'web' do
|
5
|
+
system "bundle exec rerun --pattern '{**/*.rb}' -c 'puma -p 3000 --dir example'"
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Console'
|
9
|
+
task 'console' do
|
10
|
+
system "bundle exec irb -r ./example/app.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Rub tests'
|
14
|
+
task 'test' do
|
15
|
+
system %Q(bundle exec rerun --pattern '{**/*.rb}' -cx rspec -t ~feature)
|
16
|
+
end
|
17
|
+
|
18
|
+
# for CI
|
19
|
+
require 'rspec/core/rake_task'
|
20
|
+
RSpec::Core::RakeTask.new(:spec)
|
21
|
+
task :default => :spec
|
data/example/app.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'vxod'
|
3
|
+
require 'slim'
|
4
|
+
require 'sass'
|
5
|
+
require 'config_env'
|
6
|
+
require 'mongoid'
|
7
|
+
require 'omniauth'
|
8
|
+
require 'omniauth-twitter'
|
9
|
+
require 'omniauth-vkontakte'
|
10
|
+
require 'omniauth-facebook'
|
11
|
+
require 'omniauth-google-oauth2'
|
12
|
+
require 'omniauth-github'
|
13
|
+
|
14
|
+
|
15
|
+
config_env = "#{__dir__}/config_env.rb"
|
16
|
+
require config_env if File.exists?(config_env)
|
17
|
+
|
18
|
+
require_relative 'config_app'
|
19
|
+
|
20
|
+
helpers do
|
21
|
+
def vxod
|
22
|
+
@vxod = Vxod.api(self)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
get '/' do
|
27
|
+
'Hello please try protected page at <a id="secret" href="/secret">/secret</a>'
|
28
|
+
end
|
29
|
+
|
30
|
+
get '/secret' do
|
31
|
+
vxod.required
|
32
|
+
slim :secret
|
33
|
+
end
|
34
|
+
|
35
|
+
template :secret do
|
36
|
+
%q(
|
37
|
+
|
38
|
+
p
|
39
|
+
| I am secret page for
|
40
|
+
strong = vxod.user.email
|
41
|
+
p: a id='logout' href='/logout' Logout
|
42
|
+
|
43
|
+
)
|
44
|
+
end
|
data/example/config.ru
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Mongoid
|
2
|
+
|
3
|
+
Mongoid.load!(__dir__ + '/mongoid.yml')
|
4
|
+
|
5
|
+
|
6
|
+
# OmniAuth
|
7
|
+
|
8
|
+
enable :sessions
|
9
|
+
set :sessions, secret: ENV['secret_secret']
|
10
|
+
|
11
|
+
use OmniAuth::Builder do
|
12
|
+
provider :twitter, ENV['omniauth.twitter'], ENV['omniauth.twitter_x']
|
13
|
+
provider :vkontakte, ENV['omniauth.vkontakte'], ENV['omniauth.vkontakte_x']
|
14
|
+
provider :facebook, ENV['omniauth.facebook'], ENV['omniauth.facebook_x']
|
15
|
+
provider :google_oauth2, ENV['omniauth.google'], ENV['omniauth.google_x']
|
16
|
+
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
|
17
|
+
end
|
18
|
+
|
19
|
+
use Vxod::Middleware
|
20
|
+
|
21
|
+
|
22
|
+
# Db
|
23
|
+
|
24
|
+
require 'vxod/db/mongoid'
|
25
|
+
|
26
|
+
Vxod::Db.identity = Vxod::Db::Mongoid::Identity
|
27
|
+
Vxod::Db.user = Vxod::Db::Mongoid::User
|
data/example/mongoid.yml
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
development:
|
2
|
+
# Configure available database sessions. (required)
|
3
|
+
sessions:
|
4
|
+
# Defines the default session. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: redsi_development
|
9
|
+
# Provides the hosts the default session can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- 127.0.0.1:27017
|
13
|
+
options:
|
14
|
+
# Change whether the session persists in safe mode by default.
|
15
|
+
# (default: false)
|
16
|
+
# safe: false
|
17
|
+
|
18
|
+
# Change the default consistency model to :eventual or :strong.
|
19
|
+
# :eventual will send reads to secondaries, :strong sends everything
|
20
|
+
# to master. (default: :eventual)
|
21
|
+
# consistency: :eventual
|
22
|
+
|
23
|
+
# How many times Moped should attempt to retry an operation after
|
24
|
+
# failure. (default: 30)
|
25
|
+
# max_retries: 30
|
26
|
+
|
27
|
+
# The time in seconds that Moped should wait before retrying an
|
28
|
+
# operation on failure. (default: 1)
|
29
|
+
# retry_interval: 1
|
30
|
+
# Configure Mongoid specific options. (optional)
|
31
|
+
options:
|
32
|
+
# Configuration for whether or not to allow access to fields that do
|
33
|
+
# not have a field definition on the model. (default: true)
|
34
|
+
# allow_dynamic_fields: true
|
35
|
+
|
36
|
+
# Enable the identity map, needed for eager loading. (default: false)
|
37
|
+
# identity_map_enabled: false
|
38
|
+
|
39
|
+
# Includes the root model name in json serialization. (default: false)
|
40
|
+
# include_root_in_json: false
|
41
|
+
|
42
|
+
# Include the _type field in serializaion. (default: false)
|
43
|
+
# include_type_for_serialization: false
|
44
|
+
|
45
|
+
# Preload all models in development, needed when models use
|
46
|
+
# inheritance. (default: false)
|
47
|
+
# preload_models: false
|
48
|
+
|
49
|
+
# Protect id and type from mass assignment. (default: true)
|
50
|
+
# protect_sensitive_fields: true
|
51
|
+
|
52
|
+
# Raise an error when performing a #find and the document is not found.
|
53
|
+
# (default: true)
|
54
|
+
# raise_not_found_error: true
|
55
|
+
|
56
|
+
# Raise an error when defining a scope with the same name as an
|
57
|
+
# existing method. (default: false)
|
58
|
+
# scope_overwrite_exception: false
|
59
|
+
|
60
|
+
# Skip the database version check, used when connecting to a db without
|
61
|
+
# admin access. (default: false)
|
62
|
+
# skip_version_check: false
|
63
|
+
|
64
|
+
# User Active Support's time zone in conversions. (default: true)
|
65
|
+
# use_activesupport_time_zone: true
|
66
|
+
|
67
|
+
# Ensure all times are UTC in the app side. (default: false)
|
68
|
+
# use_utc: false
|
69
|
+
test:
|
70
|
+
sessions:
|
71
|
+
default:
|
72
|
+
database: redsi_test
|
73
|
+
hosts:
|
74
|
+
- 127.0.0.1:27017
|
75
|
+
options:
|
76
|
+
consistency: :strong
|
77
|
+
# In the test environment we lower the retries and retry interval to
|
78
|
+
# low amounts for fast failures.
|
79
|
+
max_retries: 1
|
80
|
+
retry_interval: 0
|
81
|
+
production:
|
82
|
+
sessions:
|
83
|
+
default:
|
84
|
+
uri: <%= ENV['MONGO_URI'] %>
|
85
|
+
options:
|
data/lib/vxod.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'vxod/version'
|
3
|
+
|
4
|
+
module Vxod
|
5
|
+
autoload :Db, 'vxod/db'
|
6
|
+
autoload :Email, 'vxod/email'
|
7
|
+
autoload :BackPath, 'vxod/back_path'
|
8
|
+
autoload :Config, 'vxod/config'
|
9
|
+
autoload :App, 'vxod/app'
|
10
|
+
autoload :Api, 'vxod/api'
|
11
|
+
autoload :LoginWithOpenid, 'vxod/login_with_openid'
|
12
|
+
require 'vxod/api_static'
|
13
|
+
autoload :OmniAuthProvider, 'vxod/omni_auth_provider'
|
14
|
+
autoload :Middleware, 'vxod/middleware'
|
15
|
+
end
|
data/lib/vxod/api.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Vxod
|
2
|
+
class Api
|
3
|
+
def initialize(rack_app)
|
4
|
+
@rack_app = rack_app
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :rack_app
|
8
|
+
|
9
|
+
# Authorize user right to make action on object
|
10
|
+
#
|
11
|
+
# Check that user login and have right to make 'action' on 'object'
|
12
|
+
# If not it redirects to login page
|
13
|
+
def required(action = nil, object = nil)
|
14
|
+
if user.nil?
|
15
|
+
BackPath.new(rack_app).save(app.request_path)
|
16
|
+
app.redirect(Vxod.config.login_path)
|
17
|
+
else
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def login_with_openid
|
23
|
+
openid.login
|
24
|
+
end
|
25
|
+
|
26
|
+
def logout
|
27
|
+
app.detele_auth_key
|
28
|
+
app.redirect(Vxod.config.after_login_default_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Save missing user data after openid registration
|
32
|
+
def openid_save_user_data
|
33
|
+
openid.save_user_data
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return user for fill user data page
|
37
|
+
def user_to_fill_data
|
38
|
+
@user_to_fill_data ||= Db.user.find_by_auth_key(app.auth_key_for_fill_user_data)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Current user
|
42
|
+
def user
|
43
|
+
@user ||= Db.user.find_by_auth_key(app.auth_key)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def openid
|
49
|
+
@openid ||= LoginWithOpenid.new(app)
|
50
|
+
end
|
51
|
+
|
52
|
+
def app
|
53
|
+
@app ||= Vxod::App.new(rack_app)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|