Giter Site home page Giter Site logo

Comments (5)

danschultzer avatar danschultzer commented on May 3, 2024

Yeah, the default changeset is strict and won't permit params that users shouldn't be able to submit (like the :email_confirmed_at value). You're doing it the right way.

There's another way of doing it, but it's much less secure:

defmodule MyApp.Users.User do
  use Ecto.Schema
  use Pow.Ecto.Schema
  use Pow.Extension.Ecto.Schema,
    extensions: [PowEmailConfirmation]

  schema "users" do
    pow_user_fields()

    timestamps()
  end

  def changeset(user_or_changeset, attrs) do
    user
    |> Ecto.Changeset.cast(attrs, [:email_confirmed_at])
    |> pow_changeset(attrs)
    |> pow_extension_changeset(attrs)
  end
end

To highlight the issue with permitting mass assignment, Coherence has a huge security issue due to its lax treatment of user params: smpallen99/coherence#270

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

I've updated readme, thanks 👍

from pow.

jung-hunsoo avatar jung-hunsoo commented on May 3, 2024

Casting fields in changeset should be dealt with care, so I agree your approach is proper.

By the way how about replacing PowEmailConfirmation.Ecto.Context.confirm_email/2 with PowEmailConfirmation.confirm_email/2 or PowEmailConfirmation.Operations.confirm_email/2? It will wrap lower level functions and allow possible independent with Ecto.

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

That's a great idea. The extensions have been built so they are tightly connected between the plug and ecto APIs, mostly because I wasn't 100% sure how the extensions should be working. Having an Operations module for the extensions makes a lot of sense. Let me reopen this until I can create a PR to add a similar high level API 👍

from pow.

danschultzer avatar danschultzer commented on May 3, 2024

I've been looking at this several times, but I think as Pow currently is it works pretty well. There hasn't been a need to decouple extension plug and extension ecto modules so I don't think it's really needed. I'll revisit this if it becomes relevant, but it seems like extensions are so tightly coupled that any modification would in any case require developers to plan carefully.

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.