class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :auth, :update, :destroy] # GET /users def index @users = User.all end # GET /users/1 def show end # GET /users/new def new @user = User.new end # GET /users/1/auth def auth end # POST /users def create @user = User.new(user_params) if @user.save redirect_to @user, notice: 'User was successfully created.' else render :new end end # PATCH/PUT /users/1 def update @auth_user = @user.authenticate(user_params[:password]) unless user_params[:password].nil? if @auth_user.nil? render :auth, notice: 'Invalid authentication' else redirect_to @auth_user, notice: 'User successfully authenticated' end end # DELETE /users/1 def destroy @user.destroy redirect_to users_url, notice: 'User was successfully destroyed.' end private # Use callbacks to share common setup or constraints between actions. def set_user @user = User.find(params[:id]) end # Only allow a trusted parameter "white list" through. def user_params params.require(:user).permit(:name, :password) end end