rameshsharma

rameshsharma

Dear All,

I have the below two urls in my project:-

Url1 - https://localhost:4443/register

Url2 - https://localhost:4443/register?scheme=tesco

If Url1 is used by a user while registration then we must verify the user with his email suffix (should have @tesco.com in the email address).

If Url2 is used then user is verified with his url query parameter (scheme=tesco) and then his email suffix can be anything (no restriction with email suffix)

I am struggling to make both the cases work together. Can someone please help me here. It would be of great help for me.

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Happy to help. The best place to start would be if we can see what you’ve tried so far, can you post your code? The more code the better!

rameshsharma

rameshsharma OP

Thanks Ben for the reply.

Url2 requirement, I am able to achieve as I am verifying the scheme parameter in the url from the database and allowing user to proceed with any email suffix. Code snippet below:-

def partner_intro(%{request_path: path} = conn, %{“scheme” => scheme_value} = params, _guest)

  when path == "/register" do

query = Repo.all(from u in PensionSchemeFees, select: u.scheme)

if Enum.member?(query, scheme_value) do

.>>>

Struggling to fit in the same module the url1 suffix validation condition.

rameshsharma

rameshsharma OP

I have a module for email suffix validation like below where I have the email pattern mentioned.
But the problem is if I apply this ‘validate_email_domain’ module in my changeset, then it is applied for both Url1 and Url2. I do not want any email address restrictions for Url2 case. Only want the restriction for Url1 case.

def validate_email_domain(changeset, field, opts \ ) do

pattern = ~r/|@tesco.com/
kokolegorille

kokolegorille

Please note the site uses Markdown,

You should enclose code with ```

You struggle with the case where there is no scheme params?

Maybe add this after your first match?!

def partner_intro(%{request_path: path} = conn, params, _guest) when path == "/register" do
  ...
end
rameshsharma

rameshsharma OP

Thanks, I can add another module as you mentioned.
But how to make the ‘validate_email_domain’ condition apply to one case and not to apply for another case.

Below is my one common changeset which has to be used for both the cases:-

def email_changeset(struct, params \\ %{}) do

   struct

   |> cast(params, [:email])

   |> validate_required(:email)

   |> validate_unique_field(:email)

   |> validate_email_format(:email)

   |> validate_email_domain(:email)

 end
rameshsharma

rameshsharma OP

Is there any way to exclude the ‘validate_email_domain’ condition in one case and include in another case.

kokolegorille

kokolegorille

If it is to separate case, I would not mind having separate changeset.

This is the descriptive way…

or add a parameter when domain needs to be checked, and use a condition.

rameshsharma

rameshsharma OP

Can you please give some example of ‘add a parameter when domain needs to be checked, and use a condition’.
I am very new to elixir and phoenix web development.

rameshsharma

rameshsharma OP

Any help here can you provide please

kokolegorille

kokolegorille

You can differentiate case by pattern matching on param scheme (or not)… then I advise You to have to different changesets for each cases.

If You prefer, add a parameter when You call email_changeset… like should_verify_email and use a condition in the pipeline.

But I would try to avoid that, and use pattern match instead.

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews