Module: DeviceTracker::ApplicationHelper
- Defined in:
- lib/device_tracker/helpers/application_helper.rb
Constant Summary collapse
- SECRET =
'mYR4nd0mAr$eS3cr3t/fuGg1wugGl3'
Instance Method Summary collapse
- #change_password?(params) ⇒ Boolean
- #create_flash(type, message) ⇒ Object
- #generate_activation_code(size = 6) ⇒ Object
- #get_logged_in_user ⇒ Object
- #is_admin? ⇒ Boolean
- #perform_admin_check ⇒ Object
- #protected! ⇒ Object
- #report_transaction(message, type, device = nil) ⇒ Object
- #valid_heartbeat?(data) ⇒ Boolean
- #value_for(name, object) ⇒ Object
Instance Method Details
#change_password?(params) ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 29 def change_password?(params) if params[:user][:password].empty? or params[:user][:password_confirmation].empty? false else true end end |
#create_flash(type, message) ⇒ Object
69 70 71 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 69 def create_flash(type, ) flash[:message] = {css_class: type, message: } end |
#generate_activation_code(size = 6) ⇒ Object
24 25 26 27 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 24 def generate_activation_code(size = 6) charset = %w{0 1 2 3 4 6 7 8 9 A C D E F G H J K M N P Q R T V W X Y Z} (0...size).map{ charset.to_a[rand(charset.size)] }.join end |
#get_logged_in_user ⇒ Object
20 21 22 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 20 def get_logged_in_user session[:user] unless session[:user].nil? end |
#is_admin? ⇒ Boolean
6 7 8 9 10 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 6 def is_admin? user = get_logged_in_user return if user.nil? user[:is_admin] end |
#perform_admin_check ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 61 def perform_admin_check user = get_logged_in_user if user.nil? or user[:is_admin] == false create_flash "warning", ["#{user[:name]} does not have permissions to access this page."] redirect back end end |
#protected! ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 37 def protected! if session[:user].nil? create_flash "info", ["You must be logged in to see this page."] redirect "/login" elsif !session[:user][:is_verified] create_flash "info", ["You account is awaiting verification by an admin."] redirect "/login" end end |
#report_transaction(message, type, device = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 47 def report_transaction(, type, device = nil) transaction = Transaction.new if session[:user] transaction.user_id = get_logged_in_user[:id] end transaction.description = transaction.transaction_type = type transaction.device_id = device.id unless device.nil? transaction.save! end |
#valid_heartbeat?(data) ⇒ Boolean
73 74 75 76 77 78 79 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 73 def valid_heartbeat?(data) if !data["heartbeat"].nil? and !data["heartbeat"]["longitude"].nil? and !data["heartbeat"]["latitude"].nil? and !data["heartbeat"]["device_id"].nil? return true end false end |
#value_for(name, object) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/device_tracker/helpers/application_helper.rb', line 12 def value_for(name, object) if flash[name] flash[name] elsif object object.send name end end |