Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate/Inviting #1

Merged
merged 11 commits into from
Sep 8, 2019
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ gem 'rails', '~> 5.2.3'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'haml-rails', '~> 2.0'
gem 'devise_invitable', '~> 2.0.0'

group :development, :test do
gem 'pry-byebug'
gem 'rspec-rails', '~> 3.8'
gem 'factory_bot_rails'
gem 'letter_opener'
end

group :development do
Expand All @@ -20,4 +23,8 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
gem 'database_cleaner'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
48 changes: 48 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,30 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (9.0.0)
bcrypt (3.1.13)
bootsnap (1.4.5)
msgpack (~> 1.0)
builder (3.2.3)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
database_cleaner (1.7.0)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise_invitable (2.0.1)
actionmailer (>= 5.0)
devise (>= 4.6)
diff-lcs (1.3)
erubi (1.8.0)
erubis (2.7.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.2)
Expand All @@ -60,8 +74,26 @@ GEM
ffi (1.11.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
haml (5.1.2)
temple (>= 0.8.0)
tilt
haml-rails (2.0.1)
actionpack (>= 5.1)
activesupport (>= 5.1)
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 5.1)
html2haml (2.2.0)
erubis (~> 2.7.0)
haml (>= 4.0, < 6)
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.7.0)
launchy (~> 2.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -82,13 +114,15 @@ GEM
nio4r (2.5.1)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
pg (1.1.4)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.7.0)
byebug (~> 11.0)
pry (~> 0.10)
public_suffix (4.0.1)
puma (3.12.1)
rack (2.0.7)
rack-test (1.1.0)
Expand Down Expand Up @@ -121,6 +155,9 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
Expand All @@ -139,6 +176,9 @@ GEM
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
ruby_dep (1.5.0)
ruby_parser (3.13.1)
sexp_processor (~> 4.9)
sexp_processor (4.12.1)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand All @@ -150,10 +190,14 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
temple (0.8.1)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
tzinfo (1.2.5)
thread_safe (~> 0.1)
warden (1.2.8)
rack (>= 2.0.6)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
Expand All @@ -163,7 +207,11 @@ PLATFORMS

DEPENDENCIES
bootsnap (>= 1.1.0)
database_cleaner
devise_invitable (~> 2.0.0)
factory_bot_rails
haml-rails (~> 2.0)
letter_opener
listen (>= 3.0.5, < 3.2)
pg (>= 0.18, < 2.0)
pry-byebug
Expand Down
27 changes: 8 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
# README
## Getting Started

This README would normally document whatever steps are necessary to get the
application up and running.
This section provides quick start guide.

Things you may want to cover:
### Prerequisites

* Ruby version
- [Ruby](https://www.ruby-lang.org/en/): 2.6.3
- [Ruby on Rails](https://rubyonrails.org/): 2.6.3
- [PostgreSQL](https://www.postgresql.org/) 9.4 or higher.

* System dependencies
### Standard Installation

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
1. `bin/setup`
9 changes: 9 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class HomeController < ApplicationController
before_action :authenticate_user!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это имеет смысл перенести в application_controller

# GET /
def homepage
render json: { success: 'ok' }, status: :ok
end
end
11 changes: 11 additions & 0 deletions app/controllers/invites_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class InvitesController < ApplicationController
before_action :authenticate_user!

# GET /invite
def invite

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

такое название метода не по REST.
И судя по всему оно меняет стейт в базе, поэтому надо юзать POST #create

User.invite!(email: '[email protected]', fullname: 'John Doe')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему email захардкожен?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Из-за того, что логики пока никакой нет.

render json: { success: 'invite sent' }, status: :ok
end
end
11 changes: 11 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable,
:invitable

validates :email, :password, presence: true
validates :email, uniqueness: true
validates :password, length: { in: 8..20 }
end
9 changes: 9 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ chdir APP_ROOT do
puts "\n== Preparing database =="
system! 'bin/rails db:setup'

puts "\n== Create database =="
system! 'bin/rails db:create'

puts "\n== Updating database =="
system! 'bin/rails db:migrate'

puts "\n== Fill database =="
system! 'bin/rails db:seed'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Rock
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2

config.autoload_paths << Rails.root.join('lib')
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
Expand Down
3 changes: 2 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.action_mailer.delivery_method = :letter_opener

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
Expand Down
Loading