<commit_before>// Dependencies
import React, { Component } from 'react';
import Card from './Card';
import Header from './Header';
import Content from './Content';
import Login from './Login';
import get from '../../utils/get';

class ProtoController extends Component {

    constructor(...args) {
        super(...args);
        this.writingAnimationFinished = this.writingAnimationFinished.bind(this);
        this.content = this.content.bind(this);
        this.authenticate = this.authenticate.bind(this);
        this.appGotAuthenticated = this.appGotAuthenticated.bind(this);

        this.state = {
            title: '<NAME>',
            navigation: [],
            expanded: true,
            needsAuthentication: false,
            authenticated: false,
        };

        this.authenticate();
    }

    writingAnimationFinished(event) {
        this.setState({
            expanded: false,
        });
    }

    /**
     * content - Return the content component used in a controller
     * @param {array} navItems - Navigation items
     * @param {object} routerParams - Router Params
     * @param {object} routerPath - Router Path
     * @return {object} - Content Component
     */
    content(navItems, routerParams, routerPath) {
        return (
            <Card>
                # This resource was not found
            </Card>
        );
    }

    /*
        The ProtoController's own authentication request
        If the user is already logged in, he won't see the login dialog
    */
    authenticate(event) {

        if (event) {
            if (event.authenticated) {
                this.appGotAuthenticated();
                this.setState({
                    authenticated: event.authenticated,
                });
                return;
            }
        }

        // Get the authorization status
        get('/auth/status', 'POST', {}, (err, response) => {
            if (!err) {
                response = JSON.parse(response);
                if (!this.state.authenticated) {
                    this.setState({
                        authenticated: response.authenticated,
                    });
                    this.appGotAuthenticated();
                }
            }
        });
    }

    /*
        The appGotAuthenticated method can be viewed as a second componentDidMount,
        but for being authenticated.
    */
    appGotAuthenticated(authenticated) {
        return authenticated;
    }

    render() {

        if (document) {
            document.title = this.state.title;
        }

        let content;
        if (!this.state.authenticated && this.state.needsAuthentication) {
            content = (
                <Content expanded={this.state.expanded}>
                    <Login onauthentication={this.authenticate}></Login>
                </Content>
            );
        } else {
            content = (
                <Content expanded={this.state.expanded}>
                    {this.content(this.state.navigation, this.props.params, this.props.route)}
                    <Card>
                        # Logout
                        <button><a href="/auth/logout">Log out</a></button>
                    </Card>
                </Content>
            );
        }
<commit_msg>Removed logout button if not logged in<commit_after>// Dependencies
import React, { Component } from 'react';
import Card from './Card';
import Header from './Header';
import Content from './Content';
import Login from './Login';
import get from '../../utils/get';

class ProtoController extends Component {

    constructor(...args) {
        super(...args);
        this.writingAnimationFinished = this.writingAnimationFinished.bind(this);
        this.content = this.content.bind(this);
        this.authenticate = this.authenticate.bind(this);
        this.appGotAuthenticated = this.appGotAuthenticated.bind(this);

        this.state = {
            title: '<NAME>',
            navigation: [],
            expanded: true,
            needsAuthentication: false,
            authenticated: false,
        };

        this.authenticate();
    }

    writingAnimationFinished(event) {
        this.setState({
            expanded: false,
        });
    }

    /**
     * content - Return the content component used in a controller
     * @param {array} navItems - Navigation items
     * @param {object} routerParams - Router Params
     * @param {object} routerPath - Router Path
     * @return {object} - Content Component
     */
    content(navItems, routerParams, routerPath) {
        return (
            <Card>
                # This resource was not found
            </Card>
        );
    }

    /*
        The ProtoController's own authentication request
        If the user is already logged in, he won't see the login dialog
    */
    authenticate(event) {

        if (event) {
            if (event.authenticated) {
                this.appGotAuthenticated();
                this.setState({
                    authenticated: event.authenticated,
                });
                return;
            }
        }

        // Get the authorization status
        get('/auth/status', 'POST', {}, (err, response) => {
            if (!err) {
                response = JSON.parse(response);
                if (!this.state.authenticated) {
                    this.setState({
                        authenticated: response.authenticated,
                    });
                    this.appGotAuthenticated();
                }
            }
        });
    }

    /*
        The appGotAuthenticated method can be viewed as a second componentDidMount,
        but for being authenticated.
    */
    appGotAuthenticated(authenticated) {
        return authenticated;
    }

    render() {

        if (document) {
            document.title = this.state.title;
        }

        let content;
        if (!this.state.authenticated && this.state.needsAuthentication) {
            content = (
                <Content expanded={this.state.expanded}>
                    <Login onauthentication={this.authenticate}></Login>
                </Content>
            );
        } else if (this.state.authenticated) {
            content = (
                <Content expanded={this.state.expanded}>
                    {this.content(this.state.navigation, this.props.params, this.props.route)}
                    <Card>
                        # Logout
                        <button><a href="/auth/logout">Log out</a></button>
                    </Card>
                </Content>
            );
        } else {
            content = (
                <Content expanded={this.state.expanded}>
                    {this.content(this.state.navigation, this.props.params, this.props.route)}
                </Content>
            );
        }

{'fraction_non_alphanumeric': 0.1093384074941452, 'fraction_numerical': 0.0, 'mean_word_length': 1.4919766593727206, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, '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': '5199234', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1655, 'n_words': 392}