3

I am creating a web app and need to send an email verification to users after they registered in the system. When the user receives a verification email, they need to click on the link in that email to verify their email address. My question is whether the link points to my backend server or to my frontend.

Options1: If I make the link to my backend, I need to implement a GET RESTFul service to receive this request since browser couldn't send a POST request. After verification, backend will response a redirect to the browser to redirect to front end url. This may be not a best practice in terms of RESTFul design since it makes changes in my database.

Option2: If I make the link to the front end, my front end needs to parse the verify code from the url and send a post request to the backend to do the verification job.

I am not sure which one is better. Does anyone give me some suggestions on that?

My frontend and backend are separated. Backend is implemented in Python while front end is angularjs. They communicate through Restful API.

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • Is your URL dispatcher in your Python app? – Greg Schmit Jan 08 '18 at 05:44
  • I am not sure I understand your question. What do you mean by `dispatcher`? – Joey Yi Zhao Jan 08 '18 at 05:47
  • Or URL router, or URL parser – Greg Schmit Jan 08 '18 at 05:48
  • It is a restful service, so I think it is URL router. – Joey Yi Zhao Jan 08 '18 at 05:49
  • If I go to yoursite.com/some/view -- the first thing is the URL has to be parsed so we know where to go next. This is normally done by a URL dispatcher. – Greg Schmit Jan 08 '18 at 05:51
  • 1
    while, if you go to `yoursite.com/some/view`, the frontend Angularjs will server this page and show your the web site. When you do some actions on the front end, such as `login`, `sign up`, etc, a async http request will be sent to backend to handle the request. – Joey Yi Zhao Jan 08 '18 at 05:53
  • I updated my answer; your AngularJS app should handle the request, but it should send a request to the backend that does the processing of the email verification. Depending on how that goes, your frontend should format a response to the user. – Greg Schmit Jan 08 '18 at 06:00

1 Answers1

4

Your backend should handle email verification. The backend should handle all of that stuff. Assuming your URL dispatcher is in your frontend, it would get the request and then pass it to the backend.

The common phrase is to keep all of your "business logic" in the backend. This ensures that your frontend is only focused on presenting the data.

Your AngularJS app should handle the request, make a call to the Python backend (so it can do the logic of processing the email verification to see if it is valid or not), and then the response should come back to the AngularJS app which should format a nice looking response to the user to indicate whether the email verification worked.

Greg Schmit
  • 4,275
  • 2
  • 21
  • 36
  • I am not using MVC. Front end and backend are separated. – Joey Yi Zhao Jan 08 '18 at 05:40
  • I have added a description at the end of my post. – Joey Yi Zhao Jan 08 '18 at 05:47
  • It looks like my angularJS works as a proxy. It receives the url from user then parse the verify code from parameters of the url, then send a post request to backend. Why not links directly to backend then redirect users to frontend? Is there any advantage of your approach? – Joey Yi Zhao Jan 08 '18 at 10:16
  • @ZhaoYi I think consistency and extensibility. Your users should be able to do **everything** through your frontend, including going to the link to activate their email. Also, in the future if you want an interstitial to set their initial password, then doing that will be easier because the scaffolding on the frontend will be setup. – Greg Schmit Jan 08 '18 at 15:08