Instantly share code, notes, and snippets.

View gist:3462bbf1b8f2bb5191ce660ccdfd25eb
require 'minitest/autorun'
require_relative 'raindrops'
class RaindropsTest < Minitest::Test
def test_the_sound_for_1_is_1
end
def test_the_sound_for_3_is_pling
end
View user.py
class User:
"""Basic User class"""
def __init__(self, name, email, password):
self.name = name
self.email = email
self.password = password
View index.html.eex
<div class="jumbotron">
<h2><%= gettext "Welcome %{name}", name: @current_user.name %></h2>
<p class="lead">A productive web framework that<br />does not compromise speed and maintainability.</p>
</div>
View page_controller_index.ex
def index(conn, _params) do
user = Guardian.Plug.current_resource(conn)
render conn, "index.html", current_user: user
end
View web_controllers_page_controller.ex
defmodule PhoenixUeberauthComeonin.PageController do
use PhoenixUeberauthComeonin.Web, :controller
plug Guardian.Plug.EnsureAuthenticated, handler: __MODULE__
def index(conn, _params) do
render conn, "index.html"
end
def unauthenticated(conn, _params) do
View sessions_controller.ex
defmodule PhoenixUeberauthComeonin.SessionsController do
use PhoenixUeberauthComeonin.Web, :controller
alias Ueberauth.Strategy.Helpers
plug Ueberauth
def new(conn, _params) do
render conn, "new.html", callback_url: Helpers.callback_url(conn), current_user: nil
end
View guardian_serializer.ex
defmodule GuardianSerializer do
@behaviour Guardian.Serializer
alias PhoenixUeberauthComeonin.Repo
def for_token(user = %User{}), do: { :ok, "User:#{user.id}" }
def for_token(_), do: { :error, "Unknown resource type" }
def from_token("User:" <> id), do: { :ok, Repo.get(User, id) }
def from_token(_), do: { :error, "Unknown resource type" }
View config_config.exs
config :guardian, Guardian,
allowed_algos: ["HS512"],
verify_module: Guardian.JWT,
issuer: "Metamorfo",
ttl: { 30, :days },
verify_issuer: true,
secret_key: <<188, 78, 156, 202, 219, 17, 166, 68, 84, 206, 109, 204, 103, 136, 108,
222>>,
serializer: GuardianSerializer
View mix.exs
def application do
[mod: {PhoenixUeberauthComeonin, []},
applications: [
...
:guardian,
:ueberauth,
:ueberauth_identity,
]
]
end
View mix.exs
defp deps do
[
...
{:guardian, "~> 0.13.0"}
]
end