Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (46 sloc) 1.14 KB
class UsersController < ApplicationController
before_action :set_user, only: [ :edit, :update, :destroy, :confirmation]
before_action :check_expiration, only: :show
def show
@user = User.find_by_token(params[:id])
@delete_time = delete_time(@user)
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
session[:id] = @user.id
redirect_to new_upload_path
else
render 'new'
end
end
def destroy
@user.destroy
end
def confirmation
@uploads = @user.uploads.all
end
private
include ActionView::Helpers::DateHelper
def check_expiration
@user = User.find_by_token(params[:id])
if delete_time(@user).to_i == 0
flash[:expired] = "Files you're trying to access have expired."
@user.destroy
redirect_to root_url
end
end
def delete_time(user)
time = user.expiration
distance_of_time_in_words(Time.now, time)
end
def set_user
@user ||= User.find(params[:id])
end
def user_params
params.require(:user).permit(:name, :email, :recipient_email, :recipient_name, :message, :token, :expiration)
end
end