Class: Opium::User

Inherits:
Object show all
Includes:
Model
Defined in:
lib/opium/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#initialize, #inspect

Class Method Details

.authenticate(username, password) ⇒ Object

Note that this will eat any ParseErrors which get raised, and not perform any logging.



17
18
19
20
21
# File 'lib/opium/user.rb', line 17

def authenticate( username, password )
  authenticate!( username, password )
rescue Opium::Model::Connectable::ParseError => e
  nil
end

.authenticate!(username, password) ⇒ Object



23
24
25
# File 'lib/opium/user.rb', line 23

def authenticate!( username, password )
  new( as_resource('login') { http_get query: { username: username, password: password } } )
end

.find_by_session_token(token) ⇒ Object



27
28
29
# File 'lib/opium/user.rb', line 27

def find_by_session_token( token )
  new( http_get id: 'me', headers: { x_parse_session_token: token } )
end

Instance Method Details

#reset_passwordObject



32
33
34
35
36
37
# File 'lib/opium/user.rb', line 32

def reset_password
  reset_password!
rescue => e
  self.errors.add( :email, e.to_s )
  false
end

#reset_password!Object



39
40
41
42
# File 'lib/opium/user.rb', line 39

def reset_password!
  fail KeyError, 'an email address is required to reset password' unless email
  self.class.as_resource('requestPasswordReset') { self.class.http_post data: email }.empty?
end