Class: EME::AdminUser
- Inherits:
-
APIConsumer
- Object
- APIConsumer
- EME::AdminUser
- Defined in:
- lib/eme/admin_user.rb
Defined Under Namespace
Classes: RequiredLogin, SessionInfo
Class Method Summary collapse
-
.all_permissions(admin_session_key, conn = connection, opts = {}) ⇒ Object
returns all permissions if they are still logged in, and have permissions to see all permissions, permission data only includes, id, controller, action, method.
-
.all_roles(admin_session_key, conn = connection, opts = {}) ⇒ Object
returns all roles if they are still logged in, and have permissions to see all roles, role data only includes, id, name.
-
.all_users(admin_session_key, conn = connection, opts = {}) ⇒ Object
returns all users if they are still logged in, and have permissions to see all users, user data only includes, id, name, last_login, roles, and current_logged_in_status.
- .check_salts ⇒ Object
-
.decode_admin_key_cookie(val, ip) ⇒ Object
SESSION COOKIES.
- .encode_admin_key_cookie(val, ip) ⇒ Object
-
.heartbeat(admin_session_key, conn = connection, opts = {}) ⇒ Object
requires admin_session_key.
- .ipaddress_factor(ip) ⇒ Object
-
.login(email, password, conn = connection, opts = {}) ⇒ Object
if successful username/password combo, it should return a unique 16 digit hex session id for the user.
-
.logout(admin_session_key, conn = connection, opts = {}) ⇒ Object
a get or delete call.
-
.me(admin_session_key, conn = connection, opts = {}) ⇒ Object
This is the call that returns the current user data, including permissions and roles, this will be converted to a Session object that will be used by the app to get your logged in status, and permissions, etc.
-
.role(role_id, admin_session_key, conn = connection, opts = {}) ⇒ Object
returns specific a role’s data; id, name, permissions, users with role.
-
.update_role(role_data, admin_session_key, conn = connection, opts = {}) ⇒ Object
takes a hash of role info(name, and permissions), and posts it to the service to edit the role, if they have permissions.
-
.update_user(user_data, admin_session_key, conn = connection, opts = {}) ⇒ Object
takes a hash of user info, and posts it to the service to edit the user record, if they have permissions.
-
.user(user_id, admin_session_key, conn = connection, opts = {}) ⇒ Object
returns specific users data, DO NOT include session_key_id, or password/hashed_password.
Class Method Details
.all_permissions(admin_session_key, conn = connection, opts = {}) ⇒ Object
returns all permissions if they are still logged in, and have permissions to see all permissions, permission data only includes, id, controller, action, method
74 75 76 |
# File 'lib/eme/admin_user.rb', line 74 def self.(admin_session_key, conn = connection, opts={}) return do_request("/permissions", conn, opts_work(opts, admin_session_key)) end |
.all_roles(admin_session_key, conn = connection, opts = {}) ⇒ Object
returns all roles if they are still logged in, and have permissions to see all roles, role data only includes, id, name
55 56 57 |
# File 'lib/eme/admin_user.rb', line 55 def self.all_roles(admin_session_key, conn = connection, opts={}) return do_request("/roles", conn, opts_work(opts, admin_session_key)) end |
.all_users(admin_session_key, conn = connection, opts = {}) ⇒ Object
returns all users if they are still logged in, and have permissions to see all users, user data only includes, id, name, last_login, roles, and current_logged_in_status
23 24 25 |
# File 'lib/eme/admin_user.rb', line 23 def self.all_users(admin_session_key, conn = connection, opts={}) return do_request("/users", conn, opts_work(opts, admin_session_key)) end |
.check_salts ⇒ Object
90 91 92 93 94 |
# File 'lib/eme/admin_user.rb', line 90 def self.check_salts if(self.settings[:salt].nil? || self.settings[:pepper].nil? || self.settings[:salt].length < 15 || self.settings[:pepper].length < 15) raise RuntimeError, "Requires settings salt and pepper, min length 15." end end |
.decode_admin_key_cookie(val, ip) ⇒ Object
SESSION COOKIES
80 81 82 83 |
# File 'lib/eme/admin_user.rb', line 80 def self.(val, ip) check_salts ((val.to_s.hex ^ self.settings[:pepper].hex) - self.settings[:salt].hex - ipaddress_factor(ip)).to_s(16) end |
.encode_admin_key_cookie(val, ip) ⇒ Object
85 86 87 88 |
# File 'lib/eme/admin_user.rb', line 85 def self.(val, ip) check_salts return ((self.settings[:salt].hex + val.to_s.hex + ipaddress_factor(ip)) ^ self.settings[:pepper].hex).to_s(16) end |
.heartbeat(admin_session_key, conn = connection, opts = {}) ⇒ Object
requires admin_session_key. Just returns true or false if you are still logged in or not. if still logged in: returns json true, “permissions_updated”: false Most likely to be used via AJAX on the front end.
43 44 45 |
# File 'lib/eme/admin_user.rb', line 43 def self.heartbeat(admin_session_key, conn = connection, opts={}) return do_request("/users/heartbeat", conn, opts_work(opts, admin_session_key)) end |
.ipaddress_factor(ip) ⇒ Object
96 97 98 |
# File 'lib/eme/admin_user.rb', line 96 def self.ipaddress_factor(ip) ip.gsub(/\./, "d").to_i(17) * 93 end |
.login(email, password, conn = connection, opts = {}) ⇒ Object
if successful username/password combo, it should return a unique 16 digit hex session id for the user.
{"admin_session_key": "432423h13h341ab2", "error": false}
if failed it should return error true, and error message.
{"error": true, "message": "Incorrect email/password combination."}
NOTE: This is the only call that does not require an admin_session_key in the headers/cookies, still requires the API_KEY.
10 11 12 13 14 |
# File 'lib/eme/admin_user.rb', line 10 def self.login(email, password, conn = connection, opts = {}) opts[:method] = :post opts[:body] = {:email => email, :password => password}.to_json return do_request("/users/login", conn, opts_work(opts)) end |
.logout(admin_session_key, conn = connection, opts = {}) ⇒ Object
a get or delete call. It only requires the first 8 digits of the admin_session_key, but will accept all 16 digits.
17 18 19 20 |
# File 'lib/eme/admin_user.rb', line 17 def self.logout(admin_session_key, conn = connection, opts = {}) opts[:method] = :delete return do_request("/users/logout", conn, opts_work(opts, admin_session_key)) end |
.me(admin_session_key, conn = connection, opts = {}) ⇒ Object
This is the call that returns the current user data, including permissions and roles, this will be converted to a Session object that will be used by the app to get your logged in status, and permissions, etc.
48 49 50 |
# File 'lib/eme/admin_user.rb', line 48 def self.me(admin_session_key, conn = connection, opts={}) tmp = do_request("/users/me", conn, opts_work(opts, admin_session_key)) end |
.role(role_id, admin_session_key, conn = connection, opts = {}) ⇒ Object
returns specific a role’s data; id, name, permissions, users with role.
60 61 62 |
# File 'lib/eme/admin_user.rb', line 60 def self.role(role_id, admin_session_key, conn = connection, opts={}) return do_request("/roles/#{role_id}", conn, opts_work(opts, admin_session_key)) end |
.update_role(role_data, admin_session_key, conn = connection, opts = {}) ⇒ Object
takes a hash of role info(name, and permissions), and posts it to the service to edit the role, if they have permissions.
65 66 67 68 69 |
# File 'lib/eme/admin_user.rb', line 65 def self.update_role(role_data, admin_session_key, conn = connection, opts={}) opts[:method] = :post opts[:body] = role_data.to_json return do_request("/roles/#{user_id}", conn, opts_work(opts, admin_session_key)) end |
.update_user(user_data, admin_session_key, conn = connection, opts = {}) ⇒ Object
takes a hash of user info, and posts it to the service to edit the user record, if they have permissions. if there is a password change it requires the fields password, and confirmed password.
34 35 36 37 38 |
# File 'lib/eme/admin_user.rb', line 34 def self.update_user(user_data, admin_session_key, conn = connection, opts={}) opts[:method] = :post opts[:body] = user_data.to_json return do_request("/users/#{user_id}", conn, opts_work(opts, admin_session_key)) end |
.user(user_id, admin_session_key, conn = connection, opts = {}) ⇒ Object
returns specific users data, DO NOT include session_key_id, or password/hashed_password. Requires permission check.
28 29 30 |
# File 'lib/eme/admin_user.rb', line 28 def self.user(user_id, admin_session_key, conn = connection, opts={}) return do_request("/users/#{user_id}", conn, opts_work(opts, admin_session_key)) end |