Last active
July 11, 2018 10:06
-
-
Save Ninigi/b247846875d47c71dc81b122e59facb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule UselessWeb.ShopController do | |
use UselessWeb, :controller | |
alias Useless.ShopifyApp | |
alias Useless.ShopifyApp.Shop | |
def new(conn, _params) do | |
changeset = ShopifyApp.change_shop(%Shop{}) | |
render(conn, "new.html", changeset: changeset) | |
end | |
def signup(conn, %{"shop" => %{"shopify_domain" => shop_name}}) when shop_name != "" and not is_nil(shop_name) do | |
params = %{scope: "read_orders,read_products", redirect_uri: "http://localhost:4000/auth"} | |
permission_url = shop_name |> Shopify.session() |> Shopify.OAuth.permission_url(params) | |
conn | |
|> redirect(external: permission_url) | |
end | |
def signup(conn, _) do | |
{:error, changeset} = ShopifyApp.create_shop(%{}) | |
render(conn, "new.html", changeset: changeset) | |
end | |
# def index(conn, _params) do | |
# shops = ShopifyApp.list_shops() | |
# render(conn, "index.html", shops: shops) | |
# end | |
# def show(conn, %{"id" => id}) do | |
# shop = ShopifyApp.get_shop!(id) | |
# render(conn, "show.html", shop: shop) | |
# end | |
# | |
# def edit(conn, %{"id" => id}) do | |
# shop = ShopifyApp.get_shop!(id) | |
# changeset = ShopifyApp.change_shop(shop) | |
# render(conn, "edit.html", shop: shop, changeset: changeset) | |
# end | |
# | |
# def update(conn, %{"id" => id, "shop" => shop_params}) do | |
# shop = ShopifyApp.get_shop!(id) | |
# | |
# case ShopifyApp.update_shop(shop, shop_params) do | |
# {:ok, shop} -> | |
# conn | |
# |> put_flash(:info, "Shop updated successfully.") | |
# |> redirect(to: shop_path(conn, :show, shop)) | |
# {:error, %Ecto.Changeset{} = changeset} -> | |
# render(conn, "edit.html", shop: shop, changeset: changeset) | |
# end | |
# end | |
# | |
# def delete(conn, %{"id" => id}) do | |
# shop = ShopifyApp.get_shop!(id) | |
# {:ok, _shop} = ShopifyApp.delete_shop(shop) | |
# | |
# conn | |
# |> put_flash(:info, "Shop deleted successfully.") | |
# |> redirect(to: shop_path(conn, :index)) | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment