def change_password(request): # chacking uselogin pcode = request.GET.get('auto', False) username = request.GET.get('username', False) nextUrl = request.GET.get('next', False) # check pcode in profile page if pcode and username and nextUrl: user = User.objects.get(username=username) profile = Profile.objects.get(user=user) if profile.confirmation_code == pcode: user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) if request.user.is_anonymous(): return HttpResponseRedirect( '/accounts/login/?next=/accounts/change-password') context = {} form = ChangePasswordForm() if request.method == "POST": form = ChangePasswordForm(request.POST) if form.is_valid(): profile = Profile.objects.get( user_id=form.cleaned_data['userid'], confirmation_code=form.cleaned_data['code']) user = profile.user user.set_password(form.cleaned_data['new_password']) user.save() # change if any mdl user pass too from mdldjango.views import changeMdlUserPass changeMdlUserPass(user.email, form.cleaned_data['new_password']) if nextUrl: return HttpResponseRedirect(nextUrl.split("?", 1)[0]) messages.success( request, "Your account password has been updated successfully!") return HttpResponseRedirect("/accounts/view-profile/" + user.username) context['form'] = form context.update(csrf(request)) return render(request, 'cms/templates/change_password.html', context)
def change_password(request): # chacking uselogin pcode = request.GET.get('auto', False) username = request.GET.get('username', False) nextUrl = request.GET.get('next', False) # check pcode in profile page if pcode and username and nextUrl: user = User.objects.get(username=username) profile = Profile.objects.get(user=user) if profile.confirmation_code == pcode: user.backend='django.contrib.auth.backends.ModelBackend' login(request,user) if request.user.is_anonymous(): return HttpResponseRedirect('/accounts/login/?next=/accounts/change-password') context = {} form = ChangePasswordForm() if request.method == "POST": form = ChangePasswordForm(request.POST) if form.is_valid(): profile = Profile.objects.get(user_id = form.cleaned_data['userid'], confirmation_code = form.cleaned_data['code']) user = profile.user user.set_password(form.cleaned_data['new_password']) user.save() # change if any mdl user pass too from mdldjango.views import changeMdlUserPass changeMdlUserPass(user.email, form.cleaned_data['new_password']) if nextUrl: return HttpResponseRedirect(nextUrl.split("?", 1)[0]) messages.success(request, "Your account password has been updated successfully!") return HttpResponseRedirect("/accounts/view-profile/" + user.username) context['form'] = form context.update(csrf(request)) return render(request, 'cms/templates/change_password.html', context)
def password_reset(request): context = {} form = PasswordResetForm() if request.method == "POST": form = PasswordResetForm(request.POST) if form.is_valid(): password_string = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) user = User.objects.filter(email=request.POST['email']).first() user.set_password(password_string) user.save() # change if any mdl user pass too from mdldjango.views import changeMdlUserPass changeMdlUserPass(request.POST['email'], password_string) print 'Username => ', user.username print 'New password => ', password_string changePassUrl = "http://www.spoken-tutorial.org/accounts/change-password" if request.GET and request.GET['next']: changePassUrl = changePassUrl + "?auto=%s&username=%s&next=%s" % (user.profile_set.first().confirmation_code, user.username, request.GET['next']) #Send email subject = "Spoken Tutorial password reset" to = [user.email] message = '''Hi {0}, Your account password at 'Spoken Tutorials' has been reset and you have been issued with a new temporary password. Your current login information is now: username: {1} password: {2} With respect to change your password kindly follow the steps written below : Step 1. Visit below link to change the password. Provide temporary password given above in the place of Old Password field. {3} Step 2.Use this changed password for spoken forum login and in moodle login also. In most mail programs, this should appear as a blue link which you can just click on. If that doesn't work, then cut and paste the address into the address line at the top of your web browser window. Best Wishes, Admin Spoken Tutorials IIT Bombay. '''.format(user.username, user.username, password_string,changePassUrl) # send email email = EmailMultiAlternatives( subject, message, '*****@*****.**', to = to, bcc = [], cc = [], headers={'Reply-To': '*****@*****.**', "Content-type":"text/html;charset=iso-8859-1"} ) result = email.send(fail_silently=False) # redirect to next url if there or redirect to login page # use for forum password rest form redirectNext = request.GET.get('next', False) if redirectNext: return HttpResponseRedirect(redirectNext) messages.success(request, "New password sent to your email "+user.email) return HttpResponseRedirect('/accounts/change-password/') context = { 'form': form } context.update(csrf(request)) return render(request, 'cms/templates/password_reset.html', context)
def password_reset(request): context = {} form = PasswordResetForm() if request.method == "POST": form = PasswordResetForm(request.POST) if form.is_valid(): password_string = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) user = User.objects.filter(email=request.POST['email']).first() user.set_password(password_string) user.save() # change if any mdl user pass too from mdldjango.views import changeMdlUserPass changeMdlUserPass(request.POST['email'], password_string) print(('Username => ', user.username)) print(('New password => ', password_string)) changePassUrl = "http://www.spoken-tutorial.org/accounts/change-password" if request.GET and request.GET['next']: changePassUrl = changePassUrl + "?auto=%s&username=%s&next=%s" % (user.profile_set.first().confirmation_code, user.username, request.GET['next']) #Send email subject = "Spoken Tutorial password reset" to = [user.email] message = '''Hi {0}, Your account password at 'Spoken Tutorials' has been reset and you have been issued with a new temporary password. Your current login information is now: username: {1} password: {2} With respect to change your password kindly follow the steps written below : Step 1. Visit below link to change the password. Provide temporary password given above in the place of Old Password field. {3} Step 2.Use this changed password for spoken forum login and in moodle login also. In most mail programs, this should appear as a blue link which you can just click on. If that doesn't work, then cut and paste the address into the address line at the top of your web browser window. Best Wishes, Admin Spoken Tutorials IIT Bombay. '''.format(user.username, user.username, password_string,changePassUrl) # send email email = EmailMultiAlternatives( subject, message, '*****@*****.**', to = to, bcc = [], cc = [], headers={'Reply-To': '*****@*****.**', "Content-type":"text/html;charset=iso-8859-1"} ) result = email.send(fail_silently=False) # redirect to next url if there or redirect to login page # use for forum password rest form redirectNext = request.GET.get('next', False) if redirectNext: return HttpResponseRedirect(redirectNext) messages.success(request, "New password sent to your email "+user.email) return HttpResponseRedirect('/accounts/change-password/') context = { 'form': form } context.update(csrf(request)) return render(request, 'cms/templates/password_reset.html', context)