Module: Eli::Admin
- Defined in:
- lib/eli/admin.rb,
lib/eli/admin/app.rb,
lib/eli/admin/organization.rb
Overview
Documentation for Eli::Admin.
Administrative REST client used to manage admin sessions, accounts and to sign users in on their behalf.
Defined Under Namespace
Classes: App, Organization
Class Method Summary collapse
-
.confirm(confirmation_token) ⇒ Object
Confirms user's email.
-
.current_user(session_token) ⇒ Object
Returns the current admin user data.
-
.recover_password(token, password, password_confirmation) ⇒ Object
Recover password updating it.
-
.refresh(session_token) ⇒ Object
Refresh your token session returning a new session token.
-
.request_password_recovery(app_token, email) ⇒ Object
Requests password recovery.
-
.sign_in(email, password) ⇒ Object
Sign in.
-
.sign_out(session_token) ⇒ Object
Signs the admin user out closing and deleting the session.
-
.signed_in(session_token) ⇒ Object
Checks whether the admin user is signed in or not.
-
.signs_in(session_token, user_data, app_id) ⇒ Object
Admin signs in any user without password.
-
.unlock(unlock_token) ⇒ Object
Unlocks user making him/her able to sign in again.
Class Method Details
.confirm(confirmation_token) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/eli/admin.rb', line 151 def confirm(confirmation_token) url = Eli::Config.base_url + "/rest/accounts/confirm" = { params: { token: confirmation_token } } Eli::RestApi.put(url, ) end |
.current_user(session_token) ⇒ Object
Returns the current admin user data.
Examples
Eli::Admin.current_user("JWT session token")
# 200
# {
# "data" => {
# "active" => true,
# "email" => "user@mail.com",
# "id" => "732cf1c2-6299-41fa-8784-e458765743b7",
# "language" => "en",
# "name" => "User Name",
# "timezone" => "Europe/London"
# }
# }
# 404
# { "errors" => { "detail" => "Not Found" } }
71 72 73 74 75 76 77 78 79 |
# File 'lib/eli/admin.rb', line 71 def current_user(session_token) url = Eli::Config.base_url + "/rest/admin/sessions" = { headers: { "authorization" => "Bearer #{session_token}" } } Eli::RestApi.get(url, ) end |
.recover_password(token, password, password_confirmation) ⇒ Object
Recover password updating it.
Examples
Eli::Admin.recover_password("token", "Secret.123", "Secret.123")
# 200
# { "data" => { "message" => "password was successfully recovered" } }
# 400
# { "errors" => { "detail" => "token is invalid" } }
# 400
# { "errors" => { "detail" => "password has an invalid format" } }
# 400
# { "errors" => { "detail" => "password and confirmation password are different" } }
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/eli/admin.rb', line 198 def recover_password(token, password, password_confirmation) url = Eli::Config.base_url + "/rest/accounts/password/recover" = { params: { token: token, password: password, password_confirmation: password_confirmation } } Eli::RestApi.put(url, ) end |
.refresh(session_token) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/eli/admin.rb', line 91 def refresh(session_token) url = Eli::Config.base_url + "/rest/admin/sessions" = { headers: { "authorization" => "Bearer #{session_token}" } } Eli::RestApi.put(url, ) end |
.request_password_recovery(app_token, email) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/eli/admin.rb', line 171 def request_password_recovery(app_token, email) url = Eli::Config.base_url + "/rest/accounts/password/recover" = { headers: { "app-token" => app_token }, params: { email: email } } Eli::RestApi.post(url, ) end |
.sign_in(email, password) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/eli/admin.rb', line 21 def sign_in(email, password) url = Eli::Config.base_url + "/rest/admin/sessions" = { params: { email: email, password: password } } Eli::RestApi.post(url, ) end |
.sign_out(session_token) ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/eli/admin.rb', line 111 def sign_out(session_token) url = Eli::Config.base_url + "/rest/admin/sessions" = { headers: { "authorization" => "Bearer #{session_token}" } } Eli::RestApi.delete(url, ) end |
.signed_in(session_token) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eli/admin.rb', line 41 def signed_in(session_token) url = Eli::Config.base_url + "/rest/admin/sessions/signed_in" = { headers: { "authorization" => "Bearer #{session_token}" } } resp = Eli::RestApi.head(url, ) resp.status == 200 end |
.signs_in(session_token, user_data, app_id) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/eli/admin.rb', line 226 def signs_in(session_token, user_data, app_id) url = Eli::Config.base_url + "/rest/admin/sessions/signs_in" = { headers: { "authorization" => "Bearer #{session_token}" }, params: { user_data: user_data, app_id: app_id } } Eli::RestApi.post(url, ) end |