<commit_before>'use strict';

import React from 'react';
import {Glyphicon} from 'react-bootstrap';
import superagent from 'superagent';

var conf = require('../config/config.js');
var styles = {
    position: 'fixed',
    right: 20,
    top: 10
};

class Login extends React.Component {
    constructor() {
        super();
        this.state = {};
        this.session();
    }

    session() {
        superagent.get(`${conf.login.url}/auth/session`)
            .withCredentials()
            .end((err, res) => {
                if (err) console.log('Could not get session', err);
                else if (res && res.status == 200 && res.body) {
                    return this.setState({
                        user: res.body.username
                    });
                }
                this.setState({
                    user: null
                });
            });
    }


    logout() {
        superagent.get(`${conf.login.url}/auth/logout`)
            .withCredentials()
            .end((err, res) => {
                if (err) console.error('Could not logout', err);
                if (res && res.status == 200) {
                    this.session();
                }
            })
    }

    render() {
        if (!conf.login) {
            return <div></div>
        }
        if (!this.state.user || this.state.user === 'anonymous') {
            return <div style={styles}><a
                href={`${conf.login.url}/auth/login?redirect=${conf.login.redirect}`}>Login</a></div>
        } else {
            return <div style={styles}>{this.state.user} (<a href="#" onClick={this.logout.bind(this)}>Logout</a>)</div>
        }
    }
}

export default Login;<commit_msg>fix login link<commit_after>'use strict';

import React from 'react';
import {Glyphicon} from 'react-bootstrap';
import superagent from 'superagent';

var conf = require('../config/config.js');
var styles = {
    position: 'fixed',
    right: 20,
    top: 10
};

class Login extends React.Component {
    constructor() {
        super();
        this.state = {};
        this.session();
    }

    session() {
        superagent.get(`${conf.login.url}/auth/session`)
            .withCredentials()
            .end((err, res) => {
                if (err) console.log('Could not get session', err);
                else if (res && res.status == 200 && res.body) {
                    return this.setState({
                        user: res.body.username
                    });
                }
                this.setState({
                    user: null
                });
            });
    }


    logout() {
        superagent.get(`${conf.login.url}/auth/logout`)
            .withCredentials()
            .end((err, res) => {
                if (err) console.error('Could not logout', err);
                if (res && res.status == 200) {
                    this.session();
                }
            })
    }

    render() {
        if (!conf.login) {
            return <div></div>
        }
        if (!this.state.user || this.state.user === 'anonymous') {
            return <div style={styles}><a
                href={`${conf.login.url}/auth/login?continue=${conf.login.redirect}`}>Login</a></div>
        } else {
            return <div style={styles}>{this.state.user} (<a href="#" onClick={this.logout.bind(this)}>Logout</a>)</div>
        }
    }
}

export default Login;
{'fraction_non_alphanumeric': 0.16063548102383055, 'fraction_numerical': 0.005884083553986467, 'mean_word_length': 1.5018395879323032, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '5289662', 'n_tokens_mistral': 993, 'n_tokens_neox': 943, 'n_words': 195}