Skip to content
Snippets Groups Projects
Forked from PortalMEC / portalmec
2886 commits behind the upstream repository.
users_controller.rb 1.35 KiB
class UsersController < ApplicationController
  before_action :authenticate_user!, only: :me
  before_action :check_current_user_page, only: :show
  before_action :set_user, only: :show
  before_action :set_empty_collection, only: [:show, :me]

  def show
    @objects = @user.learning_objects
    @groups = [
        CollectionsGroup.new(title: 'Coleções Automáticas',
                             collections: [
                                 @new_collection
                             ]),
        CollectionsGroup.new(title: 'Coleções Adicionadas',
                             collections: [
                                 @user.collections
                             ])
    ]
  end

  def me
    asd
    @objects = current_user.learning_objects
    @bookmarks = current_user.bookmarks
    @groups = [
        CollectionsGroup.new(title: 'Coleções Automáticas',
                             collections: [@bookmarks]),
        CollectionsGroup.new(title: 'Coleções Adicionadas',
                             collections: current_user.collections)
    ]
  end


  private

  def set_empty_collection
    @new_collection = Collection.new
  end

  def set_user
    @user = user_repository.find params[:id]
  end

  def check_current_user_page
    if user_signed_in?
      if current_user.id == params[:id]
        redirect_to action: :me
      end
    end
  end

end