Module: Platformx::AuthHelpers
- Defined in:
- lib/platformx/auth.rb
Instance Method Summary collapse
-
#x_admin_authorize! ⇒ Object
Authorizes the current user as an admin or redirects the user to the admin login page.
-
#x_admin_authorized? ⇒ Boolean
Checks if the current user authorizes as an admin.
-
#x_admin_logout! ⇒ Object
Logs out the amdin.
-
#x_authorize! ⇒ Object
Authorizes the user and redirects the user to the registration page.
-
#x_authorized? ⇒ Boolean
Checks if the user is logged in.
-
#x_decrypt(str = "") ⇒ String
Decodes an encoded string.
-
#x_encrypt(int = "") ⇒ String
Encodes a value to a base 64 string.
-
#x_generate_password(len = "10") ⇒ String
Generate a random password.
-
#x_logout! ⇒ Object
Logs out the currenly logged in user.
Instance Method Details
#x_admin_authorize! ⇒ Object
Authorizes the current user as an admin or redirects the user to the admin login page.
14 15 16 |
# File 'lib/platformx/auth.rb', line 14 def redirect '/admin/login' unless || request.url.include?("/admin/login") end |
#x_admin_authorized? ⇒ Boolean
Checks if the current user authorizes as an admin
9 10 11 |
# File 'lib/platformx/auth.rb', line 9 def session[:admin_authorized] end |
#x_admin_logout! ⇒ Object
Logs out the amdin
19 20 21 22 |
# File 'lib/platformx/auth.rb', line 19 def x_admin_logout! session[:admin_authorized] = false session.clear end |
#x_authorize! ⇒ Object
Authorizes the user and redirects the user to the registration page.
34 35 36 |
# File 'lib/platformx/auth.rb', line 34 def redirect '/login' unless || request.url.include?("/login") || request.url.include?("/auth") end |
#x_authorized? ⇒ Boolean
Checks if the user is logged in
29 30 31 |
# File 'lib/platformx/auth.rb', line 29 def session[:authorized] end |
#x_decrypt(str = "") ⇒ String
Decodes an encoded string
64 65 66 67 68 |
# File 'lib/platformx/auth.rb', line 64 def x_decrypt(str = "") str = Base64.urlsafe_decode64(str) #decrypted_value = Encryptor.decrypt(:value => str, :key => '=PeuMX7B4LQ#@jG*s;tYGdF') return str.to_i end |
#x_encrypt(int = "") ⇒ String
The provided object should respond to ‘#to_s` to obtain a string representation of the object.
Encodes a value to a base 64 string.
53 54 55 56 57 |
# File 'lib/platformx/auth.rb', line 53 def x_encrypt(int = "") str = int.to_s #encrypted_value = Encryptor.encrypt(:value => str, :key => "=PeuMX7B4LQ#@jG*s;tYGdF") return Base64.urlsafe_encode64(str) end |
#x_generate_password(len = "10") ⇒ String
Generate a random password
75 76 77 78 |
# File 'lib/platformx/auth.rb', line 75 def x_generate_password(len = "10") random_password = Array.new(len).map { (65 + rand(58)).chr }.join return random_password end |
#x_logout! ⇒ Object
Logs out the currenly logged in user
39 40 41 42 |
# File 'lib/platformx/auth.rb', line 39 def x_logout! session[:authorized] = false session.clear end |