Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
model/routes fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
127 committed Feb 27, 2020
1 parent e9b1fa4 commit 6cd61da
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.0
2.6.5
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.0'
ruby '2.6.5'
gem 'pg'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
Expand Down Expand Up @@ -60,8 +60,8 @@ gem 'bootstrap4-kaminari-views'
gem 'devise'
gem 'devise_invitable' #, '~> 2.0.0'

gem 'omniauth-facebook' # use very carefuylly
gem 'omniauth-twitter'
# gem 'omniauth-facebook' # use very carefuylly
# gem 'omniauth-twitter'
# gem 'omniauth-linkedin'

gem 'kaminari'
Expand Down
90 changes: 30 additions & 60 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
bcrypt (3.1.13)
bindex (0.8.1)
bootsnap (1.4.5)
bootsnap (1.4.6)
msgpack (~> 1.0)
bootstrap4-kaminari-views (1.0.1)
kaminari (>= 0.13)
rails (>= 3.1)
builder (3.2.4)
byebug (11.0.1)
capybara (3.30.0)
byebug (11.1.1)
capybara (3.31.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -79,8 +79,8 @@ GEM
capybara (>= 2.4, < 4.0)
mail
childprocess (3.0.0)
concurrent-ruby (1.1.5)
crass (1.0.5)
concurrent-ruby (1.1.6)
crass (1.0.6)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -91,30 +91,26 @@ GEM
actionmailer (>= 5.0)
devise (>= 4.6)
erubi (1.9.0)
faraday (1.0.0)
multipart-post (>= 1.2, < 3)
ffi (1.11.3)
ffi (1.12.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashie (3.6.0)
i18n (1.7.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
json (2.3.0)
jwt (2.2.1)
kaminari (1.1.1)
kaminari (1.2.0)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
kaminari-actionview (= 1.2.0)
kaminari-activerecord (= 1.2.0)
kaminari-core (= 1.2.0)
kaminari-actionview (1.2.0)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
kaminari-core (= 1.2.0)
kaminari-activerecord (1.2.0)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kaminari-core (= 1.2.0)
kaminari-core (1.2.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -127,46 +123,22 @@ GEM
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mimemagic (0.3.4)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.13.0)
msgpack (1.3.1)
multi_json (1.14.1)
multi_xml (0.6.0)
multipart-post (2.1.1)
minitest (5.14.0)
msgpack (1.3.3)
nio4r (2.5.2)
nokogiri (1.10.7)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
oauth (0.5.4)
oauth2 (1.4.2)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.9.0)
hashie (>= 3.4.6, < 3.7.0)
rack (>= 1.6.2, < 3)
omniauth-facebook (5.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
omniauth-oauth2 (1.6.0)
oauth2 (~> 1.1)
omniauth (~> 1.9)
omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1)
rack
orm_adapter (0.5.0)
paranoia (2.4.2)
activerecord (>= 4.0, < 6.1)
pg (1.2.1)
pg (1.2.2)
public_suffix (4.0.3)
puma (4.3.1)
nio4r (~> 2.0)
rack (2.0.8)
rack (2.2.2)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
Expand Down Expand Up @@ -201,14 +173,14 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.1)
ffi (~> 1.0)
recaptcha (5.2.1)
recaptcha (5.3.0)
json
regexp_parser (1.6.0)
regexp_parser (1.7.0)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
ruby_dep (1.5.0)
rubyzip (2.0.0)
rubyzip (2.2.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.2.1)
Expand All @@ -222,14 +194,14 @@ GEM
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
simple_form (5.0.1)
simple_form (5.0.2)
actionpack (>= 5.0)
activemodel (>= 5.0)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.2)
sprockets (4.0.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
Expand Down Expand Up @@ -280,8 +252,6 @@ DEPENDENCIES
jbuilder (~> 2.7)
kaminari
listen (>= 3.0.5, < 3.2)
omniauth-facebook
omniauth-twitter
paranoia (~> 2.2)
pg
puma (~> 4.1)
Expand All @@ -298,7 +268,7 @@ DEPENDENCIES
webpacker (~> 4.0)

RUBY VERSION
ruby 2.7.0p0
ruby 2.6.5p114

BUNDLED WITH
2.1.4
31 changes: 15 additions & 16 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ class User < ApplicationRecord

belongs_to :account
has_and_belongs_to_many :roles
has_many :identities, :dependent => :destroy
has_many :identities, dependent: :destroy
# has_many :wallets

validates_format_of :email, :without => TEMP_EMAIL_REGEX, on: :update
validates_format_of :email, without: TEMP_EMAIL_REGEX, on: :update

paginates_per 10

devise :invitable, :database_authenticatable, :registerable, :confirmable,
:lockable, :recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook, :twitter]
:lockable, :recoverable, :rememberable, :trackable, :validatable
#,:omniauthable, :omniauth_providers => [:facebook, :twitter]
# before_invitation_created :setup_role
# before_invitation_created :setup_account
#:facebook, :twitter, :linkedin]

def role? role
return !!self.roles.find_by_name(role.to_s)
!!roles.find_by_name(role.to_s)
end

def self.find_for_oauth(auth, signed_in_resource = nil)
Expand All @@ -34,25 +34,24 @@ def self.find_for_oauth(auth, signed_in_resource = nil)
# что бы identity не была закрыта случайно созданным аккаунтом.
# Заметьте, что это может оставить зомби-аккаунты (без прикрепленной identity)
# которые позже могут быть удалены
user = signed_in_resource ? signed_in_resource : identity.user
user = signed_in_resource || identity.user

# Создать пользователя, если нужно
if user.nil?

# Получить email пользователя, если его предоставляет провайдер
# Если email не был предоставлен мы даем пользователю временный и просим
# пользователя установить и подтвердить новый в следующим шаге через UsersController.finish_signup
# email_is_verified = auth.info.email && (auth.info.verified || auth.info.verified_email)
# email = auth.info.email if email_is_verified
email = auth.info.email if auth.info.email
user = User.where(:email => email).first if email
user = User.where(email: email).first if email

# Создать пользователя, если это новая запись
if user.nil?
user = User.new(
name: auth.extra.raw_info.name,
email: email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
password: Devise.friendly_token[0, 20]
name: auth.extra.raw_info.name,
email: email ? email : "#{TEMP_EMAIL_PREFIX}-#{auth.uid}-#{auth.provider}.com",
password: Devise.friendly_token[0, 20]
)
user.skip_confirmation!
user.save!
Expand All @@ -68,22 +67,22 @@ def self.find_for_oauth(auth, signed_in_resource = nil)
end

def email_verified?
self.email && self.email !~ TEMP_EMAIL_REGEX
email && email !~ TEMP_EMAIL_REGEX
end

#Protected methods do not invoke in devise_invitable

protected

def setup_role
self.role_ids = [3] if self.invited_by_id != nil && self.role_ids.empty?
self.role_ids = [2] if self.role_ids.empty?
self.role_ids = [3] if !invited_by_id.nil? && role_ids.empty?
self.role_ids = [2] if role_ids.empty?
end

# Default role is "Registered"
def setup_account
self.account = self.invited_by.account if self.invited_by_id != nil && self.account_id == nil
self.account = Account.create if self.account_id == nil
self.account = invited_by.account if !invited_by_id.nil? && account_id.nil?
self.account = Account.create if account_id.nil?
end

end
7 changes: 3 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@
<%= link_to t('shared.labels.logout'), destroy_user_session_path, :method => :delete, :class => 'nav-link' %>
</li>
<% else %>
<li class="nav-item"><a class="nav-link"><%= t 'shared.labels.login' %>:</a></li>
<li class="nav-item<%= ' active'.html_safe if controller.controller_name == 'sessions' %>">
<%= link_to 'a', new_user_session_path, :class => 'nav-link' %>
<%= link_to t('shared.labels.login'), new_user_session_path, :class => 'nav-link' %>
</li>
<li class="nav-item"><%= link_to 'a', user_twitter_omniauth_authorize_path, :class => 'nav-link' %></li>
<li class="nav-item"><%= link_to 'a', user_facebook_omniauth_authorize_path, :class => 'nav-link' %></li>
<!-- <li class="nav-item"><%#= link_to 'a', user_twitter_omniauth_authorize_path, :class => 'nav-link' %></li>-->
<!-- <li class="nav-item"><%#= link_to 'a', user_facebook_omniauth_authorize_path, :class => 'nav-link' %></li>-->
<li class="nav-item<%= ' active'.html_safe if controller.controller_name == 'registrations' %>">
<%= link_to t('shared.labels.registration'), new_user_registration_path, :class => 'nav-link' %>
</li>
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'donotreply@altyn.io'
config.mailer_sender = 'donotreply@pestulon.io'

# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
Expand Down
44 changes: 24 additions & 20 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
# frozen_string_literal: true

# Docs
Rails.application.routes.draw do
devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'omniauth_callbacks'}
# devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'omniauth_callbacks'}

namespace :admin do
root :to => 'users#index'
root to: 'users#index'
resources :subscriptions, :users, :accounts, :roles
end

scope '(:locale)', :locale => /en|ru/ do
scope '(:locale)', locale: /en|ru/ do

root :to => 'pages#index'
root to: 'pages#index'
get 'pages/*page' => 'pages#index', :as => 'pages'

resources :subscriptions, only: [:show, :new, :create]

resources :account, only: [:index] do
delete 'user/:id(.:format)', :to => 'account#remove'
delete 'user/:id(.:format)', to: 'account#remove'
end

devise_for :users, :controllers => {
:registrations => 'registrations',
:invitations => 'invitations'
},
:path => 'auth',
:path_names => {
:sign_in => 'login',
:sign_out => 'logout',
:password => 'secret',
:confirmation => 'verification',
:unlock => 'unblock',
:registration => 'register',
:sign_up => 'cmon_let_me_in'
},
skip: :omniauth_callbacks
devise_for :users,
controllers: {
registrations: 'registrations',
invitations: 'invitations' },
path: 'auth',
path_names: {
sign_in: 'login',
sign_out: 'logout',
password: 'secret',
confirmation: 'verification',
unlock: 'unblock',
registration: 'register',
sign_up: 'cmon_let_me_in'
}
# ,
# skip: :omniauth_callbacks

end
end

0 comments on commit 6cd61da

Please sign in to comment.