1
0
Fork 0

Add model User

This commit is contained in:
Alex Kotov 2018-11-30 01:57:57 +05:00
parent 1bd9dd6785
commit 80fbd8c051
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
8 changed files with 118 additions and 10 deletions

View File

@ -16,6 +16,10 @@ Layout/AlignHash:
Layout/EmptyLinesAroundArguments:
Enabled: false
Metrics/AbcSize:
Exclude:
- 'db/migrate/*.rb'
Metrics/BlockLength:
Exclude:
- 'config/initializers/*.rb'

16
app/models/user.rb Normal file
View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
class User < ApplicationRecord
devise(
# :confirmable,
:database_authenticatable,
# :lockable,
# :omniauthable,
# :recoverable,
:registerable,
:rememberable,
# :timeoutable,
:trackable,
:validatable,
)
end

View File

@ -85,7 +85,7 @@ Devise.setup do |config|
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# particular strategies by setting this option.
@ -121,10 +121,10 @@ Devise.setup do |config|
config.pepper = Rails.application.credentials.pepper
# Send a notification to the original email when the user's email is changed.
# config.send_email_changed_notification = false
config.send_email_changed_notification = false
# Send a notification email when the user's password is changed.
# config.send_password_change_notification = false
config.send_password_change_notification = false
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
@ -153,21 +153,21 @@ Devise.setup do |config|
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
config.remember_for = 2.weeks
# Invalidates all the remember me tokens when the user signs out.
config.expire_all_remember_me_on_sign_out = true
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
config.extend_remember_period = true
# Options to be passed to the created cookie. For instance, you can set
# secure: true in order to force SSL only cookies.
# config.rememberable_options = {}
config.rememberable_options = { secure: true }
# ==> Configuration for :validatable
# Range for password length.
config.password_length = 6..128
config.password_length = 8..128
# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly

View File

@ -1,8 +1,6 @@
# frozen_string_literal: true
Rails.application.routes.draw do
root to: 'home#show'
get '/s/452465', to: 'home#event1'
get '/s/243898', to: 'home#post1'
get '/s/377295', to: 'home#post2'
@ -19,6 +17,12 @@ Rails.application.routes.draw do
'sekretar-ro-lpr-v-permskom-krae-byl-zaderzhan-na-4-chasa.html',
to: 'home#post2'
#####
root to: 'home#show'
devise_for :users
resources :membership_applications, only: %i[new create]
resources :telegram_bot_updates, only: :create

View File

@ -0,0 +1,43 @@
# frozen_string_literal: true
class DeviseCreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
t.timestamps null: false
## Database authenticatable
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.inet :current_sign_in_ip
t.inet :last_sign_in_ip
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email
## Lockable
t.integer :failed_attempts, default: 0, null: false
t.string :unlock_token
t.datetime :locked_at
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
add_index :users, :confirmation_token, unique: true
add_index :users, :unlock_token, unique: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_11_29_141112) do
ActiveRecord::Schema.define(version: 2018_11_29_203927) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -37,4 +37,30 @@ ActiveRecord::Schema.define(version: 2018_11_29_141112) do
t.string "api_token", null: false
end
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end
end

8
factories/users.rb Normal file
View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
FactoryBot.define do
factory :user do
email { Faker::Internet.email }
password { Faker::Internet.password }
end
end

7
spec/models/user_spec.rb Normal file
View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe User, type: :model do
subject { create :user }
end