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
Merged

Authenticate/Inviting #1

merged 11 commits into from
Sep 8, 2019

Conversation

mikeoleynik
Copy link
Owner

Добавил аутентификацию с помощью JWT.

Аутентификация

#POST /login

Параметры

email - почта
password - пароль

Пример ответа

{
  "auth_token": 
    "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOjF9.8qe4z53MfSHpishfjOtfMGc1ybHjsj9Ro7meOzTFLxY"
}

Отправляем инвайт

# GET /send_invite

Заголовки

Authorization

Пример ответа

{
  "success": "invite sent"
}

Создаем пользователя

# POST /users

Параметры

email - почта
password - пароль

Пример ответа

{
  "success": [
    "User created"
  ],
}


private

def authorize!

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
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class HomeController < ApplicationController
before_action :authorize!
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 /invite
def invite
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.

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

# 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

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

Choose a reason for hiding this comment

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

null: false ?

Copy link
Owner Author

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

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

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: ''

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]',

Choose a reason for hiding this comment

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

create!

@@ -0,0 +1,6 @@
FactoryBot.define do
factory :user do
email { '[email protected]' }

Choose a reason for hiding this comment

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

gem faker

@mikeoleynik mikeoleynik merged commit 3f38e53 into master Sep 8, 2019
@mikeoleynik mikeoleynik deleted the auth branch September 8, 2019 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants