Sha256: 0049e31d13bafa8e5717f072f1e3b82450a65b1ea16fbeb7cbd4dd4801ebbd8a

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

class SparklyAccountsController < SparklyController
  unloadable
  require_login_for :show, :edit, :update, :destroy

  # GET new_model_url
  def new
  end

  # POST model_url
  def create
    if model.save
      login!(model)
      redirect_back_or_default Auth.default_destination, Auth.account_created_message
    else
      render :action => 'new'
    end
  end

  # GET model_url
  def show
  end

  # GET edit_model_url
  def edit
  end

  # PUT model_url
  def update
    if !model_params[:password].blank? || !model_params[:password_confirmation].blank?
      model.password = model_params[:password]
      model.password_confirmation = model_params[:password_confirmation]
    end
    
    if model.save
      redirect_back_or_default user_path, Auth.account_updated_message
    else
      render :action => 'edit'
    end
  end

  # DELETE model_url
  def destroy
    current_user && current_user.destroy
    logout!
    @current_user = nil
    flash[:notice] = Auth.account_deleted_message
    redirect_back_or_default Auth.default_destination
  end

  protected
    def find_user_model
      # password fields are protected attrs, so we need to exclude them then add them explicitly.
      self.model_instance = current_user ||
              returning(model_class.new(model_params.without(:password, :password_confirmation))) { |model|
                model.password = model_params[:password]
                model.password_confirmation = model_params[:password_confirmation]
              }
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sparkly-auth-1.0.2 app/controllers/sparkly_accounts_controller.rb
sparkly-auth-1.0.1 app/controllers/sparkly_accounts_controller.rb
sparkly-auth-1.0.0 app/controllers/sparkly_accounts_controller.rb