<commit_before>class UsersController < ApplicationController

	# New user alloc
	def new
		if !logged_in?
	 		@user = User.new 
		else
			redirect_to home_path
		end
	end
	
	# Showing user data
	def show
		@user = User.find(params[:id])
		if @user != current_user
			redirect_to home_path
		end		
	end
	
	# Creating new user
	def create
	 	@user = User.new(user_params)


		if @user.save
			# when user create his account he is already log in
			session[:user_id] = @user.id
			flash[:notice] = 'Cadastro efetuado com sucesso!'
			log_in @user
			redirect_to home_path
		else
			render :new
		end

	end

	# Searcing user to edit
	def edit
		@user = User.find(params[:id])
		if @user != current_user
			redirect_to home_path
		end			
	end

	def user_params
		params[:user].permit(:name, :email, :password, :password_confirmation,:login, :dateBirthday, :gender, :uf_id, :company_id)
	end
	
	def user_params_update
		params[:user].permit(:name, :dateBirthday, :gender)
	end

	def password_params
		params[:user].permit(:password, :password_confirmation)
	end

	# Deleting user 
	def destroy
		session[:user_id] = nil
 		user = User.find(params[:id])
 		user.topics.delete_all
 		user.attaches.delete_all
 		user.evaluations.delete_all
 		user.destroy
	
		redirect_to home_path

	end

	# Updating user 
	def update
    	@user = User.find(params[:id])
    	if @user.update_attributes(user_params_update)
    		respond_to do |format| format.html {redirect_to :action => "show",:id => @user.id}
	    		flash[:notice] = "Perfil atualizado"
	    		format.js # views/users/update.js.erb

	    	end	
    	else
      		flash[:notice] = 'Erro ao atualizar o dado!'
    	end
    	
  	end

  	def user_admin?
		!@user.admin == true
	end

  	def update_password
  		@user = User.find(params[:id])
  		if  @user.authenticate(params[:user][:password_older])
  			if @user.update_attributes(password_params)
  				flash[:notice] = 'Senha atualizada com sucesso!'
  			else
  				flash[:notice] = 'Senha de confirmação invalida!'
  			end
  		else
  			flash[:notice] = 'Senha invalida!'
  		end
  		redirect_to :action => "show",:id => @user.id
  	end
end<commit_msg>Add and Fix methods to destroy user<commit_after>class UsersController < ApplicationController

	# New user alloc
	def new
		if !logged_in?
	 		@user = User.new 
		else
			redirect_to home_path
		end
	end
	
	# Showing user data
	def show
		@user = User.find(params[:id])
		if @user != current_user
			redirect_to home_path
		end		
	end
	
	# Creating new user
	def create
	 	@user = User.new(user_params)


		if @user.save
			# when user create his account he is already log in
			session[:user_id] = @user.id
			flash[:notice] = 'Cadastro efetuado com sucesso!'
			log_in @user
			redirect_to home_path
		else
			render :new
		end

	end

	# Searcing user to edit
	def edit
		@user = User.find(params[:id])
		if @user != current_user
			redirect_to home_path
		end			
	end

	def user_params
		params[:user].permit(:name, :email, :password, :password_confirmation,:login, :dateBirthday, :gender, :uf_id, :company_id)
	end
	
	def user_params_update
		params[:user].permit(:name, :dateBirthday, :gender)
	end

	def password_params
		params[:user].permit(:password, :password_confirmation)
	end

	# Deleting user 
	def destroy
		session[:user_id] = nil
 		user = User.find(params[:id])
 		user.attaches.delete_all
 		update_company_user(user.companies)
 		user.companies.delete_all
 		user.topics.delete_all
 		user.attaches.delete_all
 		user.evaluations.delete_all
 		user.destroy
	
		redirect_to home_path
	end

	# Updating user 
	def update
    	@user = User.find(params[:id])
    	if @user.update_attributes(user_params_update)
    		respond_to do |format| format.html {redirect_to :action => "show",:id => @user.id}
	    		flash[:notice] = "Perfil atualizado"
	    		format.js # views/users/update.js.erb

	    	end	
    	else
      		flash[:notice] = 'Erro ao atualizar o dado!'
    	end
    	
  	end

  	def user_admin?
		!@user.admin == true
	end

  	def update_password
  		@user = User.find(params[:id])
  		if  @user.authenticate(params[:user][:password_older])
  			if @user.update_attributes(password_params)
  				flash[:notice] = 'Senha atualizada com sucesso!'
  			else
  				flash[:notice] = 'Senha de confirmação invalida!'
  			end
  		else
  			flash[:notice] = 'Senha invalida!'
  		end
  		redirect_to :action => "show",:id => @user.id
  	end

  	def update_company_user(companies)
  		companies.each do |c|
  			c.update_attributes(:authenticated => false)
  		end	
  	end
end
{'fraction_non_alphanumeric': 0.10431338028169014, 'fraction_numerical': 0.0, 'mean_word_length': 3.223977695167286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '4919962', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1666, 'n_words': 387}