def obj_create(self, bundle, **kwargs): required = ['username', ] check_required_params(bundle, required) bundle.obj.username = bundle.data['username'] try: user = User.objects.get(username__exact=bundle.obj.username) except User.DoesNotExist: try: user = User.objects.get(email__exact=bundle.obj.username) except User.DoesNotExist: raise BadRequest(_(u'Username/email not found')) newpass = User.objects.make_random_password(length=8) user.set_password(newpass) user.save() if bundle.request.is_secure(): prefix = 'https://' else: prefix = 'http://' emailer.send_oppia_email( template_html = 'profile/email/password_reset.html', template_text = 'profile/email/password_reset.txt', subject="Password reset", fail_silently=False, recipients=[user.email], new_password = newpass, site = prefix + bundle.request.META['SERVER_NAME'] ) return bundle
def reset(request): if request.method == 'POST': # if form submitted... form = ResetForm(request.POST) if form.is_valid(): username = form.cleaned_data.get("username") try: user = User.objects.get(username__exact=username) except User.DoesNotExist: user = User.objects.get(email__exact=username) newpass = User.objects.make_random_password(length=8) user.set_password(newpass) user.save() if request.is_secure(): prefix = 'https://' else: prefix = 'http://' emailer.send_oppia_email( template_html='profile/email/password_reset.html', template_text='profile/email/password_reset.txt', subject="Password reset", fail_silently=False, recipients=[user.email], new_password=newpass, site=prefix + request.META['SERVER_NAME']) return HttpResponseRedirect('sent') else: form = ResetForm() # An unbound form return render(request, 'common/form/form.html', { 'form': form, 'title': _(u'Reset password') })
def form_valid(self, form): response = super().form_valid(form) username = form.cleaned_data.get("username") try: user = User.objects.get(username__exact=username) except User.DoesNotExist: user = User.objects.get(email__exact=username) newpass = User.objects.make_random_password(length=8) user.set_password(newpass) user.save() if self.request.is_secure(): prefix = 'https://' else: prefix = 'http://' emailer.send_oppia_email( template_html='profile/email/password_reset.html', template_text='profile/email/password_reset.txt', subject="Password reset", fail_silently=False, recipients=[user.email], new_password=newpass, site=prefix + self.request.META['SERVER_NAME'] ) return response
def email_certificate(self, award): # check user has email address course = Course.objects.filter(awardcourse__award=award).first() if award.user.email and not award.emailed: emailer.send_oppia_email( template_html='emails/certificate_awarded.html', template_text='emails/certificate_awarded.txt', subject=_(u"Certificate Awarded"), fail_silently=False, recipients=[award.user.email], attachment_from_model=award.certificate_pdf.path, award=award, course=course) award.emailed = True award.save() else: emailer.send_oppia_email( template_html='emails/certificate_updated.html', template_text='emails/certificate_updated.txt', subject=_(u"Certificate updated"), fail_silently=False, recipients=[award.user.email], attachment_from_model=award.certificate_pdf.path, award=award, course=course) award.emailed = True award.save()
def reset(request): if request.method == 'POST': # if form submitted... form = ResetForm(request.POST) if form.is_valid(): username = form.cleaned_data.get("username") try: user = User.objects.get(username__exact=username) except User.DoesNotExist: user = User.objects.get(email__exact=username) newpass = User.objects.make_random_password(length=8) user.set_password(newpass) user.save() if request.is_secure(): prefix = 'https://' else: prefix = 'http://' emailer.send_oppia_email( template_html = 'oppia/profile/email/password_reset.html', template_text = 'oppia/profile/email/password_reset.txt', subject="Password reset", fail_silently=False, recipients=[user.email], new_password = newpass, site = prefix + request.META['SERVER_NAME'] ) return HttpResponseRedirect('sent') else: form = ResetForm() # An unbound form return render(request, 'oppia/form.html', {'form': form, 'title': _(u'Reset password')})
def obj_create(self, bundle, **kwargs): if 'email' not in bundle.data or len(bundle.data['email']) == 0: raise BadRequest(_(u'Email missing')) email = bundle.data['email'] user = User.objects.filter(email=email).first() if user is not None: emailer.send_oppia_email( template_html='emails/username_reminder.html', template_text='emails/username_reminder.txt', subject="Username reminder", fail_silently=False, recipients=[user.email], username=user.username, ) return bundle