def post(self, request): lenguaje(request) form = self.form(request.POST or None) context = {'form': form} if form.is_valid(): try: a = self.model.objects.get(login=form.cleaned_data['login']) except Account.DoesNotExist: context.update({'key': _('Cuenta no existe.')}) return render(request, self.template_name, context) b = datetime.datetime( 2009, 1, 1, 0, 0, ) if a.availdt.year == b.year and a.availdt.month == b.month: context.update({ 'key': _('Tu cuenta ya esta activada'), }) return render(request, self.template_name, context) if a.status != 'OK': context.update({'key': _('Tu cuenta esta baneada')}) return render(request, self.template_name, context) if form.cleaned_data['email'] == a.email: key = aleatorio(40) a.address = key a.save() try: send_mail(_('Activacion de cuentas ') + settings.SERVERNAME, 'Content', settings.EMAIL_HOST_USER, [a.email], html_message=get_mail_register(a.login, key)) except: context.update( {'key': _('Error enviando correo al usuario')}) return render(request, self.template_name, context) context.update({ 'key': _('Se ha enviado el codigo de activacion al email') }) return render(request, self.template_name, context) else: context.update( {'key': _('El email no coincide con el usuario')}) return render(request, self.template_name, context) else: context.update({ 'key': _('Por favor rellena todos los campos correctamente.') }) return render(request, self.template_name, context)
def send_confirmation_email(self, key): try: send_mail( _('Bienvenido a ') + settings.SERVERNAME, settings.EMAIL_HOST_USER, [self.email], html_message=get_mail_register(self.login, key), ) except Exception as err: print(err)
def form_valid(self, form): key = aleatorio(40) self.object = form.save(commit=False) new_password = self.object.micryp(self.object.password) self.object.password = new_password self.object.address = key self.object.save() try: send_mail( _('Bienvenido a ') + settings.SERVERNAME, 'Content', settings.EMAIL_HOST_USER, [self.object.email], html_message=get_mail_register(self.object.login, key), ) except Exception as err: raise SendMailException(err) return HttpResponseRedirect(self.get_success_url())