<commit_before>function ContactViewModel() {
    var self = this;

    self.state = ko.observable('contacts');

    self.show_login_error = ko.observable(false);


    self.user_data = ko.observable();
    self.requests = ko.observable([]);

    self.requests_displayed = false;
    self.anonymous_user = ko.observable(true);

    self.authenticated_user = ko.computed(function() {
        return !self.anonymous_user();
    })

    self.toggleRequestsDisplay = function() {
        if (self.requests_displayed) {
            // hide requests
            self.requests([]);
            self.requests_displayed = false
        } else {
            $.getJSON('/requests/', function(response) {
                self.requests(response.data);
                self.requests_displayed = true;
            });
        }
    }

    self.showLoginForm = function() {
        location.hash = '#/login';
    }

    self.showEditForm = function() {
        location.hash = '#/edit';
    }

    self.showEditForm = function() {
        location.hash = '#/edit';
    }

    self.makeLogout = function() {
        location.hash = '#/do-logout';
    }

    $.getJSON('/contact/', function(data) {
        self.user_data(data)
        self.anonymous_user(!data.is_logged_in)
        console.log('Anonymous user: ' + self.anonymous_user())
    });

    // Client-side routes
    Sammy(function () {
        this.route('get', '#/', function() {
           $.getJSON('/contact/', function(data) {
               self.user_data(data)
               self.anonymous_user(!data.is_logged_in)
               self.state('contacts')
           });
        });
        this.get('#/login', function() {
           self.state('login-form')
        });

        this.get('#/edit', function() {
           self.state('edit-form')
        });

        this.get('#/do-logout', function() {
            $.getJSON('/contact/logout', function(response) {
                self.anonymous_user(!response.is_logged_in)
            })
        });

        this.post('#/do-login', function(context) {
            $.ajax({
                type: 'POST',
                url: '/contact/login/',
                data: JSON.stringify({
                    'username': context.params.username,
                    'password': context.params.password}),
                contentType: 'application/json',
                dataType: 'json',
                success: function(data) {
                    location.hash = '/'
                    self.show_login_error(false)
                    if (!data.is_logged_in) {
                        self.show_login_error(true)
                    } else {
                        self.anonymous_user(!data.is_logged_in)
                    }
                },
                error: function(data) {
                    self.show_login_error(true)
                }
            })

        });
    }).run();

}


ko.applyBindings(new ContactViewModel())
<commit_msg>#5 added redirect after logout<commit_after>function ContactViewModel() {
    var self = this;

    self.state = ko.observable('contacts');

    self.show_login_error = ko.observable(false);


    self.user_data = ko.observable();
    self.requests = ko.observable([]);

    self.requests_displayed = false;
    self.anonymous_user = ko.observable(true);

    self.authenticated_user = ko.computed(function() {
        return !self.anonymous_user();
    })

    self.toggleRequestsDisplay = function() {
        if (self.requests_displayed) {
            // hide requests
            self.requests([]);
            self.requests_displayed = false
        } else {
            $.getJSON('/requests/', function(response) {
                self.requests(response.data);
                self.requests_displayed = true;
            });
        }
    }

    self.showLoginForm = function() {
        location.hash = '#/login';
    }

    self.showEditForm = function() {
        location.hash = '#/edit';
    }

    self.showEditForm = function() {
        location.hash = '#/edit';
    }

    self.makeLogout = function() {
        location.hash = '#/do-logout';
    }

    $.getJSON('/contact/', function(data) {
        self.user_data(data)
        self.anonymous_user(!data.is_logged_in)
        console.log('Anonymous user: ' + self.anonymous_user())
    });

    // Client-side routes
    Sammy(function () {
        this.route('get', '#/', function() {
           $.getJSON('/contact/', function(data) {
               self.user_data(data)
               self.anonymous_user(!data.is_logged_in)
               self.state('contacts')
           });
        });
        this.get('#/login', function() {
           self.state('login-form')
        });

        this.get('#/edit', function() {
           self.state('edit-form')
        });

        this.get('#/do-logout', function() {
            $.getJSON('/contact/logout', function(response) {
                self.anonymous_user(!response.is_logged_in)
                redirect('#/');
            })
        });

        this.post('#/do-login', function(context) {
            $.ajax({
                type: 'POST',
                url: '/contact/login/',
                data: JSON.stringify({
                    'username': context.params.username,
                    'password': <PASSWORD>}),
                contentType: 'application/json',
                dataType: 'json',
                success: function(data) {
                    location.hash = '/'
                    self.show_login_error(false)
                    if (!data.is_logged_in) {
                        self.show_login_error(true)
                    } else {
                        self.anonymous_user(!data.is_logged_in)
                    }
                },
                error: function(data) {
                    self.show_login_error(true)
                }
            })

        });
    }).run();

}


ko.applyBindings(new ContactViewModel())

{'fraction_non_alphanumeric': 0.14160780356542213, 'fraction_numerical': 0.00016818028927009755, 'mean_word_length': 1.5317156236696468, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '89905', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1617, 'n_words': 229}