Django allauth: Getting an IntegrityError during user creation - django-allauth

I saw a few discussions relating to this, but it seems the common cause of this is entering ACCOUNT_USER_MODEL_USERNAME_FIELD=None, which I'm not doing.
The exact error is:
duplicate key value violates unique constraint "auth_user_username_key" DETAIL: Key (username)=(testaccount) already exists.
(It doesn't, at least not when I fill out the form. Despite the error, it then shows up in my database, which leads me to believe it's making the account twice.)
Here are my custom allauth settings:
ACCOUNT_EMAIL_REQUIRED=True
ACCOUNT_USERNAME_REQUIRED=True
ACCOUNT_USER_MODEL_USERNAME_FIELD='username'
ACCOUNT_EMAIL_VERIFICATION=True
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION=True
ACCOUNT_SIGNUP_FORM_CLASS = 'profiles.forms.UserCreateForm'
And, just in case, here's my form:
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{% bootstrap_form form %}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<br>
<button type="submit" class="btn btn-primary btn-block">Sign Up</button>
</form>
Update: I've been trying to fix this for 2 weeks now and my code has undergone a lot of iterations. This seems to be the minimal amount of code I can have and still reproduce the error.

I had an integrityerror because my existing users had identical usernames before I started implementing this (I use PostgreSQL). In this case you might have multiple users with username 'testaccount'.
Maybe you should try to delete your existing users or make sure usernames are unique.

Related

How to get last inserted ID and send again

How can I send the lastInsertId again to another php document?
Explanation why:
After someone sends a form (form.html) to a database (send.php) he will get an ID for that form. This ID I show in the send.php to the person via PDO:
<p>Your ID:<?php echo $dbh->lastInsertId(); ?></p>
At this confirmation page I want give the person the possibility to print the data from his form as an pdf. So I wrote:
<form action="print.php" method="POST">
<input type="hidden" name="ID" value="<=htmlspecialchars($_POST['lastInsertId']);?>"/>
<input type="submit" name="Print" value="Print" >
</form>
But I he doesn't send the lastInsertId -> I guess the problem is here:
value="<?=htmlspecialchars($_POST['lastInsertId']);?>"
Can you help me to solve that problem?
Your code should be like this:
<form action="print.php" method="POST">
<input type="hidden" name="ID" value="<?php echo $dbh->lastInsertId(); ?>"/>
<input type="submit" name="Print" value="Print" >
</form>
Not sure if it's the best way, but I once needed the last ID of a person who registered.
I did the following after inserting the info into the DB (My table has Auto Increment Primairy Key ID):
$lastId = mysqli_insert_id($con);
You can store the ID anywhere you want. (In the URL or cookie)
Hope this helps (:
Thank you very much! That helped.
Is their an easy way that after he press print (now gets with the ID all the data from the database to show it at the site print.php - that part all works) and NOW DIRECTLY asks to save as pdf?

url of navigations of jekyll posts do not work when pushed to github

I wanted to add the navigation capability to my blog posts on github pages.
I added the following code into my post.html:
<div class="PageNavigation">
{% if page.previous.url %}
<a class="prev" href="{{page.previous.url}}">«
{{page.previous.title}}</a>
{% endif %}
...
</div>
When I push the posts to github, the link will not work due to the fact that code is residing under a repository url.
As a workaround, I added the repo name manually to the link. It becomes:
<a class="prev" href="/myRepoName{{page.previous.url}}">«
{{page.previous.title}}</a>
Now the problem is that the navigation is not working locally. Is there a simple solution to avoid this mess?
In _config.yml :
baseurl: /myRepoName
Link looks like :
<a href="{{ site.baseurl }}{{ page.previous.url }}" class="prev">
{{page.previous.title}}
</a>

Assigning a variable value to a paper-item

I'm trying to assign a object id to a list item so that I can look it up when it's selected. There is an example here that uses a literal. It also works for me. This code doesn't set the value:
<paper-dropdown-menu label="Style">
<paper-listbox class="dropdown-content" attr-for-selected="value" selected="2">
<paper-item *ngFor="let style of styles" value="{{ style.id }}">
{{ style.name }}
</paper-item>
</paper-listbox>
</paper-dropdown-menu>
If I code value="1" or value="test", it appears when I inspect in the browser. If it's set as above, nothing appears, not even an empty value. I've also tried creating String test=1; in the Angular component and using value="{{ test }}". It also does not appear.
If this doesn't work, then it might be a timing issue:
attr.value="{{style.id}}"

Can't get onclick on a button to be accepted

I currently have a link in the below form:
Change
In order to fit the look of the site in which I'm adding this link, I want to change it to a button input, as so:
<input type="button" value="Change" onclick="changeNumbers('Numbers', '#Url.Action("ChangeNumbers")')" />
However, I'm running into a snag with this second form: the single quotes around #Url.Action("ChangeNumbers") are being flagged as Unterminated string constant. Can anyone tell me what I'm doing incorrectly and how to fix it?
EDIT
It didn't occur to me to just try the page - it looks like the second form works. So now my question is - why is Visual Studio flagging this as incorrect?
You're not doing anything "incorrectly" per se, it's just that Razor isn't perfect, and things like quotes within quotes tend to cause it to freak.
One quick fix would be to store the URL in a variable and then use the variable:
#{ var url = Url.Action("ChangeNumbers"); }
<input type="button" value="Change" onclick="changeNumbers('Numbers', '#url')" />
However, an even better fix is to not use the onclick attribute at all. Put this where it belongs: in JS.
<script>
$('#myButton').on('click', function () {
changeNumbers('Numbers', '#Url.Action("ChangeNumbers")');
});
</script>
Used jQuery above, since it's included in MVC by default
I've found that to make Visual Studio happy in this scenario, the easiest thing to do is simply change the <input /> element to a <button></button> element and the error will resolve itself:
<button type="button" onclick="changeNumbers('Numbers', '#Url.Action("ChangeNumbers")')">Change</button>
Otherwise, to continue using an <input /> the markup will need to be changed to the following:
<input type="button" value="Change" onclick="#("changeNumbers('Numbers', '" + Url.Action("ChangeNumbers") + "')")" />

Amazon S3 Upload via Post and ASP.NET MVC

I've been trying in vain for 2 days now to do a simple upload to my Amazon S3 Bucket. Below is my rendered form:
<form action="http://s3.amazonaws.com/MYBUCKETNAME" method="post" enctype="multipart/form-data">
<input type="hidden" name="AWSAccessKeyId" value="MYACCESSKEY" />
<input type="hidden" name="acl" value="private" />
<input type="hidden" name="key" value="UserUploads/TestUser/${filename}" />
<input type="hidden" name="success_action_redirect" value="http://WWW.MYURL.COM/" />
<input type="hidden" name="policy" value="POLICY" />
<input type="hidden" name="signature" value="SIGNATURE" />
<div>
Please specify a file, or a set of files:
<input type="file" name="file" size="100" />
</div>
<input type="submit" value="Upload" />
</form>
and my policy document looks like this:
{
expiration = "2011-12-08T12:00:00.000Z",
conditions = [
["eq","bucket","MYBUCKETNAME"],
["eq","acl","private"],
["starts-with","$key","UserUploads/TestUser/"],
["eq","success_action_redirect", "HTTP://WWW.MYURL.COM/"]
]
}
I get the following error:
Code: AccessDenied,
Message: Invalid according to Policy: Policy Condition failed: ["eq", "bucket", "MYBUCKETNAME"]
Does anyone have any ideas please, I'm grabbing at straws here. Also not sure if my Bucket Policy and ACL is correct.
According to http://doc.s3.amazonaws.com/proposals/post.html#Access_Control
Matching a Particular Value
Description: There are certain fields that you want to match a
particular value, such as matching a bucket name or requiring that an
object is uploaded using the public-read access control policy. The
field value is case sensitive, but the name is not.
Syntax: There are two ways to require that the field fieldname matches
the string value. The value is case sensitive. If the value starts
with a dollar sign ($), the dollar sign must be escaped with a
backslash (\$)
[ "eq", "$fieldname", "S" ],
(Note the $ prefix).
So your policy should have $ in sets where you using "eq" format
Why not do this in C# with the S3 SDK (http://aws.amazon.com/sdkfornet/), it's a bit more secure.
Here's my blog post with more detail: http://bradoyler.com/post/3614362044/uploading-an-image-with-aws-sdk-for-net-c.
Cheers and Good luck.
I was getting the following error:
Invalid according to Policy: Policy Condition failed: [\"eq\", \"$bucket\"
After many hours, I learned that you can't have a bucket with uppercase letters. Changing the bucket to lowercase fixed it.

Resources