Sha256: ea356f5e43dedc1dd99960a866ffd9ca3abdb942807af70186dd5e2188248326

Contents?: true

Size: 1.52 KB

Versions: 40

Compression:

Stored size: 1.52 KB

Contents

require 'shelly/organization'

module Shelly
  class User < Model
    def apps
      shelly.apps.map do |attributes|
        Shelly::App.from_attributes(attributes)
      end
    end

    def organizations
      shelly.organizations.map do |attributes|
        Shelly::Organization.new(attributes)
      end
    end

    def email
      shelly.user_email
    end

    def register(email, password)
      shelly.register_user(email, password)
    end

    def authorize!
      if credentials_exists?
        email, password = File.read(credentials_path).split("\n")
        shelly.authorize_with_email_and_password(email, password)
        delete_credentials
      else
        shelly.authorize!
      end
    end

    def login(email, password)
      delete_credentials # clean up previous auth storage

      shelly.authorize_with_email_and_password(email, password)
    end

    def logout
      delete_credentials # clean up previous auth storage
      shelly.forget_authorization
    end

    def ssh_keys
      @keys ||= SshKeys.new
    end

    def ssh_key
      ssh_keys.prefered_key
    end

    def delete_credentials
      File.delete(credentials_path) if credentials_exists?
    end

    def self.guess_email
      @@guess_email ||= IO.popen("git config --get user.email").read.strip
    end

    def config_dir
      File.expand_path("~/.shelly")
    end

    protected
      def credentials_path
        File.join(config_dir, "credentials")
      end

      def credentials_exists?
        File.exists?(credentials_path)
      end
    end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
shelly-0.5.7 lib/shelly/user.rb
shelly-0.5.6 lib/shelly/user.rb
shelly-0.5.5 lib/shelly/user.rb
shelly-0.5.4 lib/shelly/user.rb
shelly-0.5.3 lib/shelly/user.rb
shelly-0.5.2 lib/shelly/user.rb
shelly-0.5.1 lib/shelly/user.rb
shelly-0.5.0 lib/shelly/user.rb
shelly-0.4.42 lib/shelly/user.rb
shelly-0.4.41 lib/shelly/user.rb
shelly-0.4.40 lib/shelly/user.rb
shelly-0.4.39 lib/shelly/user.rb
shelly-0.4.38 lib/shelly/user.rb
shelly-0.4.37 lib/shelly/user.rb
shelly-0.4.36 lib/shelly/user.rb
shelly-0.4.35 lib/shelly/user.rb
shelly-0.4.34 lib/shelly/user.rb
shelly-0.4.33 lib/shelly/user.rb
shelly-0.4.32 lib/shelly/user.rb
shelly-0.4.31 lib/shelly/user.rb