Exemple #1
0
def activate_discord(request):
    logger.debug("activate_discord called by user %s" % request.user)
    success = False
    if request.method == 'POST':
        logger.debug("Received POST request with form.")
        form = DiscordForm(request.POST)
        logger.debug("Form is valid: %s" % form.is_valid())
        if form.is_valid():
            email = form.cleaned_data['email']
            logger.debug("Form contains email address beginning with %s" % email[0:3])
            password = form.cleaned_data['password']
            logger.debug("Form contains password of length %s" % len(password))
            try:
                user_id = DiscordManager.add_user(email, password, request.user)
                logger.debug("Received discord uid %s" % user_id)
                if user_id != "":
                    AuthServicesInfoManager.update_user_discord_info(user_id, request.user)
                    logger.debug("Updated discord id %s for user %s" % (user_id, request.user))
                    update_discord_groups.delay(request.user.pk)
                    logger.debug("Updated discord groups for user %s." % request.user)
                    success = True
                    logger.info("Succesfully activated discord for user %s" % request.user)
                    return HttpResponseRedirect("/services/")
            except:
                logger.exception("An unhandled exception has occured.")
                pass
    else:
        logger.debug("Request is not type POST - providing empty form.")
        form = DiscordForm()

    logger.debug("Rendering form for user %s with success %s" % (request.user, success))
    context = {'form': form, 'success': success}
    return render_to_response('registered/discord.html', context, context_instance=RequestContext(request))
Exemple #2
0
def activate_discord(request):
    logger.debug("activate_discord called by user %s" % request.user)
    success = False
    if request.method == 'POST':
        logger.debug("Received POST request with form.")
        form = DiscordForm(request.POST)
        logger.debug("Form is valid: %s" % form.is_valid())
        if form.is_valid():
            email = form.cleaned_data['email']
            logger.debug("Form contains email address beginning with %s" % email[0:3])
            password = form.cleaned_data['password']
            try:
                user_id = DiscordManager.add_user(email, password, request.user)
                logger.debug("Received discord uid %s" % user_id)
                if user_id != "":
                    AuthServicesInfoManager.update_user_discord_info(user_id, request.user)
                    logger.debug("Updated discord id %s for user %s" % (user_id, request.user))
                    update_discord_groups(request.user)
                    logger.debug("Updated discord groups for user %s." % request.user)
                    success = True
                    logger.info("Succesfully activated discord for user %s" % request.user)
                    return HttpResponseRedirect("/services/")
            except:
                logger.exception("An unhandled exception has occured.", exc_info=True)
                pass
    else:
        logger.debug("Request is not type POST - providing empty form.")
        form = DiscordForm()

    logger.debug("Rendering form for user %s with success %s" % (request.user, success))
    context = {'form': form, 'success': success}
    return render_to_response('registered/discord.html', context, context_instance=RequestContext(request))
Exemple #3
0
def reset_discord(request):
    authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
    result = DiscordManager.delete_user(authinfo.discord_uid)
    if result:
        AuthServicesInfoManager.update_user_discord_info("",request.user)
        return HttpResponseRedirect("/activate_discord/")
    return HttpResponseRedirect("/services/")
Exemple #4
0
def deactivate_discord(request):
    authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
    result = DiscordManager.delete_user(authinfo.discord_uid)
    if result:
        remove_all_syncgroups_for_service(request.user, "discord")
        AuthServicesInfoManager.update_user_discord_info("", request.user)
        return HttpResponseRedirect("/services/")
    return HttpResponseRedirect("/dashboard")
Exemple #5
0
def reset_discord(request):
    logger.debug("reset_discord called by user %s" % request.user)
    authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
    result = DiscordManager.delete_user(authinfo.discord_uid)
    if result:
        AuthServicesInfoManager.update_user_discord_info("",request.user)
        logger.info("Succesfully deleted discord user for user %s - forwarding to discord activation." % request.user)
        return HttpResponseRedirect("/activate_discord/")
    logger.error("Unsuccessful attempt to reset discord for user %s" % request.user)
    return HttpResponseRedirect("/services/")
Exemple #6
0
def reset_discord(request):
    logger.debug("reset_discord called by user %s" % request.user)
    authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
    result = DiscordManager.delete_user(authinfo.discord_uid)
    if result:
        AuthServicesInfoManager.update_user_discord_info("",request.user)
        logger.info("Succesfully deleted discord user for user %s - forwarding to discord activation." % request.user)
        return HttpResponseRedirect("/activate_discord/")
    logger.error("Unsuccessful attempt to reset discord for user %s" % request.user)
    return HttpResponseRedirect("/services/")
Exemple #7
0
def deactivate_discord(request):
    logger.debug("deactivate_discord called by user %s" % request.user)
    authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
    result = DiscordManager.delete_user(authinfo.discord_uid)
    if result:
        remove_all_syncgroups_for_service(request.user, "discord")
        AuthServicesInfoManager.update_user_discord_info("", request.user)
        logger.info("Succesfully deactivated discord for user %s" % request.user)
        return HttpResponseRedirect("/services/")
    logger.error("Unsuccesful attempt to deactivate discord for user %s" % request.user)
    return HttpResponseRedirect("/dashboard")
Exemple #8
0
def deactivate_discord(request):
    logger.debug("deactivate_discord called by user %s" % request.user)
    authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
    result = DiscordManager.delete_user(authinfo.discord_uid)
    if result:
        remove_all_syncgroups_for_service(request.user, "discord")
        AuthServicesInfoManager.update_user_discord_info("", request.user)
        logger.info("Succesfully deactivated discord for user %s" %
                    request.user)
        return HttpResponseRedirect("/services/")
    logger.error("Unsuccesful attempt to deactivate discord for user %s" %
                 request.user)
    return HttpResponseRedirect("/dashboard")
Exemple #9
0
def activate_discord(request):
    success = False
    if request.method == 'POST':
        form = DiscordForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            try:
                user_id = DiscordManager.add_user(email, password)
                AuthServicesInfoManager.update_user_discord_info(user_id, request.user)
                update_discord_groups(request.user)
                success = True
                return HttpResponseRedirect("/services/")
            except:
                pass
    else:
        form = DiscordForm()

    context = {'form': form, 'success': success}
    return render_to_response('registered/discord.html', context, context_instance=RequestContext(request))