PHCNetworks/multi-tenancy-warden

View on GitHub
app/controllers/mtwarden/accounts_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
require_dependency "mtwarden/application_controller"

module Mtwarden
    class AccountsController < ApplicationController
        def new
            @account = Mtwarden::Account.new
            @account.build_owner
        end

        def create
            @account = Mtwarden::Account.create_with_owner(account_params)
            if @account.valid?
                force_authentication!(@account.owner)
                flash[:success] = "Your account has been successfully created."
                redirect_to mtwarden.root_url(:subdomain => @account.subdomain)
            else
                flash[:error] = "Sorry, your account could not be created."
                render :new
            end
        end

        private

        def account_params
            params.require(:account).permit(:name, :subdomain,
                { :owner_attributes => [
                    [:email, :password, :password_confirmation]
                ]}
            )
        end
    end
end