defmodule PlugParadoxAuth.GoogleAuthCheck do
import Plug.Conn
def init(options) do
# initialize options
options
end
def call(conn, _opts) do
IO.puts "conn in checkgoogauth"
IO.inspect conn
cond do
get_session(conn, :google_user) -> conn
conn.request_path == "/auth/google/callback" -> conn
true -> handle_redirect(conn)
end
end
def handle_redirect(conn) do
put_session(conn, :google_auth_success_url, conn.request_path)
conn
|> put_resp_header("location", ElixirAuthGoogle.generate_oauth_url(conn))
|> send_resp(302, "text/html")
end
end