Giter Site home page Giter Site logo

Comments (10)

danschultzer avatar danschultzer commented on May 3, 2024

It's not possible without custom templates currently, but maybe it could be possible if a conditional check is made on the registration link: https://github.com/danschultzer/pow/blob/80e1dc03725552a319e81e8448cd84566d9786ec/lib/pow/phoenix/templates/session_template.ex#L15

I think your approach is great, I really like the idea of disabling registration by just removing the registration paths 😄 Let me give it some thoughts to figure out how this could work well.

from pow.

mrcasals avatar mrcasals commented on May 3, 2024

Maybe we could add it as a configuration option? Then when defining the pow_routes() macro we could check the configuration and add the registration paths if needed. Then add a view helper to check that, and use it on the link you posted.

I also disabled the registration#edit route because I don't need it and wanted to use a different layout for sign in and profile edition pages, and couldn't find a way to achieve it (but I might be missing something, I'm quite new to Elixir/Phoenix)

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

I prefer to have less configuration options if possible, and in this case, checking if the registration paths exists would work well. It could also be options passed to pow_routes/0, like pow_routes(registration: false), but I think it's clearer when the routes are written explicitly. How you wrote it feels like the best approach for me. The only thing holding me back with the PR is how to keep the EEx template super simple, but I'm working on it.

I assume you'll use a custom controller for profile edit?

I handle different layout for authenticated and non authenticated pages with an app that's running in production this way:

# app.html.eex
<html>
  <body>
    <%= render_sub_template(@conn, @view_module, @view_template, assigns) %>
  </body>
</html>

# layout_view.ex
defmodule MyAppWeb.LayoutView do
  use MyAppWeb, :view

  @spec render_subtemplate(Conn.t(), atom(), binary(), map()) :: Phoenix.HTML.safe()
  def render_subtemplate(conn, view_module, view_template, assigns) do
    case unauthenticated?(conn) do
      true ->
        render(view_module, view_template, Map.put(assigns, :layout, {MyAppWeb.LayoutView, "_unauthenticated.html"}))

      false ->
        render(view_module, view_template, Map.put(assigns, :layout, {MyAppWeb.LayoutView, "_authenticated.html"}))
    end
  end
end

Maybe it would be good to have as a guide in Pow docs.

from pow.

mrcasals avatar mrcasals commented on May 3, 2024

Ah yes, I thought about something like pow_routes(registration: false), but then I didn't know how to check whether the registration_path existed or not, that's why I mentioned a config option. But again, I'm barely starting with Elixir/Phoenix, so there might be a way I'm not aware of.

I assume you'll use a custom controller for profile edit?

Yes, that was the idea, but I haven't started this section. I'll keep your idea in mind in case it comes handy!

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

So I would love Pow to be smart enough to just detect what kind of template it should generate, but after doing a few different solutions for this, I think it's clashing too much with the goal of Pow being as explicit as possible. It's better to let the responsibility be on the developer, and require them to generate the templates.

Ideally all customization of Pow would be done by the developer by extracting the individual parts they want to customize. So in this case I would recommend to make the custom routes, and generate the templates, and then delete the registration templates/views since they are not needed.

I'm thinking about writing a guide on how to disable registration.

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

(Also I checked for the routes existence with the __routes__/0 method in the router module, but it's not meant to be a public API method)

from pow.

mrcasals avatar mrcasals commented on May 3, 2024

So in this case I would recommend to make the custom routes, and generate the templates, and then delete the registration templates/views since they are not needed.

@danschultzer yup, that's what I ended up doing. I'm 👍 on this solution, the only issue I had was that I had to look at the internals of pow to see what the pow_routes() macro expanded to. What about separating the content of pow_routes() in different macros so that devs can use pow_session_routes() or pow_routes() as they need to, without having to rely too much on the implementation of those macros? Whould that be fine?

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

It's something I did think about doing for quite some time. I've opened #71 that makes it possible.

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

Also added a guide for disabling registration 😄

from pow.

mrcasals avatar mrcasals commented on May 3, 2024

Looks good, yay! Thanks for the time building this! 😄

from pow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.