spring lemon - "Request method 'GET' not supported" on email verification - spring-lemon

I am trying to use spring lemon for user handling. I am sending a registration request which gets a 201 response and sends an email to the user, but when the user clicks the link he gets a "Request method 'GET' not supported" response. I looked at the spring lemon code, and in LemonController.java line 104 the verifyUser method uses a #PostMapping annotation. Shouldn't it use a GET annotation? The link from the email creates a GET request, not POST.
Thanks.

Related

Django stripe is returning "No such token: 'tok_1M2CbwG5K6HWS5kNipsQbCKh'" as error message

Anytime i tried to make a test payment on stripe, it returns the error below,
tok_1M2CbwG5K6HWS5kNipsQbCKh 86.0 25
Request req_eboPGGTsmc4D3a: No such token: 'tok_1M2CbwG5K6HWS5kNipsQbCKh'
i tried with the api keys from stripe but still it wont work.

Why does Django return http 200 if form data is invalid?

AFAIK Django uses this way to handle forms:
GET: client receives HTML with input elements
user fills out the form
user submits form: http POST
server/Django validates the form. In this case it is invalid
server sends HTML containg the same form and an error message to the user. With http status 200.
Wouldn't it make more sense to use a different http status code if the data is invalid?
PS: I know the Post/Redirect/Get pattern. The question is: "Why 200 if the data is invalid?"

api test with postman in angular project

I want to test my api for resister which is post type it contain username, email, password, phone number. I really don't know how to test api in postman. It should be authorization type of no-auth. After this I have to validate or test api for login then it generate some key then I have to use this key to test other api's.
i believe to test post api withpostman
first you need to put the route of your api and the type of http in your case POST
then go to header tab and add this header(under key/value):-
Content-Type :application/json
then under body tab select row option and insert valid json as below
{
"username": "Omar Shabro",
"email": "o4#o.com",
"phone": "0599"
}
depends first find if any form of auth is being used in such case you will need to handled the auth before sending requests. check the link bellow it will help you in case of auth
https://www.getpostman.com/docs/helpers

Designing URLs without verbs for operations related to user in a REST API

I'm building REST API.
I have following structure
GET /user/{id} - get
POST /users - Create user
PUT /users/{id} - Update user
DELETE /users/{id} - Delete user
The problem is following. As I got from many tutorials/articles - it is bad practice to use action in URL. But what to do with such actions like:
check email (is unique)
recover user by email
?
Assume user registration. User submits form ( POST /users ) and I need to check if email is unique. Do I need to do it in same api method and return validation errors as response body?
Or do I need to create something like
POST /users/email
And what about user recovering by email? Where do I need to do it? Because recover is verb
POST /users/recover
I'm not sure, that I'm doing it right and I can't find correct explanation for that situation.
Validating the e-mail and registering the user
If you want, you can have an endpoint to check whether an e-mail is already registered or not. It's up to your requirements. So, you can have something as following and then send the e-mail which will be validated in the request payload:
POST /users/email/validation
{
"email": "mail#example.com"
}
The endpoint above can be invoke, for example, when the user completes the e-mail field of your account registration form.
However, do not forget checking if the e-mail is already registered when creating a user:
POST /users
{
"firstName": "John",
"lastName": "Doe",
"email": "mail#example.com",
"password": "123456"
}
If an e-mail is already registered, you could consider returning a 409 Conflict status code and a payload that includes enough information for a user to recognize the source of the conflict.
Recovering the password
I'm unsure if this is your requirement, because of this I posted a comment asking for clarification. I presume you are trying to recover the password of a user, assuming the user has no more access to their account.
If so, you could have an endpoint as following and then send the e-mail of the user in the request payload:
POST /users/password/recovery
{
"email": "mail#example.com"
}
Then your server can send a link with a token to the e-mail specified in the payload. Only send the e-mail if the e-mail specified in the payload is registered in your application, of course.
The link should take the user to a page where they will enter the new password and, when submitting, an endpoint to replace the password of the user will be invoked, sending the token and the new password to the server:
PUT /users/password?token=SomeValueGoesHere
{
"password": "654321"
}

Translate email messages

I would like to translate email messages. I have a method in my model which is called after_save. This method creates mailer:
MyMailer.delay.notify_on_new_object self
The mailer uses mail message to send it:
mail(to: #email, subject: t(:subject, scope: "mailers.object"))
The problem is that every time english version of email is sent. No matter which locale is set in request. I know that request informations are not passed to models. So how can I set proper locale from request before sending email?
Have you tried something like:
I18n.locale = :es # or a locale variable given to the mailer
mail(to: #email, subject: t(:subject, scope: "mailers.object"))