such a document already exists что делать
I want to add data into the firestore database if the document ID doesn’t already exists. What I’ve tried so far:
The goal is to check all the documents ID in the database and see in any matches with the «varuId» variable. If it matches, the document won’t be created. If it doesn’t match, It should create a new document
4 Answers 4
You can use the get() method to get the Snapshot of the document and use the exists property on the snapshot to check whether the document exists or not.
Use the exists method on the snapshot:
getDocuments() fetches the documents for this query, you need to use that instead of document() which returns a DocumentReference with the provided path.
Edit: @Doug Stevenson is right, this method is costly, slow and probably eat up the battery because we’re fetching all the documents to check documentId. Maybe you can try this:
The reason I’m doing null check on the data is, even if you put random strings inside document() method, it returns a document reference with that id.
Drupal Русскоязычное сообщество
Создал на Гитхабе репу.
Выдает
fatal: remote origin already exists.
Устанавливать Drupal можно так:
1.
Может проблема от того, что раньше пользовался 2-м способом, а теперь попробовал 1-м?
Комментарии
пробовал решить так (не получилось):
Вроде работает
правда папка files с картинками почему-то пошла в репу
Так зачем ты инициируешь репозиторий (git init), если у тебя уже есть удаленный репозиторий (https://github.com/Vasy0K/portal.git).
Прочитай какой-нибудь букварь по гиту, например вот этот: https://git-scm.com/book/ru/v2
Какие-то продвинутые вещи не нужны, хотя-бы просто понимание базовых команд, ветвей и работы с удаленной репой.
Видимо, как-то слишком по диагонали, раз возникают такие вопросы и удивления.
Пойми правильно, не стоит задача подколоть. Просто твой вопрос немедленно сигнализирует о том, что ты не понимаешь что за команды ты вводишь, что они делают и как работает распределенный гит. Инвестируй 2-3 часа времени на четкое понимание основ, этим ты застрахуешь себя и своих клиентов от седых волос и сидений в ночи в попытке восстановить похеренный репозитарий.
До того, как разбираться собственно с командами git, и пытаться методом тыка что-то сделать, неплохо бы понимать концептуально, как вообще строится процесс работы. Как вариант, почитать книжку по ссылке @Selpi.
Я понимаю, когда что-то делаю, а не читаю.
Проблема выше решена, но мне хотелось бы услышать технический комментарий, а не посыл.
Дак тебе объяснили уже, что если бы ты понимал, что делаешь, этого вопроса вообще бы не возникло
На развитие drupal.ru
Ваша финансовая помощь дает нам возможность оплачивать хостинг и поддерживать стабильную работу сайта. Благодарим за поддержку!
HTTP response code for POST when resource already exists
I’m building a server that allows clients to store objects. Those objects are fully constructed at client side, complete with object IDs that are permanent for the whole lifetime of the object.
I have defined the API so that clients can create or modify objects using PUT:
The
Now, I’m also considering allowing clients to create the object using POST:
Since POST is meant as «append» operation, I’m not sure what to do in case the object is already there. Should I treat the request as modification request or should I return some error code (which)?
17 Answers 17
My feeling is 409 Conflict is the most appropriate, however, seldom seen in the wild of course:
The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.
Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being used and the entity being PUT included changes to a resource which conflict with those made by an earlier (third-party) request, the server might use the 409 response to indicate that it can’t complete the request. In this case, the response entity would likely contain a list of the differences between the two versions in a format defined by the response Content-Type.
According to RFC 7231, a 303 See Other MAY be used If the result of processing a POST would be equivalent to a representation of an existing resource.
The 422 Unprocessable Entity status code means the server understands the content type of the request entity (hence a 415 Unsupported Media Type status code is inappropriate), and the syntax of the request entity is correct (thus a 400 Bad Request status code is inappropriate) but was unable to process the contained instructions.
It’s all about context, and also who is responsible for handling duplicates in requests (server or client or both)
If server just point the duplicate, look at 4xx:
For implicit handling of duplicates, look at 2XX:
if the server is expected to return something, look at 3XX:
when the server is able to point the existing resource, it implies a redirection.
If the above is not enough, it’s always a good practice to prepare some error message in the body of the response.
Late to the game maybe but I stumbled upon this semantics issue while trying to make a REST API.
10.4.4 403 Forbidden
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
Nowadays, someone says «403» and a permissions or authentication issue comes to mind, but the spec says that it’s basically the server telling the client that it’s not going to do it, don’t ask it again, and here’s why the client shouldn’t.
9.6 PUT
it MUST send a 301 (Moved Permanently) response; the user agent MAY then make its own decision regarding whether or not to redirect the request.
As an argument against other answers, to use any non- 4xx error code would imply it’s not a client error, and it obviously is. To use a non- 4xx error code to represent a client error just makes no sense at all.
It seems that 409 Conflict is the most common answer here, but, according to the spec, that implies that the resource already exists and the new data you are applying to it is incompatible with its current state. If you are sending a POST request, with, for example, a username that is already taken, it’s not actually conflicting with the target resource, as the target resource (the resource you’re trying to create) has not yet been posted. It’s an error specifically for version control, when there is a conflict between the version of the resource stored and the version of the resource requested. It’s very useful for that purpose, for example when the client has cached an old version of the resource and sends a request based on that incorrect version which would no longer be conditionally valid. «In this case, the response representation would likely contain information useful for merging the differences based on the revision history.» The request to create another user with that username is just unprocessable, having nothing to do with any version conflict.
For the record, 422 is also the status code GitHub uses when you try to create a repository by a name already in use.
Such a document already exists что делать
Ever since then, now he gets «incoming server already exists» no matter which e-mail account he tries to add. We had him uninstall and delete all Thunderbird folders. Same problem. We had him try Thunderbird 38, 45, and the latest version of Thunderbird. Same problem. He calls us «mate,» so we think he is in UK, Australia or NZ, so we always sent him official Thunderbird ftp links that let him pick by country. Suspecting that he might be doing something wrong in deleting the profile or adding accounts, we had him create a new Windows user account to be sure. In the new user account, he gets the same problem. Very perplexing.
So, at this point, I would think the problem is not tied to his Thunderbird user profile or his Windows profile. He has no problem accessing any of his e-mail accounts via webmail. I should mention at this point that he is using a decrepit Windows XP machine. Suspecting that he could be having a problem with e-mail accounts in general, or with having Thunderbird set as default mail reader, we had him change his default to Outlook Express and set up a couple of accounts using Outlook Express, and he had no issues in Outlook Express. We returned to Thunderbird, and he got the same error.
I’ve never had to resort to registry edits involving Thunderbird, but we are at a loss.
Any advice/suggestions welcome.
Edit: I should also mention that he says that when he tries to add an e-mail account, it stays stuck on «Checking password» for about an hour before it produces the «incoming server already exists» message.
Modified May 26, 2020 at 1:34:50 PM PDT by Corey
Chosen solution
‘Authentication Method’ = OAuth was available in version 52.9.1 It became available in version 38.0.1
Add the gmail account. File > New > Existing Mail Account Enter name Enter full gmail email address Enter Password (same one used to access webmail) Select checkbox to remember password click on ‘Continue’ Let Thunderbird try to locate config data Make sure ‘imap’ is selected. Then click on ‘Manual Config’ button
Double check Incoming ‘imap’ is selected and all server settings are correct. imap.gmail.com port: 993 connection security: SSL/TLS Authentication : ‘OAuth2’
outgoing: smtp.gmail.com port: 465 connection security: SSL/TLS Authentication : ‘OAuth2’
‘username’ is the full gmail email address
click on ‘Re-test’ when ok click on ‘Done’ You will be prompted by gmail to enter email address and password in a browser that auto opens. Password is the one used to logon to see webmail account. Gmail is checking you really are you. Then gmail creates a token that is auto saved in Thunderbird in the same place as passwords.
All Replies (8)
re : I should mention at this point that he is using a decrepit Windows XP machine.
The last Thunderbird version that could be used on an XP was 52.9.1
re :Ever since then, now he gets «incoming server already exists» no matter which e-mail account he tries to add. Sounds like he did not delete the profile, it cannot exist if it was fully deleted.
He would have needed to : Exit Thunderbird first if it was running. This is important.
Delete the ‘Thunderbird’ folder as shown below; assuming everything was installed in default location. In XP his profile would have stored here:
He would need to not search, but actually locate that directory to ensure he was in the correct place.
Note: The Application Data folder is a hidden folder; to show hidden folders, open Windows Explorer and choose «Tools → Folder Options → View (tab) → Show hidden files and folders».
Then empty the ‘Recycle Bin’.
click on appropriate language eg: En-GB (English British) Install as standard (not custom) installation. Run to create automatic profile. Add accounts.
Chosen Solution
‘Authentication Method’ = OAuth was available in version 52.9.1 It became available in version 38.0.1
Add the gmail account. File > New > Existing Mail Account Enter name Enter full gmail email address Enter Password (same one used to access webmail) Select checkbox to remember password click on ‘Continue’ Let Thunderbird try to locate config data Make sure ‘imap’ is selected. Then click on ‘Manual Config’ button
Double check Incoming ‘imap’ is selected and all server settings are correct. imap.gmail.com port: 993 connection security: SSL/TLS Authentication : ‘OAuth2’
outgoing: smtp.gmail.com port: 465 connection security: SSL/TLS Authentication : ‘OAuth2’
‘username’ is the full gmail email address
click on ‘Re-test’ when ok click on ‘Done’ You will be prompted by gmail to enter email address and password in a browser that auto opens. Password is the one used to logon to see webmail account. Gmail is checking you really are you. Then gmail creates a token that is auto saved in Thunderbird in the same place as passwords.
Thank you for the steps. He says he followed them, and it still hangs at checking for password. Does this look like the right settings? : https://imgur.com/GlVMZ46
Server name already exists sounds like he is not following the steps.
Try these instructions to remove what already exists.
In the windows run dialog. (windowskey+R) Type %appdata% and press enter. Have him locate the Thunderbird folder that will be displayed in the windows file manager and select it and press the delete key.
I have seen a lot of folks get instructions to delete something and they type the file into windows search, get a not found result and then confirm they did it. So I am anything but trusting.
I did try and look at the settings, but I gave up, they never downloaded. The following link is to the correct settings for Gmail that Thunderbird looks up when trying to set up a new account. It is an XML file, but the what setting is what is fairly obvious. https://autoconfig.thunderbird.net/v1.1/gmail.com
Note this part particularly well. I have had extreme issues with anti virus product messing up account creation. Either blocking the site with the account setting I just linked to or in the case of Norton, just blocking the wizard entirely because it was a «threat» until I disabled something called sonar, so you may not be dealing with a Thunderbird issue at all. It just looks like it.
These following instructions are the next logical step to try once all the old stuff is actually deleted.
Once a new version of Thunderbird 52.9.1 program has been installed, it does not need to be deleted again.
If he gets «incoming server already exists» error message at the first attempt to create a mail account after following instructions, then it is likely he did not correctly delete the ‘Thunderbird’ folder that contains the ‘Profiles’ used. That error message would mean he was accessing the same old original profile and the ‘profiles.ini’ file still existed and pointed to it. Hence the need for deleting the User Account > Application Data > ‘Thunderbird’ folder that contains everything.
That information on profile location does assume he has always allowed Thunderbird to create profiles in the default location. It assumes he is not using any ‘portable’ version of Thunderbird.
Please note: If he has more than one Windows ‘User Account’, then each account will contain it’s own ‘Thunderbird’ folder containing profiles. So I would advise, he logs in to each ‘User Account’ and makes sure all profile ‘Thunderbird’ folders are deleted.
re image: As far as I can tell the settings look correct.
Check Firewall settings: After downloading and installing the 52.9.1 version of Thunderbird. Check the ‘Firewall’ setting as it must allow ‘Mozilla Thunderbird’ program. It could be a default Window Firewall or if any Anti-Virua product is installed then it could be controlling the ‘Firewall’. If Firewall already says it is allowed, then uncheck it, say ok. Then access Firewall again and select ‘Mozilla Thunderbird’ program as ‘allowed’. Just to make sure it is allowing the last version installed.
re :He says he followed them, and it still hangs at checking for password. I notice the images shows lower ‘Status Bar’ says the email at server is ‘sending secure login information’. But you/he do not mention whether the browser auto opened. Usually, the browser opens and gmail wants you enter email address and password to check you really are you. It could be waiting for a response. Is the browser opening behind the Thunderbird window and he is not aware of it?
HTTP Status Code for username already exists when registering new account
A client sends the following to POST /account/register
The server attempts to create the new account but finds that the username is already taken.
What should the most appropriate HTTP status code response be?
I’m thinking 409 Conflict however that means the client is then aware that the username exists, which might be a security issue? Or is it simply a case of visibility based on the type of site so depends on the situation?
4 Answers 4
I’d suggest returning error 409 Conflict :
The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request.
If your are concerned about privacy, regardless if the account was created or not make sure to respond the same way, and probably 204 or 202 are the most appropriated status code in this case.
To not confuse the user on the frontend you can display a generic message saying something like «You will receive a confirmation email on the next minutes if you don’t have an account, if you don’t receive the email try forget password».
Depending on how far you want to take things, you might want to create the account on a background process rather than in the main/request thread, otherwise attackers could analyze the response time of your endpoint and infer if the account was created or not based on the response time, this since the process of actually creating the account might take more time than just checking if it exists and returning.
Responding the same way in both scenarios is the only way to ensure an attacker can’t figure out who is already registered in your system.
For user already exists 403 seemed perfect according to wikipedia https://en.wikipedia.org/wiki/HTTP_403
Not the answer you’re looking for? Browse other questions tagged security http or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.11.12.40742
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.