r/shittyprogramming • u/imwearingyourpants • Feb 15 '14
Am I doing it right? [x-post from /r/webdev]
20
Feb 16 '14
is it really that hard to at least disable the button in javascript on click? I mean that would be the minimum that I would recommend. Along with something on the backend to say "If this user has submitted this same order within the last hour, don't process it." I mean really? Its like a few hours of work, maybe.
8
u/spin81 Feb 19 '14
Along with something on the backend to say "If this user has submitted this same order within the last hour, don't process it."
I don't know about that one. If I want to buy the same thing twice within one hour, that's my business.
Maybe I forgot I needed two [things] instead of one.
Maybe I want a spare [thing] in case I break the first one.
Maybe I bought two tickets to a show and the couple next door want to join us.
Maybe I streamed an episode of House of Cards and I want to watch another one right after that.
26
Feb 20 '14
no, not the same thing, the same order. What you do is have a hidden field in the order form somewhere with some kind of hash (doesn't matter what it is, as long as its unique). This is generated when you hit the form, and recorded into the table when the order is submitted. if this same hash is submitted again, ignore it. Actually now that I think of it, you wouldn't need the hour constraint.
11
u/Arphrial Apr 15 '14
Just to bring this up from the dead, this is the typical method of doing this.
For anyone wondering, this is called a nonce, or a number used once.
1
u/ajax333221 Apr 09 '14
I don't trust the DOM manipulation, I would go for changing a global variable and once it has changed prevent the submit.
But for the record, I fully know that client side protection is less than a layer of air, but having more layers is never bad.
1
1
10
8
7
u/goosepoop Feb 16 '14
This is ingenious.. Just make sure you throw some <h1> tags on the part about charging credit card multiple times.
4
4
3
u/Omiris Mar 12 '14
twist: Genius management thought this would be better so they get double charges from people who fail to read. Programmer complained, offered solution to problem, was shot down by greedy dill hammer.
74
u/[deleted] Feb 15 '14
Most would not have gone through the trouble of warning their user base about the ill-effects of this feature. This dev really went above and beyond.