Accessing account information in Django Allauth confirmation email - django

I am using a custom e-mail message by overriding the default confirmation email of Django Allauth email_confirmation_message.txt
I have a custom signup form that also collects first and last name so I would like to access the first name that they have given during signup, in my e-mail confirmation. So you can address someone with his first name.
This is what the default template looks like:
{% load account %}
{% user_display user as user_display %}
{% load i18n %}
{% autoescape off %}
Dear {{ first name given at registration here }}
...
{{ activate_url }}
...
{% endautoescape %}
It uses {% user_display user as user_display %} to display the username. So there must be a way to access the first name as well?
How can I access the first name in this e-mail? Or is this not possible without completely writing a custom confirmation e-mail?

Related

Allauth email verification link still works after verification and doesn't invalidate

I'm using allauth to handle my verification and I'm receiving verification emails to confirm signup. The verification email gets sent fine and works, but my problem is that even after I'm done with verification, the else statement in the html provided by allauth doesn't get triggered and the verification email still works and asks me to verify the user when I click on it, although it's already verified.
email_confirm.html
{% if confirmation %}
{% user_display confirmation.email_address.user as user_display %}
<p>{% blocktrans with confirmation.email_address.email as email %}Please confirm that {{ email }} is an e-mail address for user {{ user_display }}.{% endblocktrans %}</p>
<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">
{% csrf_token %}
<button type="submit">{% trans 'Confirm' %}</button>
</form>
{% else %}
{% url 'account_email' as email_url %}
<p>{% blocktrans %}This e-mail confirmation link expired or is invalid. Please issue a new e-mail confirmation request.{% endblocktrans %}</p>
{% endif %}
Anyone face something similar or know a fix to this?
Thanks!
you need to go to your settings file to set cooldown time (the period after it the email will be invalid ) for the verification email
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS (=3)
you can visit https://django-allauth.readthedocs.io/en/latest/configuration.html
for more configurations

how to pass account information to django template in django-registration?

I want to pass the account information to the template so that when an user account is activated, there is a message saying "your account is activated; please log in now" with a link below. if the activation days have expired, it must say "activation days expired". I have url and template here, but I do not know how to pass the account information to the template.
url.py
urlpatterns = patterns('',
url(r'^activate/complete/$',
TemplateView.as_view(template_name='registration/activate.html'),
name='registration_activation_complete'),
......)
registration/activate.html
{% extends "registration/base.html" %}
{% block title %}Account activated{% endblock %}
{% block content %}
<h1>Account activated.</h1>
{% load humanize %}
{% if account %}
<p>Thanks for signing up! Now you can log in.</p>
{% else %}
<p>Sorry, it didn't work. Either your activation link was incorrect, or
the activation key for your account has expired; activation keys are
only valid for {{ expiration_days|apnumber }} days after
registration.</p>
{% endif %}
{% endblock %}
basically, I want to pass account and expiration_days to the above template. I just don't know how. help plz!
I'm afraid it won't be enough just to use TemplateView like you did; you'll have to write a custom view which will contain the logic for activation and pass the data to the template.

why does password reset works with unregistered email in django?

I have a couple of questions regarding how the password reset works in Django.
How can I do testing on password reset testing during development phase?
The password reset sends email to unregistered email addresses successfully (as appears on screen). I thought it should display "no such registered email address is found" instead of displaying "password reset successful".
Here is the form used for password reset. I am confused from the form action. It submits to itself which is http://127.0.0.1:8000/accounts/password/reset/ but how is that it is redirected to http://127.0.0.1:8000/accounts/password/reset/done/ after submission when it submits to itself.
{% extends "registration/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Reset password" %}{% endblock %}
{% block content %}{% blocktrans %}
Forgot your password? Enter your email in the form below and we'll send you
instructions for creating a new one.{% endblocktrans %}
<form method='post' action=''>{% csrf_token %}
<table>
{{ form }}
<tr><td></td><td><input type='submit' value="{% trans "Reset password" %}" /></td></tr>
</table>
</form>
{% endblock %}
I presume the problem is that your development environment isn't set up to send emails? In that case, add this in your settings_local(or equivalent):
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
This will cause emails to be displayed in the runserver terminal. You can copy-paste any links from there.
That is deliberate, to not-allow outside users to poke at the registration form and see whether a particular email has been registered or not. A "privacy feature", I guess we could call it.
POST-ing to the same URL is a standard practice in Django. It is not a requirement, but it just makes sense to do that. It makes sense because that way a single View handles both creating of the Form and receiving the data, see Using a form in a view
And the redirection happens from the View, deliberately:
def form_valid(self, request, form):
# blah blah...
return redirect(success_url)
The redirection after a POST is also a standard practice, and not just in Django: http://en.wikipedia.org/wiki/Post/Redirect/Get
I doesn't display "no such registered email address is found", as it is the best practice approach against phishing attempts. However, you can always write your own code to check if the given email exists in your DB. As for how the user gets redirected to '/accounts/password/reset/done/', I'd have to see the 'Reset password' view to know for sure.

django-profiles: how to edit a profile from a user different from current user

newbie django question
I'm using django-profiles to display a list of profiles, using profiles.views.profile_list view, and individual profiles, using profiles.views.profile_detail.
For each individual profile, I wanted to add a link to edit the profile, only if the profile corresponds to the current user. My first attempt was:
(...)
{% block content %}
<p>Profile detail info for {{ user }} </p>
<ul>
<li>{{ user.username }}
{% if user.is_authenticated %}
edit
{% endif %}
</li>
<li>{{ user.get_profile.url }}</li> (...)
But then I hit the obvious issue: edit_profile is meant to edit the current user profile, so doesn't take username/ id as arguments, and django cannot reverse the url, because in fact I don't have a url to edit a named user's profile.
What's the best strategy here? copy the profiles app into my project and add the named user edit profile view? Or is there a way to do it without having to have a local project copy of the app - which I guess would be preferable?
thanks
The edit_profile view already enforces that the profile being edited is the current user's profile. You don't need to pass any arguments to it:
(...)
{% block content %}
<p>Profile detail info for {{ user }} </p>
<ul>
<li>{{ user.username }}
{% if user.is_authenticated %}
edit
{% endif %}
</li>
<li>{{ user.get_profile.url }}</li> (...)

2 problems with registration

I use the obvious powerful registration 0.8 alpha version. I do have to questions.
1.) I want to add the checkbox RegistrationTermsOfService at the registration form html file. I just don't know how to do it. Please don't give me an link on uebernstorm docs. Just tell me please how to do it. I have read and tried a lot and it actually doesn't work. I am dispairing!
2.) The activation email is send with the activation key. When I click on activation the account is getting activated in the database but the template says something different. It says:"Sorry, it didn't work. Either..."
I use the standard activate.html below:
{% extends "base.html" %}
{% block title %}Account activated{% endblock %}
{% block content %}
Account activated
{% load humanize %}
{% if account %}
Thanks for signing up! Now you can "href"
{% else %}
Sorry, it didn't work. Either your activation link was incorrect, or
the activation key for your account has expired; activation keys are
only valid for {{ expiration_days|apnumber }} days after
registration.
{% endif %}
{% endblock %}
PLEASE, PLEASE help me!!! I am dispairing!!!
Craphunter
For 1) you need to use a different form. Look in registration.forms for the one you need and pass it as an additional argument in the backend's urls.py
For 2) we'll need more info - is the URL correct? Is there a RegistrationProfile object created for the user account in question? What is the value of the key?