             ip: Enum.join(Tuple.to_list(conn.remote_ip), "."),
             test: "lalalal"
         }
+        up = Repo.get_by(UserProperties, user_id: user.id)
+        Logger.debug("LOGIN #{user.id} #{inspect up}")
+
         session_changeset = Session.create_changeset(%Session{}, %{user_id: user.id, data: sdata})
         {:ok, session} = Repo.insert(session_changeset)
-        new_conn = Guardian.Plug.sign_in(conn, user, :token, perms: %{admin: [:dashboard]})
-        #new_conn = Guardian.Plug.sign_in(conn, user)
+        
+        new_conn = cond do
+            up && check_perm(up, "admin", "dashboard") ->
+                Guardian.Plug.sign_in(conn, user, :token, perms: %{admin: [:dashboard]})
+            up   -> Guardian.Plug.sign_in(conn, user)
+            true -> Guardian.Plug.sign_in(conn, user)
+        end
+
         jwt    = Guardian.Plug.current_token(new_conn)
         {:ok, claims} = Guardian.Plug.claims(new_conn)
         exp = Map.get(claims, "exp")

        |> render("index.html")
  end

end



  alias Elapi.User
  alias Elapi.Session
  alias Elapi.UserProperties

  def index(conn, _params, _current_user, _claims) do
    render conn, "index.html"
