1
|
|
|
require 'nokogiri' |
2
|
|
|
require 'open-uri' |
3
|
|
|
|
4
|
|
|
class Participant < ActiveRecord::Base |
5
|
|
|
has_many :sessions |
6
|
|
|
has_many :attendances |
7
|
|
|
has_many :sessions_attending, :through => :attendances, :source => :session |
8
|
|
|
has_many :presentations |
9
|
|
|
has_many :sessions_presenting, :through => :presentations, :source => :session |
10
|
|
|
has_many :presenter_timeslot_restrictions, dependent: :destroy |
11
|
|
|
|
12
|
|
|
validates_presence_of :name |
13
|
|
|
validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true |
14
|
|
|
|
15
|
|
|
before_save :slurp_github_og_info, if: :github_profile_username_changed? |
16
|
|
|
|
17
|
|
|
acts_as_authentic do |config| |
18
|
|
|
config.crypto_provider = Authlogic::CryptoProviders::BCrypt |
19
|
|
|
config.require_password_confirmation = false |
20
|
|
|
end |
21
|
|
|
|
22
|
|
|
def restrict_after(datetime, weight=1, event=Event.current_event) |
23
|
|
|
event.timeslots.each do |timeslot| |
24
|
|
|
if timeslot.ends_at >= datetime |
25
|
|
|
self.presenter_timeslot_restrictions.create!( |
26
|
|
|
timeslot: timeslot, |
27
|
|
|
weight: weight) |
28
|
|
|
end |
29
|
|
|
end |
30
|
|
|
end |
31
|
|
|
|
32
|
|
|
def restrict_before(datetime, weight=1, event=Event.current_event) |
33
|
|
|
event.timeslots.each do |timeslot| |
34
|
|
|
if timeslot.starts_at <= datetime |
35
|
|
|
self.presenter_timeslot_restrictions.create!( |
36
|
|
|
timeslot: timeslot, |
37
|
|
|
weight: weight) |
38
|
|
|
end |
39
|
|
|
end |
40
|
|
|
end |
41
|
|
|
|
42
|
|
|
def deliver_password_reset_instructions! |
43
|
|
|
reset_perishable_token! |
44
|
|
|
Notifier.password_reset_instructions(self).deliver_now! |
45
|
|
|
end |
46
|
|
|
|
47
|
|
|
def attending_session?(session) |
48
|
|
|
sessions_attending.include?(session) |
49
|
|
|
end |
50
|
|
|
|
51
|
|
|
def github_profile_url |
52
|
|
|
"https://github.com/#{self.github_profile_username}" |
53
|
|
|
end |
54
|
|
|
|
55
|
|
|
def slurp_github_og_info |
56
|
|
|
logger.debug "slurp github og info" |
57
|
|
|
|
58
|
|
|
return if self.github_profile_username.blank? |
59
|
|
|
|
60
|
|
|
begin |
61
|
|
|
doc = Nokogiri::HTML(open(github_profile_url)) |
62
|
|
|
|
63
|
|
|
nodes = doc.xpath("//head/meta [@property='og:image']") |
64
|
|
|
self.github_og_image = nodes.first.attributes['content'].value |
65
|
|
|
|
66
|
|
|
nodes = doc.xpath("//head/meta [@property='og:url']") |
67
|
|
|
self.github_og_url = nodes.first.attributes['content'].value |
68
|
|
|
|
69
|
|
|
rescue StandardError => err |
70
|
|
|
logger.error err.message |
71
|
|
|
end |
72
|
|
|
|
73
|
|
|
end |
74
|
|
|
|
75
|
|
|
end |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
|