[finish #28524505] add change email form

pull/1/head
eric 2012-04-24 22:20:10 -04:00
parent 2a79a82dd7
commit d0148cf6dc
4 changed files with 57 additions and 19 deletions

View File

@ -97,6 +97,13 @@ class ProfileForm(forms.ModelForm):
'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):
username = forms.RegexField(
label=_("New Username"),

View File

@ -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

View File

@ -1,16 +1,26 @@
{% extends "registration/registration_base.html" %}
{% block title %}Change User Data{% endblock %}
{% 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>
<div>
<p> <b>Your current username:</b> {{ user.username }}</p>
<form method="POST" action="#">
{% csrf_token %}
{{ 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>
</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>
{% endblock %}

View File

@ -12,7 +12,6 @@ from re import sub
from itertools import islice
from decimal import Decimal as D
from xml.etree import ElementTree as ET
import requests
import oauth2 as oauth
from django import forms
@ -20,7 +19,6 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.comments import Comment
@ -29,6 +27,7 @@ from django.forms import Select
from django.forms.models import modelformset_factory
from django.http import HttpResponseRedirect, Http404
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.http import require_POST
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.translation import ugettext_lazy as _
from regluit.core import tasks
from regluit.core.tasks import send_mail_task
from regluit.core import models, bookloader, librarything
from regluit.core import userlists
from regluit.core.search import gluejar_search
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 ManageCampaignForm, DonateForm, CampaignAdminForm, EmailShareForm, FeedbackForm
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)
def edit_user(request):
form=UserData()
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
oldemail= request.user.email
if request.method == 'POST':
# surely there's a better way to add data to the POST data?
postcopy=request.POST.copy()
postcopy['oldusername']=oldusername
form = UserData(postcopy)
if form.is_valid(): # All validation rules pass, go and change the username
request.user.username=form.cleaned_data['username']
request.user.save()
return HttpResponseRedirect(reverse('home')) # Redirect after POST
return render(request,'registration/user_change_form.html', {'form': form},)
if 'change_username' in request.POST.keys():
# surely there's a better way to add data to the POST data?
postcopy=request.POST.copy()
postcopy['oldusername']=oldusername
form = UserData(postcopy)
if form.is_valid(): # All validation rules pass, go and change the username
request.user.username=form.cleaned_data['username']
request.user.save()
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):
@ -1601,7 +1616,7 @@ def emailshare(request):
message = form.cleaned_data['message']
sender = form.cleaned_data['sender']
recipient = form.cleaned_data['recipient']
send_mail(subject, message, sender, [recipient])
send_mail_task.delay(subject, message, sender, [recipient])
try:
next = form.cleaned_data['next']
except:
@ -1666,7 +1681,7 @@ def feedback(request):
else:
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
send_mail(subject, message, sender, [recipient])
send_mail_task.delay(subject, message, sender, [recipient])
return render(request, "thanks.html", {"page":page})