Comments (5)
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.
I've updated readme, thanks 👍
from pow.
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.
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.
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)
- Replacing Phoenix.Token with JWT-based for signing and verifiying of tokens HOT 1
- Unable to logout user in Pow API HOT 2
- Feature Request: Apple Passkeys HOT 1
- Pow.Plug.authenticate_user/1 performance HOT 2
- Reset password - test fails issue HOT 1
- Upgrading to Phoenix 1.7 HOT 5
- Create account without email/password using some unique ID?
- Phoenix 1.7 compilers warning HOT 1
- Maintain case when storing emails HOT 2
- Permissions issues with mnesia backend for Pow HOT 15
- Improve mix tasks
- Crash @missing_field? in Schema.ex HOT 1
- Inject values on registration HOT 2
- users_context seems to be ignored HOT 1
- Upgrading POW from 1.6 to 1.7 HOT 12
- Changeset errors into view HOT 1
- POW & LiveView - best way to implement `assigns.current_user` ? HOT 7
- Elixir 1.15 deprecation warnings HOT 1
- Persistence of stale session ids in MnesiaCache HOT 10
- Phoenix 1.6 App upgraded to 1.7 warning about layout conflicts. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pow.