Skip to content
Snippets Groups Projects
Commit dac95d39 authored by pabois's avatar pabois
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents d27377a7 af87e62f
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ module User::WithAuthentication
validates :mobile_phone, format: { with: /\A\+[0-9]+\z/ }, allow_blank: true
before_validation :adjust_mobile_phone, :sanitize_fields
before_validation :set_default_role, on: :create
def self.find_for_authentication(warden_conditions)
where(email: warden_conditions[:email].downcase, university_id: warden_conditions[:university_id]).first
......@@ -71,6 +72,16 @@ module User::WithAuthentication
self.mobile_phone = full_sanitizer.sanitize(self.mobile_phone)&.gsub('=', '')
end
def set_default_role
if User.all.empty?
role = :superadmin
elsif university.users.empty?
role = :admin
else
role = :visitor
end
end
def password_required?
!persisted? || !password.nil? || !password_confirmation.nil?
end
......
......@@ -143,7 +143,7 @@ Devise.setup do |config|
# without confirming their account.
# Default is 0.days, meaning the user cannot access the website without
# confirming their account.
# config.allow_unconfirmed_access_for = 2.days
config.allow_unconfirmed_access_for = 1.day
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
......
......@@ -8,7 +8,10 @@ namespace :app do
desc 'Fix things'
task fix: :environment do
User.find_each(&:confirm)
User.find_each { |u|
u.confirm
u.update(role: :visitor) if u.role.nil?
}
end
namespace :db do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment