[finish #28524505] add change email form
parent
2a79a82dd7
commit
d0148cf6dc
|
@ -97,6 +97,13 @@ class ProfileForm(forms.ModelForm):
|
||||||
'tagline': forms.Textarea(attrs={'rows': 5, 'onKeyUp': "counter(this, 140)", 'onBlur': "counter(this, 140)"}),
|
'tagline': forms.Textarea(attrs={'rows': 5, 'onKeyUp': "counter(this, 140)", 'onBlur': "counter(this, 140)"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UserEmail(forms.Form):
|
||||||
|
email = forms.EmailField(
|
||||||
|
label=_("new email address"),
|
||||||
|
max_length=100,
|
||||||
|
error_messages={'required': 'Please enter an email address.'},
|
||||||
|
)
|
||||||
|
|
||||||
class UserData(forms.Form):
|
class UserData(forms.Form):
|
||||||
username = forms.RegexField(
|
username = forms.RegexField(
|
||||||
label=_("New Username"),
|
label=_("New Username"),
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
The email address for your unglue.it accound has been changed from {{oldemail}} to {{request.user.email}}.
|
||||||
|
|
||||||
|
If there's any reason that this is in error, please contact us at support@gluejar.com
|
||||||
|
|
||||||
|
Sincerely,
|
||||||
|
The unglue.it Team
|
|
@ -1,16 +1,26 @@
|
||||||
{% extends "registration/registration_base.html" %}
|
{% extends "registration/registration_base.html" %}
|
||||||
{% block title %}Change User Data{% endblock %}
|
{% block title %}Change User Data{% endblock %}
|
||||||
{% block doccontent %}
|
{% block doccontent %}
|
||||||
<h1>Changing Your Username</h1>
|
<h2>Changing Your Username</h2>
|
||||||
|
|
||||||
<p> If you change your username, the web address for your profile page will change as well.</p>
|
<p> If you change your username, the web address for your profile page will change as well.</p>
|
||||||
|
<div>
|
||||||
<p> <b>Your current username:</b> {{ user.username }}</p>
|
<p> <b>Your current username:</b> {{ user.username }}</p>
|
||||||
<form method="POST" action="#">
|
<form method="POST" action="#">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<input type="submit" name="submit" value="Change username" id="submit">
|
<input type="submit" name="change_username" value="Change username" id="submit_username">
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2>Changing Your Email</h2>
|
||||||
|
<p> <b>Your current email:</b> {{ user.email }}</p>
|
||||||
|
<form method="POST" action="#">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ emailform.as_p }}
|
||||||
|
<input type="submit" name="change_email" value="Change email" id="submit_email">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<p>Want to <a href="/accounts/password/change/">change your password</a> instead?</p>
|
<p>Want to <a href="/accounts/password/change/">change your password</a> instead?</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ from re import sub
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
from decimal import Decimal as D
|
from decimal import Decimal as D
|
||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import oauth2 as oauth
|
import oauth2 as oauth
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -20,7 +19,6 @@ from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.mail import send_mail
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.comments import Comment
|
from django.contrib.comments import Comment
|
||||||
|
@ -29,6 +27,7 @@ from django.forms import Select
|
||||||
from django.forms.models import modelformset_factory
|
from django.forms.models import modelformset_factory
|
||||||
from django.http import HttpResponseRedirect, Http404
|
from django.http import HttpResponseRedirect, Http404
|
||||||
from django.http import HttpResponse, HttpResponseNotFound
|
from django.http import HttpResponse, HttpResponseNotFound
|
||||||
|
from django.template.loader import render_to_string
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic.edit import FormView
|
||||||
|
@ -38,11 +37,12 @@ from django.shortcuts import render, render_to_response, get_object_or_404
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from regluit.core import tasks
|
from regluit.core import tasks
|
||||||
|
from regluit.core.tasks import send_mail_task
|
||||||
from regluit.core import models, bookloader, librarything
|
from regluit.core import models, bookloader, librarything
|
||||||
from regluit.core import userlists
|
from regluit.core import userlists
|
||||||
from regluit.core.search import gluejar_search
|
from regluit.core.search import gluejar_search
|
||||||
from regluit.core.goodreads import GoodreadsClient
|
from regluit.core.goodreads import GoodreadsClient
|
||||||
from regluit.frontend.forms import UserData, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm
|
from regluit.frontend.forms import UserData, UserEmail, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm
|
||||||
from regluit.frontend.forms import RightsHolderForm, UserClaimForm, LibraryThingForm, OpenCampaignForm
|
from regluit.frontend.forms import RightsHolderForm, UserClaimForm, LibraryThingForm, OpenCampaignForm
|
||||||
from regluit.frontend.forms import ManageCampaignForm, DonateForm, CampaignAdminForm, EmailShareForm, FeedbackForm
|
from regluit.frontend.forms import ManageCampaignForm, DonateForm, CampaignAdminForm, EmailShareForm, FeedbackForm
|
||||||
from regluit.frontend.forms import EbookForm, CustomPremiumForm, EditManagersForm
|
from regluit.frontend.forms import EbookForm, CustomPremiumForm, EditManagersForm
|
||||||
|
@ -1089,20 +1089,35 @@ def supporter(request, supporter_username, template_name):
|
||||||
return render(request, template_name, context)
|
return render(request, template_name, context)
|
||||||
|
|
||||||
def edit_user(request):
|
def edit_user(request):
|
||||||
form=UserData()
|
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse('auth_login'))
|
return HttpResponseRedirect(reverse('auth_login'))
|
||||||
|
form=UserData()
|
||||||
|
emailform = UserEmail({'email':request.user.email})
|
||||||
oldusername=request.user.username
|
oldusername=request.user.username
|
||||||
|
oldemail= request.user.email
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# surely there's a better way to add data to the POST data?
|
if 'change_username' in request.POST.keys():
|
||||||
postcopy=request.POST.copy()
|
# surely there's a better way to add data to the POST data?
|
||||||
postcopy['oldusername']=oldusername
|
postcopy=request.POST.copy()
|
||||||
form = UserData(postcopy)
|
postcopy['oldusername']=oldusername
|
||||||
if form.is_valid(): # All validation rules pass, go and change the username
|
form = UserData(postcopy)
|
||||||
request.user.username=form.cleaned_data['username']
|
if form.is_valid(): # All validation rules pass, go and change the username
|
||||||
request.user.save()
|
request.user.username=form.cleaned_data['username']
|
||||||
return HttpResponseRedirect(reverse('home')) # Redirect after POST
|
request.user.save()
|
||||||
return render(request,'registration/user_change_form.html', {'form': form},)
|
return HttpResponseRedirect(reverse('home')) # Redirect after POST
|
||||||
|
elif 'change_email' in request.POST.keys():
|
||||||
|
emailform = UserEmail(request.POST)
|
||||||
|
if emailform.is_valid():
|
||||||
|
request.user.email=emailform.cleaned_data['email']
|
||||||
|
request.user.save()
|
||||||
|
send_mail_task.delay(
|
||||||
|
'unglue.it email changed',
|
||||||
|
render_to_string('registration/email_changed.txt',{'oldemail':oldemail,'request':request}),
|
||||||
|
None,
|
||||||
|
[request.user.email,oldemail]
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(reverse('home')) # Redirect after POST
|
||||||
|
return render(request,'registration/user_change_form.html', {'form': form,'emailform': emailform})
|
||||||
|
|
||||||
|
|
||||||
def search(request):
|
def search(request):
|
||||||
|
@ -1601,7 +1616,7 @@ def emailshare(request):
|
||||||
message = form.cleaned_data['message']
|
message = form.cleaned_data['message']
|
||||||
sender = form.cleaned_data['sender']
|
sender = form.cleaned_data['sender']
|
||||||
recipient = form.cleaned_data['recipient']
|
recipient = form.cleaned_data['recipient']
|
||||||
send_mail(subject, message, sender, [recipient])
|
send_mail_task.delay(subject, message, sender, [recipient])
|
||||||
try:
|
try:
|
||||||
next = form.cleaned_data['next']
|
next = form.cleaned_data['next']
|
||||||
except:
|
except:
|
||||||
|
@ -1666,7 +1681,7 @@ def feedback(request):
|
||||||
else:
|
else:
|
||||||
ungluer = request.user.username
|
ungluer = request.user.username
|
||||||
message = "<<<This feedback is about "+page+". Original user message follows\nfrom "+sender+", ungluer name "+ungluer+"\nwith user agent "+useragent+"\n>>>\n"+message
|
message = "<<<This feedback is about "+page+". Original user message follows\nfrom "+sender+", ungluer name "+ungluer+"\nwith user agent "+useragent+"\n>>>\n"+message
|
||||||
send_mail(subject, message, sender, [recipient])
|
send_mail_task.delay(subject, message, sender, [recipient])
|
||||||
|
|
||||||
return render(request, "thanks.html", {"page":page})
|
return render(request, "thanks.html", {"page":page})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue