<commit_before>﻿/// <reference path="data-persister.js" />
define(["DataPersister", "htmlRenderer", "jquery"], function (DataPersister, htmlRenderer) {
    var controller = (function () {
        var persister = DataPersister.getDataPersister('http://localhost:1945/');
        var $main = $('#main');

        function attachEvents() {
            $main.on('click', '#login-user', loginUser);
            $main.on('click', '#login-admin', loginAdmin);
            $main.on('click', '#all-exams', renderAllExams);
            $main.on('click', "#register-btn", registerUser);
            $main.on('click', "#add-exam", addExam);
            $main.on('click', "#add-problem", addProblem);
            $main.on('click', "ul li a", showComments);

        }

        function Controller() {
        }

        function switchToLoginPage() {
            window.location.hash = '#/';
        }

        function registerUser(ev) {
            var $email = $('#email').val();
            var $password = $('#password').val();
            var $confirm = $('#confirm-password').val();
            if ($email === '' || $password === '' || $confirm === '') {
                alert("Username and password are required");
                ev.preventDefault();
                return;
            }
            persister.userPersister.register($email, $password, $confirm);
            switchToLoginPage();
        }

        function loginUser(ev) {
            var $email = $('#email').val();
            var $password = $('#password').val();
            if ($email === '' || $password === '') {
                alert("Username and password are required");
                ev.preventDefault();
                return;
            }

            persister.userPersister.login($email, $password).then(function () {
                window.location.hash = '#/UserHomepage';
                htmlRenderer.renderUsername(persister.userPersister.getUserName());
                renderAllExams();
            });
        }

        function loginAdmin(ev) {
            var $email = $('#email').val();
            var $password = $('#password').val();
            if ($email === '' || $password === '') {
                alert("Username and password are required");
                ev.preventDefault();
                return;
            }

            persister.adminPersister.login($email, $password);
            window.location.hash = '#/AdminHomepage';
            htmlRenderer.renderUsername(persister.adminPersister.getUserName());
            renderAllExams();
        }

        function addExam(){
            var $name = $('#exam-name').val();
            var $start = $('#start-time').val();
            var $end = $('#end-time').val();
            persister.userPersister.addExam($name, $start, $end).then(function(){<commit_msg>login fixed<commit_after>﻿/// <reference path="data-persister.js" />
define(["DataPersister", "htmlRenderer", "jquery"], function (DataPersister, htmlRenderer) {
    var controller = (function () {
        var persister = DataPersister.getDataPersister('http://localhost:1945/');
        var $main = $('#main');

        function attachEvents() {
            $main.on('click', '#login-user', loginUser);
            $main.on('click', '#login-admin', loginAdmin);
            $main.on('click', '#all-exams', renderAllExams);
            $main.on('click', "#register-btn", registerUser);
            $main.on('click', "#add-exam", addExam);
            $main.on('click', "#add-problem", addProblem);
            $main.on('click', "ul li a", showComments);

        }

        function Controller() {
        }

        function switchToLoginPage() {
            window.location.hash = '#/';
        }

        function registerUser(ev) {
            var $email = $('#email').val();
            var $password = $('#password').val();
            var $confirm = $('#confirm-password').val();
            if ($email === '' || $password === '' || $confirm === '') {
                alert("Username and password are required");
                ev.preventDefault();
                return;
            }
            persister.userPersister.register($email, $password, $confirm);
            switchToLoginPage();
        }

        function loginUser(ev) {
            var $email = $('#email').val();
            var $password = $('#password').val();
            if ($email === '' || $password === '') {
                alert("Username and password are required");
                ev.preventDefault();
                return;
            }

            $.ajax({url: "http://localhost:1945/Token",
                type: "POST",
                data: "userName=" + $email + "&password=" + $password + "&grant_type=password",
                success: function (data) {
                    localStorage.setItem("token", data.access_token);
                    window.location.hash = '#/UserHomepage';
                    renderAllExams();
                },
                error: function (errorData) {
                }
            });

//            persister.userPersister.login($email, $password).then(function () {
//                window.location.hash = '#/UserHomepage';
//                htmlRenderer.renderUsername(persister.userPersister.getUserName());
//                renderAllExams();
//            });
        }

        function loginAdmin(ev) {
            var $email = $('#email').val();
            var $password = $('#password').val();
            if ($email === '' || $password === '') {
                alert("Username and password are required");
                ev.preventDefault();
                return;
            }

            persister.adminPersister.login($email, $password);
            window.location.hash = '#/AdminHomepage';
            htmlRenderer.renderUsername(persister.adminPersister.getUserName());
            renderAllExams();
        }

        function addExam(){
            var $name = $('#exam-name').val();
            var $start = $('#start-time').val();
            var $end = $('#end-time').val();
            persister.userPersister.addExam($name, $start, $end).then(function(){
{'fraction_non_alphanumeric': 0.17068011714936543, 'fraction_numerical': 0.0019524894240156199, 'mean_word_length': 1.7979062357760582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6036630', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1527, 'n_words': 293}