Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def login(request):
- print("test")
- if request.method == 'POST':
- form = LoginForm(request.POST)
- if form.is_valid():
- username = form.cleaned_data['username']
- password = form.cleaned_data['password']
- user = authenticate(username=username, password=password)
- if user is not None:
- return HttpResponseRedirect('/accountManagement/home')
- else:
- form = LoginForm()
- else:
- HttpResponse("form is not valid")
- else:
- form = LoginForm()
- return render(request, 'accountManagement/login.html', {'form': form})
- def home(request):
- print(request.user.username)
- if request.user.is_authenticated:
- passwordForm = ChangePasswordForm()
- emailForm = ChangeEmailForm()
- return render(request, 'accountManagement/home.html', {'passwordForm': passwordForm, 'emailForm': emailForm})
- else:
- return HttpResponseRedirect("/accountManagement/")
- def change_password(request):
- if request.user.is_authenticated:
- if request.method == 'POST':
- passwordForm = ChangePasswordForm(request.POST)
- if passwordForm.is_valid():
- oldPassword = passwordForm.cleaned_data['oldPassword']
- newPassword = passwordForm.cleaned_data['newPassword']
- newPasswordConfirmation = passwordForm.cleaned_data['newPasswordConfirmation']
- if (newPassword == newPasswordConfirmation) and (request.user.check_password(oldPassword)):
- request.user.set_password(newPassword)
- request.user.save()
- return HttpResponseRedirect("/accountManagement/logout")
- else:
- return HttpResponse("password change failed")
- else:
- return HttpResponse("password form not valid")
- else:
- return HttpResponse("request != POST")
- else:
- return HttpResponse("user ist not authenticated")
- urlpatterns = [
- url(r'^$', views.login, name='login'),
- url(r'^home', views.home, name='home'),
- url(r'^changeEmail', views.change_email, name='changeEmail'),
- url(r'^changePassword', views.change_password, name='changePassword'),
- url(r'^logout', views.logout_view, name='logout'),
- ]
- class LoginForm(forms.Form):
- username = forms.CharField(label='Username', max_length=20)
- password = forms.CharField(label='Password', max_length=20)
- class ChangeEmailForm(forms.Form):
- newEmail = forms.CharField(label='New Email', max_length=50)
- class ChangePasswordForm(forms.Form):
- oldPassword = forms.CharField(label='Old Password', max_length=20)
- newPassword = forms.CharField(label='New Password', max_length=20)
- newPasswordConfirmation = forms.CharField(label='Confirm new Password', max_length=20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement