ftp-manager/app/controllers/accounts_controller.rb

57 lines
1.1 KiB
Ruby
Raw Permalink 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
2016-09-28 22:39:42 -05:00
@account = Account.new(password: SecureRandom.urlsafe_base64(12))
2016-08-27 21:40:21 -05:00
end
def edit
end
def reveal
render json: { hash: @account.password }.to_json
end
2016-09-28 22:39:42 -05:00
def genpass
render json: { hash: SecureRandom.urlsafe_base64(12) }.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