Example #1
0
def process_reg(request, url):
    lenguaje(request)
    # Preparando el contexto usado por la funcion
    context = {}
    if request.method == 'GET':
        if url:
            try:
                a = Account.objects.get(address=url)
            except Account.DoesNotExist:
                context.update({'key': _('El token que intentas usar no existe.')})
                return render(request, 'account/activar_cuenta.html', context)
            if a.status == 'OK':
                b = datetime.datetime(2009, 1, 1, 0, 0,)
                if a.availdt.year == b.year and a.availdt.month == b.month:
                    a.address = aleatorio(40)
                    a.save()
                    context.update({'key': _('Tu cuenta ya esta activada')})
                    return render(request, 'account/activar_cuenta.html', context )
                else:
                    a.availdt = "2009-01-01T00:00:00"
                    a.address = aleatorio(40)
                    a.save()

                    context.update({'key': _('Tu cuenta se ha activado correctamente')})
                    return render(request, 'account/activar_cuenta.html', context )
            else:
                context.update({'key': _('Tu cuenta esta baneada')})
                return render(request, 'account/activar_cuenta.html', context )
        else:
            context.update({'key': _('No has enviado ningun token')})
            return render(request, 'account/activar_cuenta.html', context)
    else:
        context.update({'key': _('Metodo no admitido')})
        return render(request, 'account/activar_cuenta.html', context)
Example #2
0
    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 create(self, validated_data):
     cuenta = Account.objects.create(**validated_data)
     cuenta.address = aleatorio(40)
     cuenta.save()
     self.send_confirmation_email(cuenta.address)
     return {
         'login': validated_data['login'],
         'password': '******',
         'real_name': validated_data['real_name'],
         'email': validated_data['email'],
         'social_id': validated_data['social_id']
     }
Example #4
0
def recuperar_password(request):
    lenguaje(request)
    # Declarando el formulario
    form = ResPassword(request.POST or None)
    # Preparando el contexto que manajara la funcion
    context = {'form': form}
    # validando los datos que se envian por post
    if request.method == 'POST' and form.is_valid():
        a = request.POST['login']
        b = request.POST['email']
        try:
            usuario = Account.objects.get(login=a)
        except Account.DoesNotExist:
            context.update({
                'key':
                _('No se encuentran registros en nuestra base de datos')
            })
            return render(request, 'account/rescue.html', context)

        if usuario.email == b:
            key = aleatorio(40)
            usuario.address = key
            usuario.token_expire = timezone.now()
            usuario.save()
            try:
                send_mail(
                    _('Recuperar password'),
                    'Content',
                    settings.EMAIL_HOST_USER,
                    [usuario.email],
                    html_message=get_mail(usuario.real_name, key),
                )

                context.update({
                    'key':
                    _('se ha enviado un correo electronico con las instrucciones '
                      'para recupear el password')
                })
                return render(request, 'account/rescue.html', context)
            except:
                context.update({'key': _('Error enviando el correo')})
                return render(request, 'account/rescue.html', context)
        else:
            context.update({
                'key':
                _('El usuario no concuerda con el correo electronico')
            })
            return render(request, 'account/rescue.html', context)
    else:
        context.update({'key': ''})
        return render(request, 'account/rescue.html', context)
Example #5
0
 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())
Example #6
0
def process_password(request, url):
    lenguaje(request)
    # Declarando el formulario
    form = FormResetPassword(request.POST or None)
    # Preparando el contexto de la funcion
    context = {}
    if request.method == 'GET':
        if url:
            try:
                a = Account.objects.get(address=url)
            except Account.DoesNotExist:
                context.update({
                    'key': _('El token que intentas usar no existe'),
                    'if_form': False
                })
                return render(request, 'account/cambio_passwd.html', context)
            z = (timezone.now() - a.token_expire).days
            if z >= 1:
                context.update({
                    'key': _('El token que intentas usar esta vencido'),
                    'if_form': False
                })
                return render(request, 'account/cambio_passwd.html', context)
            else:
                request.session['tmp_id'] = a.id
                context.update({
                    'key': _('ingresa tu nuevo password'),
                    'form': form,
                    'if_form': True
                })
                return render(request, 'account/cambio_passwd.html', context)
        else:
            context.update({
                'key': _('No has enviado ningun token'),
                'if_form': False
            })
            return render(request, 'account/cambio_passwd.html', context)
    if request.method == 'POST':
        password = request.POST['password']
        password_again = request.POST['password_again']
        if password == password_again and form.is_valid():
            if 'tmp_id' in request.session:
                try:
                    a = Account.objects.get(id=request.session['tmp_id'])
                except Account.DoesNotExist:
                    context.update({
                        'key': _('No se encuentra el usuario'),
                        'if_form': False
                    })
                    return render(request, 'account/cambio_passwd.html', context)
                a.password = a.micryp(password)
                a.address = aleatorio(40)
                a.save()
                del request.session['tmp_id']
                context.update({
                    'key': _('Password actualizado correctamente'),
                    'if_form': False
                })
                return render(request, 'account/cambio_passwd.html', context)
            else:
                context.update({
                    'key': _('No existe la session temporal'),
                    'if_form': False
                })
                return render(request, 'account/cambio_passwd.html', context )
        else:
            context.update({
                'if_form': True,
                'key':_('Los password no coinciden')
            })
            return render(request, 'account/cambio_passwd.html', context)
Example #7
0
 def set_key(self):
     self.address = aleatorio(40)