devise-ios-rails 1.0.0

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 (108) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +114 -0
  3. data/Rakefile +3 -0
  4. data/app/controllers/devise_ios_rails/passwords_controller.rb +29 -0
  5. data/app/controllers/devise_ios_rails/registrations_controller.rb +19 -0
  6. data/app/serializers/errors_serializer.rb +16 -0
  7. data/app/services/devise_ios_rails/change_password_service.rb +26 -0
  8. data/lib/devise-ios-rails.rb +54 -0
  9. data/lib/devise-ios-rails/engine.rb +5 -0
  10. data/lib/devise-ios-rails/rails/routes.rb +19 -0
  11. data/lib/devise-ios-rails/version.rb +3 -0
  12. data/lib/tasks/devise-ios-rails_tasks.rake +4 -0
  13. data/spec/devise-ios-rails_test.rb +7 -0
  14. data/spec/dummy/Gemfile +75 -0
  15. data/spec/dummy/Gemfile.lock +537 -0
  16. data/spec/dummy/README.md +225 -0
  17. data/spec/dummy/Rakefile +6 -0
  18. data/spec/dummy/app/assets/javascripts/active_admin.js.coffee +1 -0
  19. data/spec/dummy/app/assets/javascripts/application.js.coffee +0 -0
  20. data/spec/dummy/app/assets/javascripts/secret_spaces.coffee +3 -0
  21. data/spec/dummy/app/assets/stylesheets/active_admin.css.scss +17 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css.scss +0 -0
  23. data/spec/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -0
  24. data/spec/dummy/app/assets/stylesheets/secret_spaces.css.scss +3 -0
  25. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  26. data/spec/dummy/app/controllers/secret_spaces_controller.rb +49 -0
  27. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  28. data/spec/dummy/app/helpers/secret_spaces_helper.rb +2 -0
  29. data/spec/dummy/app/models/secret_space.rb +3 -0
  30. data/spec/dummy/app/models/user.rb +5 -0
  31. data/spec/dummy/app/serializers/secret_space_serializer.rb +3 -0
  32. data/spec/dummy/app/serializers/user_serializer.rb +8 -0
  33. data/spec/dummy/app/serializers/v1/base_serializer.rb +5 -0
  34. data/spec/dummy/app/serializers/v1/user_serializer.rb +4 -0
  35. data/spec/dummy/app/views/secret_spaces/_form.html.haml +13 -0
  36. data/spec/dummy/app/views/secret_spaces/edit.html.haml +7 -0
  37. data/spec/dummy/app/views/secret_spaces/index.html.haml +19 -0
  38. data/spec/dummy/app/views/secret_spaces/new.html.haml +5 -0
  39. data/spec/dummy/app/views/secret_spaces/show.html.haml +9 -0
  40. data/spec/dummy/bin/bundle +3 -0
  41. data/spec/dummy/bin/bundler +16 -0
  42. data/spec/dummy/bin/rails +8 -0
  43. data/spec/dummy/bin/rake +8 -0
  44. data/spec/dummy/bin/rspec +20 -0
  45. data/spec/dummy/bin/spring +18 -0
  46. data/spec/dummy/config.ru +12 -0
  47. data/spec/dummy/config/application.rb +23 -0
  48. data/spec/dummy/config/boot.rb +8 -0
  49. data/spec/dummy/config/database.yml +20 -0
  50. data/spec/dummy/config/deploy.rb +48 -0
  51. data/spec/dummy/config/deploy/production.rb +5 -0
  52. data/spec/dummy/config/deploy/staging.rb +4 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +19 -0
  55. data/spec/dummy/config/environments/heroku.rb +26 -0
  56. data/spec/dummy/config/environments/production.rb +26 -0
  57. data/spec/dummy/config/environments/staging.rb +27 -0
  58. data/spec/dummy/config/environments/test.rb +14 -0
  59. data/spec/dummy/config/initializers/active_model_serializer.rb +5 -0
  60. data/spec/dummy/config/initializers/assets.rb +8 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  63. data/spec/dummy/config/initializers/devise.rb +47 -0
  64. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  65. data/spec/dummy/config/initializers/inflections.rb +16 -0
  66. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  67. data/spec/dummy/config/initializers/session_store.rb +3 -0
  68. data/spec/dummy/config/initializers/simple_token_authentication.rb +25 -0
  69. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  70. data/spec/dummy/config/locales/devise.en.yml +60 -0
  71. data/spec/dummy/config/locales/en.yml +23 -0
  72. data/spec/dummy/config/routes.rb +10 -0
  73. data/spec/dummy/config/secrets.yml +17 -0
  74. data/spec/dummy/db/migrate/20141127081722_devise_create_users.rb +19 -0
  75. data/spec/dummy/db/migrate/20141127114158_add_authentication_token_to_users.rb +6 -0
  76. data/spec/dummy/db/migrate/20141201085308_add_unique_index_to_authentication_token_in_users.rb +6 -0
  77. data/spec/dummy/db/migrate/20141201111915_remove_username_from_users.rb +5 -0
  78. data/spec/dummy/db/migrate/20141208080520_create_secret_spaces.rb +9 -0
  79. data/spec/dummy/db/migrate/20141215153026_create_active_admin_comments.rb +19 -0
  80. data/spec/dummy/db/saaskit_development.sqlite3 +0 -0
  81. data/spec/dummy/db/saaskit_test.sqlite3 +0 -0
  82. data/spec/dummy/db/schema.rb +51 -0
  83. data/spec/dummy/db/seeds.rb +1 -0
  84. data/spec/dummy/log/development.log +610 -0
  85. data/spec/dummy/log/test.log +10113 -0
  86. data/spec/dummy/spec/api/v1/authorized_users_spec.rb +141 -0
  87. data/spec/dummy/spec/api/v1/login_spec.rb +82 -0
  88. data/spec/dummy/spec/api/v1/request_password_reset_spec.rb +39 -0
  89. data/spec/dummy/spec/api/v1/unauthorized_users_spec.rb +69 -0
  90. data/spec/dummy/spec/factories/authentications.rb +48 -0
  91. data/spec/dummy/spec/factories/secret_spaces.rb +6 -0
  92. data/spec/dummy/spec/factories/users.rb +13 -0
  93. data/spec/dummy/spec/factories_spec.rb +21 -0
  94. data/spec/dummy/spec/rails_helper.rb +16 -0
  95. data/spec/dummy/spec/serializers/v1/user_serializer_spec.rb +12 -0
  96. data/spec/dummy/spec/services/devise_ios_rails/change_password_service_spec.rb +47 -0
  97. data/spec/dummy/spec/spec_helper.rb +24 -0
  98. data/spec/dummy/spec/support/devise.rb +3 -0
  99. data/spec/dummy/spec/support/factory_girl.rb +7 -0
  100. data/spec/dummy/spec/support/helpers/json.rb +3 -0
  101. data/spec/dummy/spec/support/shared_contexts/authenticated.rb +3 -0
  102. data/spec/dummy/spec/support/shared_contexts/json_format.rb +5 -0
  103. data/spec/dummy/spec/support/shared_examples/authorized.rb +18 -0
  104. data/spec/dummy/spec/support/shared_examples/requests.rb +65 -0
  105. data/spec/rails_helper.rb +52 -0
  106. data/spec/serializers/errors_serializer_spec.rb +11 -0
  107. data/spec/spec_helper.rb +85 -0
  108. metadata +336 -0
@@ -0,0 +1,225 @@
1
+ Open Source Devise iOS Rails Backend
2
+ =================================
3
+
4
+ [![Circle CI](https://circleci.com/gh/netguru/devise-ios-rails-example.svg?style=svg)](https://circleci.com/gh/netguru/devise-ios-rails-example)
5
+ [![Code Climate](https://codeclimate.com/repos/54734062e30ba07474053280/badges/398895b59d76c0c16cd2/gpa.svg)](https://codeclimate.com/repos/54734062e30ba07474053280/feed)
6
+ [![Test Coverage](https://codeclimate.com/repos/54734062e30ba07474053280/badges/398895b59d76c0c16cd2/coverage.svg)](https://codeclimate.com/repos/54734062e30ba07474053280/feed)
7
+ [![Dependency](https://img.shields.io/gemnasium/netguru/devise-ios-rails-example.svg)](https://gemnasium.com/netguru/devise-ios-rails-example)
8
+
9
+ A rails backend for demonstrating how [Devise for iOS][ios_devise] works.
10
+
11
+ How to use
12
+ ==========
13
+
14
+ After a [successfull installation](#setup) you can use `localhost:3000/doc` to trigger request at some particular endpoints.
15
+
16
+ Demo App
17
+ ========
18
+
19
+ We've setup for you a demo of this server at [https://devise-ios-rails-example.herokuapp.com](https://devise-ios-rails-example.herokuapp.com). You can test how it works with either using dynamically generated swagger [docs][heroku_docs] or by using some old school curl commands:
20
+
21
+ register a user
22
+
23
+ ```bash
24
+ $ curl \
25
+ -H 'Accept: application/json' \
26
+ -H 'Content-Type: application/json' \
27
+ -X POST -d '{ "user": { "email": "user@example.com", "password": "1234" } }' \
28
+ https://devise-ios-rails-example.herokuapp.com/v1/users
29
+ ```
30
+
31
+ in return you will get a newly created user
32
+
33
+ ```json
34
+ {
35
+ "id": 2,
36
+ "email": "user@example.com",
37
+ "created_at": "2014-12-09T16:17:46.170Z",
38
+ "updated_at": "2014-12-09T16:17:46.170Z",
39
+ "authentication_token": "2-D9jBtnAPcP8fppzJAL"
40
+ }
41
+ ```
42
+
43
+ login a user
44
+
45
+ ```bash
46
+ $ curl \
47
+ -H 'Accept: application/json' \
48
+ -H 'Content-Type: application/json' \
49
+ -X POST -d '{ "user": { "email": "user@example.com", "password": "1234" } }' \
50
+ https://devise-ios-rails-example.herokuapp.com/v1/users/sign_in
51
+ ```
52
+
53
+ you will get again the same data:
54
+
55
+ ```json
56
+ {
57
+ "id": 2,
58
+ "email": "user@example.com",
59
+ "created_at": "2014-12-09T16:17:46.170Z",
60
+ "updated_at": "2014-12-09T16:17:46.170Z",
61
+ "authentication_token": "2-D9jBtnAPcP8fppzJAL"
62
+ }
63
+ ```
64
+
65
+ to make request to resources that are only available for registered users, you need to pass email and authentication token in your headers all the time:
66
+
67
+ ```bash
68
+ $ curl \
69
+ -H 'Accept: application/json' \
70
+ -H 'Content-Type: application/json' \
71
+ -H 'X-User-Email: user@example.com' \
72
+ -H 'X-User-Token: 2-D9jBtnAPcP8fppzJAL' \
73
+ -X GET https://devise-ios-rails-example.herokuapp.com/v1/secret_spaces/new
74
+ ```
75
+
76
+ response: `{ "id": null, "text": null, "created_at": null, "updated_at": null }`
77
+
78
+ in order to check how password reset works:
79
+
80
+ ```bash
81
+ $ curl \
82
+ -H 'Accept: application/json' \
83
+ -H 'Content-Type: application/json' \
84
+ -X POST -d '{ "user": { "email": "user@example.com" } }' \
85
+ https://devise-ios-rails-example.herokuapp.com/v1/users/password
86
+ ```
87
+
88
+ you receive response status 204 (no content). In the meantime, server sends instructions on how to reset the password, which you should follow. On heroku we use `letter_opener_web` gem therefore those emails are stored at [https://devise-ios-rails-example.herokuapp.com/letter_opener](https://devise-ios-rails-example.herokuapp.com/letter_opener).
89
+
90
+ Here is a complete list of paths:
91
+
92
+ - Useful Devise paths
93
+
94
+ ```
95
+ login - POST /v1/users/sign_in
96
+ login - GET /v1/users/sign_in
97
+ register - POST /v1/users
98
+ update user - PUT /v1/users
99
+ delete user - DELETE /v1/users
100
+ change user password - PUT /v1/users/password
101
+ password reset - POST /v1/users/password
102
+ ```
103
+
104
+ - Secret Spaces for demonstration purposes
105
+
106
+ ```
107
+ index - GET /v1/secret_spaces
108
+ show - GET /v1/secret_spaces/:id
109
+ new - GET /v1/secret_spaces/new
110
+ create - POST /v1/secret_spaces
111
+ edit - GET /v1/secret_spaces/:id/edit
112
+ update - PUT /v1/secret_spaces/:id
113
+ delete - DELETE /v1/secret_spaces/password/:id
114
+ ```
115
+
116
+ Requirements
117
+ ============
118
+
119
+ | Name | Version |
120
+ | :--: | :---: |
121
+ | [Ruby][ruby] | 2.1.5 |
122
+ | [Ruby on Rails][rails] | 4.1.8 |
123
+
124
+ You can find some guidelines on how to install above [on mac][mac_guidelines] and [on ubuntu][ubuntu_guidelines]
125
+
126
+ #### Optional (recommended)
127
+
128
+ - git (mac - `brew install git`, ubuntu - `apt-get install git`)
129
+
130
+
131
+ Setup
132
+ =====
133
+
134
+ - clone repo to your local machine `git clone https://github.com/netguru/devise-ios-rails.git ./devise-ios-rails`
135
+
136
+ Database config
137
+ ---------------
138
+
139
+ - copy config/database.yml.sample to config/database.yml `cp config/database.yml.sample to config/database.yml`
140
+ - fill in your appropriate details in your database.yml config file, example:
141
+
142
+ ```yaml
143
+ development:
144
+ adapter: sqlite3
145
+ host: localhost
146
+ database: devise_ios_rails_development.sqlite3
147
+ username: devise_ios_rails
148
+ ```
149
+
150
+ - and create a database:
151
+
152
+ ```bash
153
+ rake db:create
154
+ rake db:schema:load
155
+ rake db:test:prepare
156
+ ```
157
+
158
+ - create seed data with `rake db:seed`
159
+
160
+ this will create:
161
+
162
+ * users:
163
+ - registered user - ios@example.com / alcatraz
164
+
165
+ Environment config
166
+ ------------------
167
+
168
+ - copy .env.sample to .env `cp .env.sample .env`
169
+ - fill your domain name and url - in local environment it's normally `localhost` and `http://localhost:3000` respectively.
170
+ - you will need to generate your own `SECRET_KEY_BASE` by running `rake secret` and pasting the output into .env file.
171
+ - you can omit Rollbar config in development environment.
172
+
173
+ Start Server
174
+ ------------
175
+
176
+ Before you start app be sure that PostgreSQL is already running. Then start Rails server on default port with `rails server`.
177
+
178
+ Tests
179
+ =====
180
+
181
+ - you run tests with `spring rspec`
182
+
183
+ Other tools
184
+ ===========
185
+
186
+ Spring
187
+ ------
188
+
189
+ You can use [Spring][spring] to speed up specs, rake tasks and rails commands.
190
+
191
+ Just add `spring` before commands like `rspec`, `rake`, `rails`
192
+
193
+ Contribution
194
+ ============
195
+
196
+ First, thank you for contributing!
197
+
198
+ Here a few guidelines to follow:
199
+
200
+ - we follow [Ruby Style Guide][ruby_style_guides].
201
+ - you can use [rubocop][rubocop] which can be easily integrated with popular editors. ([our rubocop config][rubocop_config])
202
+ - keep gems up to date - you can use [gemsurance][gemsurance] to check for outdated gems - simply run `bundle exec gemsurance`.
203
+ - write tests
204
+ - make sure the entire test suite passes
205
+ - make sure rubocop passes, our config
206
+ - open a pull request on GitHub
207
+ - [squash your commits][squash_commits] after receiving feedback
208
+
209
+ Copyright 2014 © [Netguru][netguru_url], released under the New BSD License
210
+
211
+ [heroku_docs]: https://devise-ios-rails-example.herokuapp.com/doc
212
+ [ruby]: https://www.ruby-lang.org
213
+ [rails]: http://www.rubyonrails.org
214
+ [postgres]: http://www.postgresql.org
215
+ [ios_devise]: https://github.com/netguru/devise-ios
216
+ [mac_guidelines]: https://gorails.com/setup/osx/10.10-yosemite
217
+ [ubuntu_guidelines]: https://gorails.com/setup/ubuntu/14.10
218
+ [postgres_guidelines]: https://wiki.postgresql.org/wiki/Detailed_installation_guides
219
+ [spring]: https://github.com/rails/spring
220
+ [ruby_style_guides]: https://github.com/bbatsov/ruby-style-guide
221
+ [rubocop]: https://github.com/bbatsov/rubocop
222
+ [rubocop_config]: https://github.com/netguru/hound/blob/master/config/rubocop.yml
223
+ [gemsurance]: https://github.com/appfolio/gemsurance
224
+ [squash_commits]: http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request
225
+ [netguru_url]: https://netguru.co
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1 @@
1
+ #= require active_admin/base
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://coffeescript.org/
@@ -0,0 +1,17 @@
1
+ // SASS variable overrides must be declared before loading up Active Admin's styles.
2
+ //
3
+ // To view the variables that Active Admin provides, take a look at
4
+ // `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
5
+ // Active Admin source.
6
+ //
7
+ // For example, to change the sidebar width:
8
+ // $sidebar-width: 242px;
9
+
10
+ // Active Admin's got SASS!
11
+ @import "active_admin/mixins";
12
+ @import "active_admin/base";
13
+
14
+ // Overriding any non-variable SASS must be done after the fact.
15
+ // For example, to change the default status-tag color:
16
+ //
17
+ // .status_tag { background: #6090DB; }
@@ -0,0 +1,69 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ p, ol, ul, td {
10
+ font-family: verdana, arial, helvetica, sans-serif;
11
+ font-size: 13px;
12
+ line-height: 18px;
13
+ }
14
+
15
+ pre {
16
+ background-color: #eee;
17
+ padding: 10px;
18
+ font-size: 11px;
19
+ }
20
+
21
+ a {
22
+ color: #000;
23
+ &:visited {
24
+ color: #666;
25
+ }
26
+ &:hover {
27
+ color: #fff;
28
+ background-color: #000;
29
+ }
30
+ }
31
+
32
+ div {
33
+ &.field, &.actions {
34
+ margin-bottom: 10px;
35
+ }
36
+ }
37
+
38
+ #notice {
39
+ color: green;
40
+ }
41
+
42
+ .field_with_errors {
43
+ padding: 2px;
44
+ background-color: red;
45
+ display: table;
46
+ }
47
+
48
+ #error_explanation {
49
+ width: 450px;
50
+ border: 2px solid red;
51
+ padding: 7px;
52
+ padding-bottom: 0;
53
+ margin-bottom: 20px;
54
+ background-color: #f0f0f0;
55
+ h2 {
56
+ text-align: left;
57
+ font-weight: bold;
58
+ padding: 5px 5px 5px 15px;
59
+ font-size: 12px;
60
+ margin: -7px;
61
+ margin-bottom: 0px;
62
+ background-color: #c00;
63
+ color: #fff;
64
+ }
65
+ ul li {
66
+ font-size: 12px;
67
+ list-style: square;
68
+ }
69
+ }
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the secret_spaces controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,49 @@
1
+ class SecretSpacesController < ApplicationController
2
+ acts_as_token_authentication_handler_for User
3
+
4
+ before_action :set_secret_space, only: [:show, :edit, :update, :destroy]
5
+
6
+ respond_to :html, :json
7
+
8
+ def index
9
+ @secret_spaces = SecretSpace.all
10
+ respond_with(@secret_spaces)
11
+ end
12
+
13
+ def show
14
+ respond_with(@secret_space)
15
+ end
16
+
17
+ def new
18
+ @secret_space = SecretSpace.new
19
+ respond_with(@secret_space)
20
+ end
21
+
22
+ def edit
23
+ end
24
+
25
+ def create
26
+ @secret_space = SecretSpace.new(secret_space_params)
27
+ @secret_space.save
28
+ respond_with(@secret_space)
29
+ end
30
+
31
+ def update
32
+ @secret_space.update(secret_space_params)
33
+ respond_with(@secret_space)
34
+ end
35
+
36
+ def destroy
37
+ @secret_space.destroy
38
+ respond_with(@secret_space)
39
+ end
40
+
41
+ private
42
+ def set_secret_space
43
+ @secret_space = SecretSpace.find(params[:id])
44
+ end
45
+
46
+ def secret_space_params
47
+ params.require(:secret_space).permit(:text)
48
+ end
49
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module SecretSpacesHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class SecretSpace < ActiveRecord::Base
2
+ validates :text, presence: true
3
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_token_authenticatable
3
+ devise :database_authenticatable, :registerable,
4
+ :recoverable, :rememberable, :validatable
5
+ end
@@ -0,0 +1,3 @@
1
+ class SecretSpaceSerializer < ActiveModel::Serializer
2
+ attributes :id
3
+ end
@@ -0,0 +1,8 @@
1
+ class UserSerializer < ActiveModel::Serializer
2
+ attributes \
3
+ :id,
4
+ :email,
5
+ :authentication_token,
6
+ :created_at,
7
+ :updated_at
8
+ end
@@ -0,0 +1,5 @@
1
+ module V1
2
+ class BaseSerializer < ActiveModel::Serializer
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module V1
2
+ class UserSerializer < ::UserSerializer
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ = form_for @secret_space do |f|
2
+ - if @secret_space.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@secret_space.errors.count, "error")} prohibited this secret_space from being saved:"
5
+ %ul
6
+ - @secret_space.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ .field
10
+ = f.label :text
11
+ = f.text_field :text
12
+ .actions
13
+ = f.submit 'Save'