ftp-manager/app/controllers/accounts_controller.rb
2016-09-28 22:39:42 -05:00

57 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class AccountsController < ApplicationController
before_action :set_account, only: [:show, :edit, :reveal, :update, :destroy]
def index
@accounts = Account.all
end
def show
end
def new
@account = Account.new(password: SecureRandom.urlsafe_base64(12))
end
def edit
end
def reveal
render json: { hash: @account.password }.to_json
end
def genpass
render json: { hash: SecureRandom.urlsafe_base64(12) }.to_json
end
def create
@account = Account.new(account_params)
if @account.save
redirect_to @account, notice: 'Account was successfully created.'
else
flash[:error] = 'Failed to create account'
render :new
end
end
def update
if @account.update(account_params)
redirect_to @account, notice: 'Account was successfully updated.'
else
flash[:error] = 'Failed to update account'
render :edit
end
end
private
def set_account
@account = Account.find(params[:id])
end
def account_params
params.require(:account).permit(:username, :password, :home_folder, :contact_email)
end
end