- Full auth system with email/password (using phx.gen.auth) - Login, registration, password reset - Session management with remember-me functionality - Magic link login support 2. Organization Management - Multi-tenant organization system - Organizations schema with unique slugs - Automatic organization creation when users register - Organization switcher UI at /orgs 3. Membership System - Users can belong to multiple organizations - 4 permission levels: Owner, Admin, Member, Viewer - Complete permission matrix implemented - Join/leave organizations 4. Invitation System - Email-based invitations with secure tokens - 7-day expiration on invites - Track who invited and who accepted 5. Authorization - Full policy system (Organizations.Policy) - can?(membership, :action, :resource) helper - Enforced via plugs in router 6. LiveView Pages - /orgs - List all your organizations - /orgs/new - Create new organization - /orgs/:slug - Organization dashboard (placeholder) 7. Database Schema - users table - organizations table - organization_memberships table - organization_invitations table - All migrations run successfully
43 lines
1.2 KiB
Elixir
43 lines
1.2 KiB
Elixir
defmodule ToweropsWeb.OrgLive.New do
|
|
@moduledoc false
|
|
use ToweropsWeb, :live_view
|
|
|
|
alias Towerops.Organizations
|
|
alias Towerops.Organizations.Organization
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
changeset = Organizations.change_organization(%Organization{})
|
|
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "New Organization")
|
|
|> assign(:form, to_form(changeset))}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("validate", %{"organization" => org_params}, socket) do
|
|
changeset =
|
|
%Organization{}
|
|
|> Organizations.change_organization(org_params)
|
|
|> Map.put(:action, :validate)
|
|
|
|
{:noreply, assign(socket, :form, to_form(changeset))}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("save", %{"organization" => org_params}, socket) do
|
|
user = socket.assigns.current_scope.user
|
|
|
|
case Organizations.create_organization(org_params, user.id) do
|
|
{:ok, organization} ->
|
|
{:noreply,
|
|
socket
|
|
|> put_flash(:info, "Organization created successfully")
|
|
|> push_navigate(to: ~p"/orgs/#{organization.slug}")}
|
|
|
|
{:error, %Ecto.Changeset{} = changeset} ->
|
|
{:noreply, assign(socket, :form, to_form(changeset))}
|
|
end
|
|
end
|
|
end
|