Sha256: 5bbb282a9df6bada73baadec415eef509809b3b3a7af17d326826d0dc7983b3b

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

# Basic Marty single-page application with authentication.
#
# == Extending Marty::AuthApp
# DOCFIX
class Marty::AuthApp < Marty::SimpleApp
  js_configure do |c|
    c.mixin
  end

  # Set the Logout button if current_user is set
  def menu
    [].tap do |menu|
      user = Mcfly.whodunnit
      if !user.nil?
        menu << "->" << {
          text: user.name,
          tooltip: 'Current user',
          menu: user_menu,
          name: "sign_out",
        }
      else
        menu << "->" << :sign_in
      end
    end
  end

  def user_menu
    [:sign_out]
  end

  action :sign_in do |c|
    c.icon = :door_in
  end

  action :sign_out do |c|
    c.icon = :door_out
    c.text = "Sign out #{Mcfly.whodunnit.name}" if Mcfly.whodunnit
  end

  endpoint :sign_in do |params,this|
    user = Marty::User.try_to_login(params[:login], params[:password])

    if user
      Netzke::Base.controller.set_user(user)
      this.netzke_set_result(true)
    else
      this.netzke_set_result(false)
      this.netzke_feedback("Wrong credentials")
    end
  end

  endpoint :sign_out do |params,this|
    Netzke::Base.controller.logout_user
    this.netzke_set_result(true)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
marty-0.5.41 app/components/marty/auth_app.rb
marty-0.5.40 app/components/marty/auth_app.rb
marty-0.5.39 app/components/marty/auth_app.rb
marty-0.5.38 app/components/marty/auth_app.rb
marty-0.5.36 app/components/marty/auth_app.rb
marty-0.5.35 app/components/marty/auth_app.rb
marty-0.5.34 app/components/marty/auth_app.rb
marty-0.5.33 app/components/marty/auth_app.rb