-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
|
||
private | ||
|
||
def authorize! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем свою писать, если есть sorcery или devise?
Remove authenticate with jwt-token and adding authenticate with devise gem
app/controllers/home_controller.rb
Outdated
@@ -1,7 +1,7 @@ | |||
# frozen_string_literal: true | |||
|
|||
class HomeController < ApplicationController | |||
before_action :authorize! | |||
before_action :authenticate_user! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это имеет смысл перенести в application_controller
|
||
# GET /invite | ||
def invite | ||
User.invite!(email: '[email protected]', fullname: 'John Doe') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему email захардкожен?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Из-за того, что логики пока никакой нет.
config/initializers/devise.rb
Outdated
# Many of these configuration options can be set straight in your model. | ||
Devise.setup do |config| | ||
config.invite_for = 1.weeks | ||
# The secret key used by Devise. Devise uses this key to generate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все эти комментарии имеет смысл вычистить
class CreateUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :users do |t| | ||
t.string :fullname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null: false ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сам всегда ограничения стараюсь ставить. Сегодня воскресенье)
## Rememberable | ||
t.datetime :remember_created_at | ||
|
||
## Trackable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ненужные комменты удаляй
before_action :authenticate_user! | ||
|
||
# GET /invite | ||
def invite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
такое название метода не по REST.
И судя по всему оно меняет стейт в базе, поэтому надо юзать POST #create
class CreateUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :users do |t| | ||
t.string :fullname, null: false, default: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я думаю default тут не нужен, откуда возьмется юзер без имени?
db/seeds.rb
Outdated
# | ||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | ||
# Character.create(name: 'Luke', movie: movies.first) | ||
User.create(email: '[email protected]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create!
spec/factories/user.rb
Outdated
@@ -0,0 +1,6 @@ | |||
FactoryBot.define do | |||
factory :user do | |||
email { '[email protected]' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gem faker
Добавил аутентификацию с помощью JWT.
Аутентификация
#POST /login
Параметры
email
- почтаpassword
- парольПример ответа
Отправляем инвайт
# GET /send_invite
Заголовки
Authorization
Пример ответа
Создаем пользователя
# POST /users
Параметры
email
- почтаpassword
- парольПример ответа