Class: AuthRocket::User
- Inherits:
-
Resource
- Object
- Resource
- AuthRocket::User
- Defined in:
- lib/authrocket/user.rb
Instance Attribute Summary collapse
-
#custom ⇒ Object
readonly
Returns the value of attribute custom.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#email_pending ⇒ Object
readonly
Returns the value of attribute email_pending.
-
#email_verification ⇒ Object
readonly
Returns the value of attribute email_verification.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
readonly
writeonly.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.authenticate(id, params) ⇒ Object
params - ‘…’ returns: Session || Token.
-
.authenticate_token(params) ⇒ Object
params - ‘kli:…’, code: ‘000000’ returns: Session.
-
.generate_password_token(id, params = {}) ⇒ Object
returns: Token.
-
.request_email_verification(id, params = {}) ⇒ Object
returns: Token.
-
.reset_password_with_token(params) ⇒ Object
params - ‘…’, password: ‘…’, password_confirmation: ‘…’ returns: Session || Token.
-
.verify_email(params) ⇒ Object
params - ‘…’ returns: User.
Instance Method Summary collapse
-
#accept_invitation(params) ⇒ Object
params - ‘…’.
-
#authenticate(params) ⇒ Object
returns: Session || Token (Session.user !== self).
- #credentials ⇒ Object
- #find_org(id) ⇒ Object
-
#generate_password_token(params = {}) ⇒ Object
returns: Token.
- #orgs ⇒ Object
-
#request_email_verification(params = {}) ⇒ Object
returns: Token.
-
#update_password(params) ⇒ Object
params - ‘old’, password: ‘new’, password_confirmation: ‘new’.
-
#update_profile(params) ⇒ Object
params - first_name:, last_name:, password:, password_confirmation:, username:.
Instance Attribute Details
#custom ⇒ Object (readonly)
Returns the value of attribute custom.
12 13 14 |
# File 'lib/authrocket/user.rb', line 12 def custom @custom end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
12 13 14 |
# File 'lib/authrocket/user.rb', line 12 def email @email end |
#email_pending ⇒ Object (readonly)
Returns the value of attribute email_pending.
12 13 14 |
# File 'lib/authrocket/user.rb', line 12 def email_pending @email_pending end |
#email_verification ⇒ Object (readonly)
Returns the value of attribute email_verification.
12 13 14 |
# File 'lib/authrocket/user.rb', line 12 def email_verification @email_verification end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
12 13 14 |
# File 'lib/authrocket/user.rb', line 12 def first_name @first_name end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
12 13 14 |
# File 'lib/authrocket/user.rb', line 12 def last_name @last_name end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
13 14 15 |
# File 'lib/authrocket/user.rb', line 13 def locale @locale end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/authrocket/user.rb', line 13 def name @name end |
#password ⇒ Object (readonly)
writeonly
14 15 16 |
# File 'lib/authrocket/user.rb', line 14 def password @password end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
13 14 15 |
# File 'lib/authrocket/user.rb', line 13 def reference @reference end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
13 14 15 |
# File 'lib/authrocket/user.rb', line 13 def state @state end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
13 14 15 |
# File 'lib/authrocket/user.rb', line 13 def username @username end |
Class Method Details
.authenticate(id, params) ⇒ Object
params - ‘…’ returns: Session || Token
37 38 39 40 41 42 43 |
# File 'lib/authrocket/user.rb', line 37 def authenticate(id, params) params = parse_request_params(params, json_root: json_root) parsed, creds = request(:post, "#{resource_path}/#{CGI.escape id}/authenticate", params) obj = factory(parsed, creds) raise RecordInvalid, obj if obj.errors? obj end |
.authenticate_token(params) ⇒ Object
params - ‘kli:…’, code: ‘000000’ returns: Session
47 48 49 50 51 52 53 |
# File 'lib/authrocket/user.rb', line 47 def authenticate_token(params) params = parse_request_params(params, json_root: json_root) parsed, creds = request(:post, "#{resource_path}/authenticate_token", params) obj = factory(parsed, creds) raise RecordInvalid, obj if obj.errors? obj end |
.generate_password_token(id, params = {}) ⇒ Object
returns: Token
56 57 58 59 60 61 62 |
# File 'lib/authrocket/user.rb', line 56 def generate_password_token(id, params={}) params = parse_request_params(params) parsed, creds = request(:post, "#{resource_path}/#{CGI.escape id}/generate_password_token", params) obj = factory(parsed, creds) raise RecordInvalid, obj if obj.errors? obj end |
.request_email_verification(id, params = {}) ⇒ Object
returns: Token
75 76 77 78 79 80 81 |
# File 'lib/authrocket/user.rb', line 75 def request_email_verification(id, params={}) params = parse_request_params(params) parsed, creds = request(:post, "#{resource_path}/#{CGI.escape id}/request_email_verification", params) obj = factory(parsed, creds) raise RecordInvalid, obj if obj.errors? obj end |
.reset_password_with_token(params) ⇒ Object
params - ‘…’, password: ‘…’, password_confirmation: ‘…’ returns: Session || Token
66 67 68 69 70 71 72 |
# File 'lib/authrocket/user.rb', line 66 def reset_password_with_token(params) params = parse_request_params(params, json_root: json_root) parsed, creds = request(:post, "#{resource_path}/reset_password_with_token", params) obj = factory(parsed, creds) raise RecordInvalid, obj if obj.errors? obj end |
.verify_email(params) ⇒ Object
params - ‘…’ returns: User
85 86 87 88 89 90 91 |
# File 'lib/authrocket/user.rb', line 85 def verify_email(params) params = parse_request_params(params, json_root: json_root) parsed, creds = request(:post, "#{resource_path}/verify_email", params) obj = factory(parsed, creds) raise RecordInvalid, obj if obj.errors? obj end |
Instance Method Details
#accept_invitation(params) ⇒ Object
params - ‘…’
97 98 99 100 101 102 |
# File 'lib/authrocket/user.rb', line 97 def accept_invitation(params) params = parse_request_params(params, json_root: json_root).reverse_merge credentials: api_creds parsed, _ = request(:post, "#{resource_path}/accept_invitation", params) load(parsed) errors.empty? ? self : false end |
#authenticate(params) ⇒ Object
returns: Session || Token
(Session.user !== self)
123 124 125 126 127 128 |
# File 'lib/authrocket/user.rb', line 123 def authenticate(params) self.class.authenticate id, params.reverse_merge(credentials: api_creds) rescue RecordInvalid => ex errors.merge! ex.errors false end |
#credentials ⇒ Object
18 19 20 21 |
# File 'lib/authrocket/user.rb', line 18 def credentials reload unless @attribs[:credentials] @attribs[:credentials] end |
#find_org(id) ⇒ Object
27 28 29 |
# File 'lib/authrocket/user.rb', line 27 def find_org(id) orgs.detect{|o| o.id == id } || raise(RecordNotFound) end |
#generate_password_token(params = {}) ⇒ Object
returns: Token
131 132 133 134 135 136 |
# File 'lib/authrocket/user.rb', line 131 def generate_password_token(params={}) self.class.generate_password_token id, params.reverse_merge(credentials: api_creds) rescue RecordInvalid => ex errors.merge! ex.errors false end |
#orgs ⇒ Object
23 24 25 |
# File 'lib/authrocket/user.rb', line 23 def orgs memberships.map(&:org) end |
#request_email_verification(params = {}) ⇒ Object
returns: Token
139 140 141 142 143 144 |
# File 'lib/authrocket/user.rb', line 139 def request_email_verification(params={}) self.class.request_email_verification id, params.reverse_merge(credentials: api_creds) rescue RecordInvalid => ex errors.merge! ex.errors false end |
#update_password(params) ⇒ Object
params - ‘old’, password: ‘new’, password_confirmation: ‘new’
105 106 107 108 109 110 |
# File 'lib/authrocket/user.rb', line 105 def update_password(params) params = parse_request_params(params, json_root: json_root).reverse_merge credentials: api_creds parsed, _ = request(:put, "#{resource_path}/update_password", params) load(parsed) errors.empty? ? self : false end |
#update_profile(params) ⇒ Object
params - first_name:, last_name:, password:, password_confirmation:, username:
113 114 115 116 117 118 |
# File 'lib/authrocket/user.rb', line 113 def update_profile(params) params = parse_request_params(params, json_root: json_root).reverse_merge credentials: api_creds parsed, _ = request(:put, "#{resource_path}/profile", params) load(parsed) errors.empty? ? self : false end |