forked from AgileVentures/projectscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.rb
More file actions
49 lines (45 loc) · 1.64 KB
/
Copy pathuser.rb
File metadata and controls
49 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :string
# last_sign_in_ip :string
# created_at :datetime not null
# updated_at :datetime not null
# provider :string
# uid :string
# role :string default("coach"), not null
#
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :recoverable,
:rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:github]
ADMIN = "admin"
COACH = "coach"
def self.from_omniauth(auth)
email = auth.info.email.nil? ? auth.extra.raw_info.email : auth.info.email
login = auth.extra.raw_info.login
if !login.nil? and !email.nil?
User.where(provider: auth.provider, provider_username: login, email: email).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = email
user.provider_username = login
user.password = Devise.friendly_token[0,20]
end
end
end
def is_admin?
self.role == ADMIN
end
end