Sha256: c12f167aa11d57ea1ecedb556b8885fe9ed1adaeb10de4de37565594effc8720

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

class InvitationsController < ApplicationController
  before_filter :authorize_admin, :except => [:show, :update]
  skip_before_filter :authenticate, :only => [:show, :update]
  layout Saucy::Layouts.to_proc

  def new
    assign_projects
    @invitation = Invitation.new
    render
  end

  def create
    @invitation = Invitation.new(params[:invitation])
    @invitation.account = current_account
    @invitation.sender  = current_user
    if @invitation.save
      flash[:success] = "User invited."
      redirect_to account_memberships_url(current_account)
    else
      assign_projects
      render :action => 'new'
    end
  end

  def show
    with_invitation { render }
  end

  def update
    with_invitation do
      if @invitation.accept(params[:invitation])
        sign_in @invitation.user
        redirect_to root_url
      else
        render :action => 'show'
      end
    end
  end

  private

  def assign_projects
    @projects = current_account.projects_by_name
  end

  def with_invitation
    @invitation = Invitation.find_by_code!(params[:id])
    if @invitation.used?
      flash[:error] = t("invitations.show.used",
                        :default => "That invitation has already been used.")
      redirect_to root_url
    else
      yield
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
saucy-0.3.1 app/controllers/invitations_controller.rb
saucy-0.3.0 app/controllers/invitations_controller.rb
saucy-0.2.45 app/controllers/invitations_controller.rb
saucy-0.2.44 app/controllers/invitations_controller.rb
saucy-0.2.43 app/controllers/invitations_controller.rb
saucy-0.2.42 app/controllers/invitations_controller.rb
saucy-0.2.41 app/controllers/invitations_controller.rb
saucy-0.2.40 app/controllers/invitations_controller.rb