ftp-manager/app/controllers/accounts_controller.rb

53 lines
1.0 KiB
Ruby
Raw Normal View History

2016-09-18 09:41:51 -05:00
# frozen_string_literal: true
2016-08-27 21:40:21 -05:00
class AccountsController < ApplicationController
before_action :set_account, only: [:show, :edit, :reveal, :update, :destroy]
2016-08-27 21:40:21 -05:00
def index
@accounts = Account.all
end
def show
end
def new
@account = Account.new
end
def edit
end
def reveal
render json: { hash: @account.password }.to_json
end
2016-08-27 21:40:21 -05:00
def create
@account = Account.new(account_params)
2016-09-18 11:16:35 -05:00
if @account.save
redirect_to @account, notice: 'Account was successfully created.'
else
flash[:error] = 'Failed to create account'
render :new
2016-08-27 21:40:21 -05:00
end
end
def update
2016-09-18 11:16:35 -05:00
if @account.update(account_params)
redirect_to @account, notice: 'Account was successfully updated.'
else
flash[:error] = 'Failed to update account'
render :edit
2016-08-27 21:40:21 -05:00
end
end
private
def set_account
@account = Account.find(params[:id])
end
def account_params
2016-09-28 22:12:55 -05:00
params.require(:account).permit(:username, :password, :home_folder, :contact_email)
2016-08-27 21:40:21 -05:00
end
end