vxod 0.0.1 → 0.0.2

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +23 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +16 -0
  6. data/Gemfile +14 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +77 -0
  9. data/Rakefile +21 -0
  10. data/example/app.rb +44 -0
  11. data/example/config.ru +3 -0
  12. data/example/config_app.rb +27 -0
  13. data/example/mongoid.yml +85 -0
  14. data/lib/vxod.rb +15 -0
  15. data/lib/vxod/api.rb +56 -0
  16. data/lib/vxod/api_static.rb +11 -0
  17. data/lib/vxod/app.rb +68 -0
  18. data/lib/vxod/assets/css/bootstrap.css +5785 -0
  19. data/lib/vxod/assets/css/common.sass +54 -0
  20. data/lib/vxod/assets/img/.gitkeep +0 -0
  21. data/lib/vxod/assets/js/bootstrap.js +1951 -0
  22. data/lib/vxod/assets/js/jquery.js +9111 -0
  23. data/lib/vxod/assets/js/prefixfree.min.js +5 -0
  24. data/lib/vxod/back_path.rb +27 -0
  25. data/lib/vxod/config.rb +12 -0
  26. data/lib/vxod/db.rb +24 -0
  27. data/lib/vxod/db/mongoid.rb +47 -0
  28. data/lib/vxod/email.rb +7 -0
  29. data/lib/vxod/login_with_openid.rb +78 -0
  30. data/lib/vxod/middleware.rb +67 -0
  31. data/lib/vxod/omni_auth_provider.rb +40 -0
  32. data/lib/vxod/public/vxod/font-awesome/css/font-awesome.css +4 -0
  33. data/lib/vxod/public/vxod/font-awesome/fonts/FontAwesome.otf +0 -0
  34. data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  35. data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.svg +414 -0
  36. data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  37. data/lib/vxod/public/vxod/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  38. data/lib/vxod/version.rb +3 -0
  39. data/lib/vxod/views/fill_user_data.slim +28 -0
  40. data/lib/vxod/views/login.slim +48 -0
  41. data/lib/vxod/views/parts/head.slim +10 -0
  42. data/lib/vxod/views/parts/nav.slim +3 -0
  43. data/spec/features/login_with_openid_spec.rb +27 -0
  44. data/spec/lib/api_spec.rb +45 -0
  45. data/spec/lib/app_spec.rb +43 -0
  46. data/spec/lib/back_path_spec.rb +21 -0
  47. data/spec/lib/config_spec.rb +11 -0
  48. data/spec/lib/db_spec.rb +27 -0
  49. data/spec/lib/login_with_openid_spec.rb +157 -0
  50. data/spec/lib/middleware_spec.rb +4 -0
  51. data/spec/lib/vxod_spec.rb +12 -0
  52. data/spec/spec_helper.rb +45 -0
  53. data/spec/support/random.rb +16 -0
  54. data/vxod.gemspec +47 -0
  55. metadata +343 -13
@@ -0,0 +1,3 @@
1
+ module Vxod
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,28 @@
1
+ doctype html
2
+ html
3
+ == slim :'parts/head'
4
+
5
+ coffee:
6
+ $ ->
7
+ $('.vxod-login-with [data-tooltip]').tooltip(placement: 'bottom', delay: { show: 1000, hide: 100 })
8
+
9
+ body
10
+ .login-container
11
+ .well
12
+ form role='form' action=Vxod.config.fill_user_data_path method='POST'
13
+ .alert.alert-danger Please provide your valid EMAIL address
14
+
15
+ .form-group
16
+ label for='email' Email *
17
+ input.form-control type='email' id='email' name='email' placeholder='Enter your email' value=user.email
18
+
19
+ .form-group
20
+ label for='firstname' First name
21
+ input.form-control type='firstname' id='firstname' name='firstname' placeholder='Enter your first name' value=user.firstname
22
+
23
+ .form-group
24
+ label for='lastname' Last name
25
+ input.form-control type='lastname' id='lastname' name='lastname' placeholder='Enter your last name' value=user.lastname
26
+
27
+ .text-right
28
+ button.btn.btn-primary.btn-lg type='submit' Continue >
@@ -0,0 +1,48 @@
1
+ doctype html
2
+ html
3
+ == slim :'parts/head'
4
+
5
+ coffee:
6
+ $ ->
7
+ $('.vxod-login-with [data-tooltip]').tooltip(placement: 'bottom', delay: { show: 1000, hide: 100 })
8
+
9
+ body
10
+ .login-container
11
+ .well
12
+ == slim :'parts/nav'
13
+
14
+ form role='form' action=Vxod.config.login_path method='POST'
15
+ .form-group
16
+ label for='email' Email
17
+ input.form-control type='email' id='email' placeholder='Enter email'
18
+
19
+ .form-group
20
+ label for='password' Password
21
+ input.form-control type='password' id='password' placeholder='Enter password'
22
+
23
+ .row
24
+ .col-xs-8.vxod-login-option
25
+ .checkbox
26
+ label
27
+ input type='checkbox' name='remember_me' checked='1' Remember me
28
+
29
+ a href='#' Reset password
30
+
31
+ .col-xs-4.text-right
32
+ button.btn.btn-primary.btn-lg type='submit' Login
33
+
34
+ - if Vxod::OmniAuthProvider.any?
35
+ .vxod-login-with
36
+ hr
37
+
38
+ .row
39
+ .pull-left
40
+ p Login with
41
+ .pull-right
42
+ ul
43
+ - Vxod::OmniAuthProvider.all.each do |provider|
44
+ - if provider.show?
45
+ li data-tooltip='1' title=provider.title
46
+ a href=provider.href
47
+ i.fa class=provider.icon
48
+ .clearfix
@@ -0,0 +1,10 @@
1
+ head
2
+ meta charset='UTF-8'
3
+ title Login
4
+
5
+ meta name='viewport' content='width=device-width, initial-scale=1.0'
6
+
7
+ == js :app
8
+ == css :app
9
+
10
+ link href='/vxod/font-awesome/css/font-awesome.css' rel='stylesheet'
@@ -0,0 +1,3 @@
1
+ ul.nav.nav-tabs.vxod-login-tab
2
+ li.active: a href=Vxod.config.login_path Login
3
+ li: a href='#' Registration
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Login with openid', :type => :feature, feature: true, js: true do
4
+ let(:email){ "sergey#{rnd}@makridenkov.com" }
5
+
6
+ it 'allow access to secret page' do
7
+ # visit home page
8
+ # click secret page
9
+ # click login with VK
10
+ # fill email and click continue
11
+ # I should be on secret page
12
+ # I click on logout
13
+ # I should be on ?home page?
14
+
15
+ visit '/'
16
+ click_on 'secret'
17
+ find('.fa-vk').click
18
+ fill_in('email', with: email)
19
+ find('.btn-primary').click
20
+
21
+ expect(page).to have_content("I am secret page for #{email}")
22
+
23
+ click_on('logout')
24
+
25
+ expect(current_path).to eq '/'
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ module Vxod
4
+ describe Api do
5
+ let(:rack_app){ double('rack_app') }
6
+ let(:vxod){ Api.new(rack_app) }
7
+
8
+
9
+ describe '#required' do
10
+ let(:back_path){ "/secret_page#{rnd}" }
11
+ let(:session){ {} }
12
+
13
+ before do
14
+ allow(rack_app).to receive(:request){ double(path: back_path) }
15
+ allow(vxod).to receive(:user){ nil }
16
+ allow(rack_app).to receive(:redirect)
17
+ allow(rack_app).to receive(:session){ session }
18
+ end
19
+
20
+ context 'when not authorized' do
21
+ it 'redirects to login path' do
22
+ expect(rack_app).to receive(:redirect).with(Vxod.config.login_path)
23
+ vxod.required
24
+ end
25
+
26
+ it 'save back path in session' do
27
+ vxod.required
28
+ expect(session['vxod.back_path']).to eq back_path
29
+ end
30
+ end
31
+
32
+ context 'when authorized' do
33
+ let(:user){ double('user') }
34
+
35
+ before do
36
+ allow(vxod).to receive(:user){ user }
37
+ end
38
+
39
+ it 'true' do
40
+ expect(vxod.required).to be_true
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module Vxod
4
+ describe App do
5
+ let(:response){ double('response') }
6
+ let(:request){ double('request') }
7
+ let(:rack_app){ double('rack_app', response: response, request: request) }
8
+ let(:app){ App.new(rack_app) }
9
+
10
+ describe '#authentify' do
11
+ it 'set cookie with for whole domain with 10 years expires' do
12
+ auth_key = rnd('auth_key')
13
+ host = rnd('host')
14
+ allow(request).to receive(:host){ host }
15
+
16
+ expect(response).to receive(:set_cookie).with('vxod.auth',
17
+ value: auth_key,
18
+ path: '/',
19
+ expires: Time.new(DateTime.now.year + 10, 1, 1),
20
+ httponly: true
21
+ )
22
+
23
+ app.authentify(auth_key)
24
+ end
25
+ end
26
+
27
+ describe '#authentify_for_fill_user_data' do
28
+ it 'set cookie for fill user data only' do
29
+ auth_key = rnd('auth_key')
30
+ host = rnd('host')
31
+ allow(request).to receive(:host){ host }
32
+
33
+ expect(response).to receive(:set_cookie).with('vxod.auth_fill_user_data',
34
+ value: auth_key,
35
+ path: Vxod.config.fill_user_data_path,
36
+ httponly: true
37
+ )
38
+
39
+ app.authentify_for_fill_user_data(auth_key)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Vxod
4
+ describe BackPath do
5
+ let(:session){ {} }
6
+ let(:back_url){ rnd('back_url') }
7
+ let(:rack_app){ double('rack_app', session: session) }
8
+ let(:back_path){ BackPath.new(rack_app) }
9
+
10
+ describe '#get' do
11
+ it 'take back path from session' do
12
+ session['vxod.back_path'] = back_url
13
+ expect(back_path.get).to eq back_url
14
+ end
15
+
16
+ it 'return default back path when no present in session' do
17
+ expect(back_path.get).to eq Vxod.config.after_login_default_path
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vxod::Config do
4
+ let(:config){ Vxod::Config.new }
5
+
6
+ describe '#login_path' do
7
+ it 'has default value' do
8
+ expect(config.login_path).to eq '/login'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Vxod
4
+ describe Db do
5
+ let(:identity){ double('identity') }
6
+ let(:user){ double('user') }
7
+
8
+ # describe '.identity_create' do
9
+ # it 'create identity'
10
+ # it 'create user'
11
+ # end
12
+
13
+ describe '.identity' do
14
+ it 'accessable' do
15
+ Db.identity = identity
16
+ expect(Db.identity).to eq identity
17
+ end
18
+ end
19
+
20
+ describe '.user' do
21
+ it 'accessable' do
22
+ Db.user = user
23
+ expect(Db.user).to eq user
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ module Vxod
4
+ describe LoginWithOpenid do
5
+ let(:app){ double('app') }
6
+ let(:identity){ double('identity') }
7
+ let(:user){ double('user') }
8
+ let(:identity_class){ double('identity_class') }
9
+ let(:provider){ rnd('provider') }
10
+ let(:openid){ rnd('openid') }
11
+ let(:auth_key){ rnd('auth_key') }
12
+ let(:login_with_openid){ LoginWithOpenid.new(app) }
13
+
14
+ before do
15
+ allow(user).to receive(:auth_key){ auth_key }
16
+ end
17
+
18
+ describe '#login' do
19
+ before do
20
+ allow(Db).to receive(:identity){ identity_class }
21
+ allow(app).to receive(:omniauth_hash){{ uid: openid, provider: provider }}
22
+ allow(identity).to receive(:user){ user }
23
+ end
24
+
25
+ context 'when identity exists and user has valid email' do
26
+ before do
27
+ allow(app).to receive(:authentify)
28
+ allow(app).to receive(:redirect_to_after_login)
29
+
30
+ allow(user).to receive(:email){ 'sergey@makridenkov.com' }
31
+ allow(identity_class).to receive(:find_by_openid).with(provider, openid){ identity }
32
+ end
33
+
34
+ it 'authentify' do
35
+ expect(app).to receive(:authentify).with(auth_key)
36
+ login_with_openid.login
37
+ end
38
+
39
+ it 'redirect back' do
40
+ expect(app).to receive(:redirect_to_after_login)
41
+ login_with_openid.login
42
+ end
43
+ end
44
+
45
+ context 'when identity not found' do
46
+ let(:email){ rnd('email') }
47
+ let(:firstname){ rnd('firstname') }
48
+ let(:lastname){ rnd('lastname') }
49
+
50
+ before do
51
+ allow(user).to receive(:email){ 'sergey@makridenkov.com' }
52
+ allow(identity_class).to receive(:find_by_openid).with(provider, openid){ nil }
53
+
54
+ allow(Db).to receive(:identity_create){ identity }
55
+
56
+ omniauth_info = { email: email, first_name: firstname, last_name: lastname }
57
+ allow(app).to receive(:omniauth_hash){{ uid: openid, provider: provider, info: omniauth_info }}
58
+ allow(app).to receive(:authentify)
59
+ allow(app).to receive(:redirect_to_after_login)
60
+ end
61
+
62
+ it 'create identity' do
63
+ expect(Db).to receive(:identity_create).with(provider, openid, email, firstname, lastname){ identity }
64
+ login_with_openid.login
65
+ end
66
+
67
+ it 'authentify' do
68
+ expect(app).to receive(:authentify).with(auth_key)
69
+ login_with_openid.login
70
+ end
71
+
72
+ it 'redirect user back' do
73
+ expect(app).to receive(:redirect_to_after_login)
74
+ login_with_openid.login
75
+ end
76
+ end
77
+
78
+ context 'when user have not valid email' do
79
+ before do
80
+ allow(user).to receive(:email){ 'invalid_email' }
81
+ allow(identity_class).to receive(:find_by_openid).with(provider, openid){ identity }
82
+
83
+ allow(app).to receive(:authentify_for_fill_user_data)
84
+ allow(app).to receive(:redirect)
85
+ end
86
+
87
+ it 'authentify for fill user data' do
88
+ expect(app).to receive(:authentify_for_fill_user_data).with(auth_key)
89
+ login_with_openid.login
90
+ end
91
+
92
+ it 'redirect user to fill email page' do
93
+ expect(app).to receive(:redirect).with(Vxod.config.fill_user_data_path)
94
+ login_with_openid.login
95
+ end
96
+ end
97
+ end
98
+
99
+ describe 'save_user_data' do
100
+ let(:firstname){ rnd('firstname') }
101
+ let(:lastname){ rnd('lastname') }
102
+ let(:params){{ 'firstname' => firstname, 'lastname' => lastname }}
103
+
104
+ before do
105
+ allow(app).to receive(:params){ params }
106
+ end
107
+
108
+ context 'when email invalid' do
109
+ it 'false' do
110
+ params['email'] = 'invalid_email'
111
+ expect(login_with_openid.save_user_data).to be_false
112
+ end
113
+ end
114
+
115
+ context 'when email valid' do
116
+ let(:email){ "sergey#{rnd}@makridenkov.com" }
117
+
118
+ before do
119
+ params['email'] = email
120
+
121
+ allow(app).to receive(:authentify)
122
+ allow(app).to receive(:redirect_to_after_login)
123
+ allow(app).to receive(:auth_key_for_fill_user_data){ auth_key }
124
+
125
+ user_class = double('user_class')
126
+ allow(user_class).to receive(:find_by_auth_key).with(auth_key){ user }
127
+
128
+ allow(Db).to receive(:user){ user_class }
129
+
130
+ allow(user).to receive(:email=)
131
+ allow(user).to receive(:firstname=)
132
+ allow(user).to receive(:lastname=)
133
+ allow(user).to receive(:save!)
134
+ end
135
+
136
+ it 'save user date' do
137
+ expect(user).to receive(:email=).with(email)
138
+ expect(user).to receive(:firstname=).with(firstname)
139
+ expect(user).to receive(:lastname=).with(lastname)
140
+ expect(user).to receive(:save!)
141
+
142
+ login_with_openid.save_user_data
143
+ end
144
+
145
+ it 'authentify' do
146
+ expect(app).to receive(:authentify).with(auth_key)
147
+ login_with_openid.save_user_data
148
+ end
149
+
150
+ it 'redirect back' do
151
+ expect(app).to receive(:redirect_to_after_login)
152
+ login_with_openid.save_user_data
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vxod::Middleware do
4
+ end