<commit_before>"use strict";

/* global Meteor,check,distUR,HTTP,EJSON,Mongo */

var jwt = Meteor.npmRequire("jsonwebtoken");

Meteor.methods({
    loginWithGithubAccount: function (username, password) {
        check(username, String);
        check(password, String);
        this.unblock();
        function notFounError() {
            throw new Meteor.Error("not-found", "Github User Not Found", "Github user " + username + "is not registered in distUR.net service. Please go to https://distUR.net, and register your account.");
        }
        var user = Meteor.users.findOne({ "services.github.username": username }, { _id: 1, "services.github.id": 1 });
        if (!user) {
            notFounError();
        }
        try {
            var result = HTTP.get("https://api.github.com/user", {
                auth: username + ":" + password
            });
            if (result.id !== user.services.github.id) {
                notFounError();
            }
            this.setUserId(user._id);
            // TODO: Return jwt token (with user's _id in it)
        }
        catch (e) {
            if (e.response && e.response.statusCode === 401) {
                throw new Meteor.Error("unauthorized", "Invalid Github Credentials", "Authentication failed, please review your Github credentials.");
            }
            else {
                throw new Meteor.Error("github-error", "Unknown Github Authentication Error", "Authentication failed bacause of an unknown Gihub error. Please retry later.");
            }
        }
    },
    distUrLogin: function (token) {
    }
});<commit_msg>auth methods implemented, Panky te meg kabe<commit_after>"use strict";

/* global Meteor,check,distUR,HTTP,EJSON,Mongo */

var jwt = Meteor.npmRequire("jsonwebtoken");
var jwtVerify = Async.wrap(jwt, "verify");

Meteor.methods({
    loginWithGithubAccount: function (username, password) {
        check(username, String);
        check(password, String);
        this.unblock();
        function notFounError() {
            throw new Meteor.Error("not-found", "Github User Not Found", "Github user " + username + "is not registered in distUR.net service. Please go to https://distUR.net, and register your account.");
        }
        var user = Meteor.users.findOne({ "services.github.username": username }, { _id: 1, "services.github.id": 1 });
        if (!user) {
            notFounError();
        }
        try {
            var result = HTTP.get("https://api.github.com/user", {
                auth: username + ":" + password
            });
            if (result.id !== user.services.github.id) {
                notFounError();
            }
            this.setUserId(user._id);
            return jwt.sign(user._id, user.services.github.id);
        }
        catch (e) {
            if (e.response && e.response.statusCode === 401) {
                throw new Meteor.Error("unauthorized", "Invalid Github Credentials", "Authentication failed, please review your Github credentials.");
            }
            else {
                throw new Meteor.Error("github-error", "Unknown Github Authentication Error", "Authentication failed bacause of an unknown Gihub error. Please retry later.");
            }
        }
    },
    distUrLogin: function (token) {
        try {
            var _id = jwtVerify(token);
            if (_.isString(_id) && Meteor.users.findOne({ _id: _id}, { _id: 1 })) {
                this.setUserId(_id);
            }
        }
        catch (e) {
            console.log(e.stack); // TODO: Log
        }
        throw new Meteor.Error("unauthorized", "Invalid Token");
    }
});
{'fraction_non_alphanumeric': 0.13166575041231446, 'fraction_numerical': 0.0030236393622869707, 'mean_word_length': 2.0451882845188285, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '6929085', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1005, 'n_words': 260}