Class: Gitlab::OAuth::User

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/o_auth/user.rb

Direct Known Subclasses

LDAP::User, Saml::User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_hash) ⇒ User

Returns a new instance of User


13
14
15
# File 'lib/gitlab/o_auth/user.rb', line 13

def initialize(auth_hash)
  self.auth_hash = auth_hash
end

Instance Attribute Details

#auth_hashObject

Returns the value of attribute auth_hash


11
12
13
# File 'lib/gitlab/o_auth/user.rb', line 11

def auth_hash
  @auth_hash
end

#gl_userObject

Returns the value of attribute gl_user


11
12
13
# File 'lib/gitlab/o_auth/user.rb', line 11

def gl_user
  @gl_user
end

Instance Method Details

#new?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/gitlab/o_auth/user.rb', line 21

def new?
  !persisted?
end

#persisted?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/gitlab/o_auth/user.rb', line 17

def persisted?
  gl_user.try(:persisted?)
end

#save(provider = 'OAuth') ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/o_auth/user.rb', line 29

def save(provider = 'OAuth')
  unauthorized_to_create unless gl_user

  if needs_blocking?
    gl_user.save!
    gl_user.block
  else
    gl_user.save!
  end

  log.info "(#{provider}) saving user #{auth_hash.email} from login with extern_uid => #{auth_hash.uid}"
  gl_user
rescue ActiveRecord::RecordInvalid => e
  log.info "(#{provider}) Error saving user: #{gl_user.errors.full_messages}"
  return self, e.record.errors
end

#valid?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/gitlab/o_auth/user.rb', line 25

def valid?
  gl_user.try(:valid?)
end