<commit_before>class UsersController < ApplicationController
skip_before_filter :check_session, :only => [:new, :create]

  # users#show notes
  # routing info: HTTP GET to => /users/:id

  # A show action displays info for a single object, in this case a single user.
  # Each link to a user passes an id param to the server when it is clicked
  # (params[:id] evaluates to the value of this parameter).
  # The top line finds the user with an id that matches the id from params and saves it to an instance variable @owner.
  # Remember that all instance variables (ones with an @ in front of them) will be available in the view that gets rendered.
  # We then find all the messages that belong to @owner and save them in an instance variable @messages
  # Finally we make an empty message and save it in an instance variable. This is needed for the new message form displayed on this page.
  # After this, the default template will be rendered (users/show.html.erb)

  def show
    #<<< create an instance variable called owner and set it equal to the user whose id matches params[:id] >>>
    #<<< create an instance variable called messages and set it equal to all of owners messages >>>
    #<<< create an instance variable called new_message and set it equal to a new message >>>
  end

  # users#create notes
  # routing info: HTTP POST to => /users/

  # This action recieves the data from the new user form and creates a user based off of it.
  # There is no view for it, it either redirects to the new users profile if it succeeds or back to the new user form if it fails.
  # it handles two cases. If the user is successfully created it sets the current user and redirects to the show page for that user. If it fails it sends you back to the
  # home page with and returns the same user back to the form along with its validation errors so the user can try to create a new user again.
  def create
    @user = User.new(user_params)
    if @user.save
      cookies.signed[:current_user_id] = @user.id
      redirect_to @user
    else
      @users = User.all
      @new_user = @user
      @errors = @user.errors
      @messages = Message.all
      render :new
    end
  end

  # users#new notes
  # routing info: HTTP GET to => /users/new

  # this page simply renders a form to create a new user.
  # Once the form is submitted it will be handled by the user#create action
  # The new user is necessary for the form. Note the new instead of create so this isn't saved to the database here.

  #<<<  define a new method called new. Make sure to put an "end" below it>>>
  #<<<  Inside your new method create an instance variable @new_user and set it equal to a new user >>>
  private
  # Never trust parameters from the scary internet, only allow the white list through.
  # This method is called when creating a new user. It prevents people from using our form to submit malicious content.
  def user_params
    params.require(:user).permit(:name, :email, :current_user_id)
  end

end<commit_msg>improves comments on user controller<commit_after>class UsersController < ApplicationController
skip_before_filter :check_session, :only => [:new, :create]

# ==============================================================
# show users method
# routing info: HTTP GET to => /users/:id
# ==============================================================
  def show
    #<<< create an instance variable called owner and set it equal to the user whose id matches params[:id] >>>
    #<<< create an instance variable called messages and set it equal to all of @owner's messages >>>
    #<<< create an instance variable called new_message and set it equal to a new instance of the message class>>>
  end


  # EXPLANATION
  # ==================
  # A show action displays info for a single object, in this case a single user.

  # Assume we have an imaginary user saved to the instance variable @user
  # In our views we can create a link to this user with: "link_to(@user.name), user_path(@user)"

  # When a user clicks this link the application will end up in this method (the def show code above)
  # this link will pass extra information to the server which are called parameters

  # we can get the values of these parameters with the variable "params"
  # for example: "params[:id]"  will equal the value of the @users id

  # Also remember that all instance variables (ones with an @ in front of them) will be available in the view that gets rendered.

  # HINTS
  #=================
  # For the first line call the find method on users and pass it the id from the params hash. refer above to see how the params hash works
  # Any model that inherits from ActiveRecord::Base has some methods that help you find, create, update and destroy them. They are

  #Model.new
  #Model.create
  #Model.update
  #Model.destroy
  #Model.save
  #Model.find(:id)
  #Model.where(attribute: value)


# ==============================================================
# Create user method
# routing info: HTTP POST to => /users/
# ==============================================================
  def create
    @user = User.new(user_params)
    if @user.save
      cookies.signed[:current_user_id] = @user.id
      redirect_to @user
    else
      @users = User.all
      @new_user = @user
      @errors = @user.errors
      @messages = Message.all
      render :new
    end
  end

  # This action recieves the data from the new user form and creates a user based off of it.

  # There is no view for it, it either redirects to the new users profile if it succeeds or back to the new user form if it fails.ew

  # It handles two cases. If the user is successfully created it sets the current user and redirects to the show page for that user. If it fails it sends you back to the
  # home page with and returns the same user back to the form along with its validation errors so the user can try to create a new user again.

# ==============================================================
# New User method
# routing info: HTTP GET to => /users/new
# ==============================================================

  #<<<  define a method with the name new. Make sure to put an "end" below it>>>
  #<<<  Inside your "new" method create an instance variable @new_user and set it equal to a new user >>>

  # this method renders a form to create a new user.
  # Once the form is submitted it will be handled by the user#create action.
  # Inside that action, all the things entered into the form will be available in the params hash

  # The new user is necessary for the form. Note the new instead of create so this isn't saved to the database here.
  # refer to the methods listed in the show method's notes for how to make an ew user
# ==============================================================
# ==============================================================

  private
  # This method is called when creating a new user. It prevents people from using our form to submit malicious content.
  def user_params
    params.require(:user).permit(:name, :email, :current_user_id)
  end

end
{'fraction_non_alphanumeric': 0.1321181291507701, 'fraction_numerical': 0.0, 'mean_word_length': 3.6874172185430463, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '802221', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1751, 'n_words': 998}