예제 #1
0
def reset_password(request):
    args = PostParametersList(request)
    args.check_parameter(key='uid', required=True)
    args.check_parameter(key='token', required=True)
    args.check_parameter(key='password', required=True)
    check = PasswordToken.reset_password(args['uid'], args['token'],
                                         args['password'])

    if check:
        user = PasswordToken.validate_token(args['uid'], args['token'])
        return JsonResponse(1 if user and user.es_admin else 2, safe=False)
    else:
        raise APIExceptions.InvalidToken.set(
            detail="Reseteo de contraseña invalido")
def validate_password_token(request):
    args = PostParametersList(request)
    args.check_parameter(key='uid', required=True)
    args.check_parameter(key='token', required=True)
    user = PasswordToken.validate_token(args['uid'], args['token'])

    if user is None:
        raise APIExceptions.InvalidUIdToken
    else:
        return JsonResponse(1, safe=False)
예제 #3
0
def validate_password_token(request):
    """Valida los tokens de contraseña proporcionados.

    Args:
    request: API request.
    """
    args = verify_post_params(request, ['uid', 'token'])
    user = PasswordToken.validate_token(args['uid'], args['token'])

    if user is None:
        raise APIExceptions.InvalidUIdToken
    else:
        return JsonResponse(1, safe=False)
예제 #4
0
def reset_password(request):
    """Verificar que el reseteo de la contraseña sea válido.

    Si es así entonces manda un check, si no manda una excepción.

    Args:
    request: API request.
    """
    args = verify_post_params(request, ['uid', 'token', 'password'])
    check = PasswordToken.reset_password(args['uid'], args['token'],
                                         args['password'])

    if check:
        check.is_active = True
        check.save()
        return JsonResponse(1 if check and check.es_admin else 2, safe=False)
    else:
        raise APIExceptions.InvalidToken.set(
            detail="Reseteo de contraseña inválido")
예제 #5
0
def request_restore(request):
    args = PostParametersList(request)
    args.check_parameter(key='email', required=True)
    url_data = PasswordToken.request_uid_token(args['email'])

    try:
        send_mail(
            'Restablece tu contraseña',
            'STTE ITESM',
            "",
            [args['email']],
            html_message='<a href="http://127.0.0.1:3000/restaurar/' +
            str(url_data.uid) + '/' + url_data.token +
            '">Haz click aquí para restablecer tu contraseña</a>',
            fail_silently=False,
        )
    except:
        raise APIExceptions.SendMailError

    return JsonResponse(1, safe=False)
def request_restore(request):
    args = PostParametersList(request)
    args.check_parameter(key='email', required=True)
    url_data = PasswordToken.request_uid_token(args['email'])

    try:

        html_message = loader.render_to_string(
            '../templates/mailTemplate.html', {
                'user_name': "",
                'subject': 'Restablecer contraseña',
                'token': url_data.uid + "/" + url_data.token
            })
        send_mail('Restablece tu contraseña',
                  'STTE ITESM',
                  "", [args['email']],
                  html_message=html_message,
                  fail_silently=False)
    except:
        raise APIExceptions.SendMailError

    return JsonResponse(1, safe=False)
예제 #7
0
def request_restore(request):
    """Envía la respuesta html para restablecer la contraseña.

    Args:
    request: API request.
    """
    def _email_password_reset_plaintext(data):
        return ('Hola,\n\nEste mensaje es para restablecer tu contraseña. '
                'Si no solicitaste restablecer tu contraseña, ignora este '
                'mensaje.\n\nhttps://www.tramitesescolares.com.mx/'
                'restaurar/{0}').format(data)

    args = verify_post_params(request, ['email'])
    url_data = PasswordToken.request_uid_token(args['email'])
    try:
        send_mail('Restablece tu contraseña',
                  _email_password_reset_plaintext(url_data.uid + '/' +
                                                  url_data.token),
                  '*****@*****.**', [request.data['email']],
                  fail_silently=False)
    except:
        raise APIExceptions.SendMailError

    return JsonResponse(1, safe=False)