Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6c9cb54a

Přidáno uživatelem Jan Pašek před asi 4 roky(ů)

Re #8475 - Added code comments

Zobrazit rozdíly:

static/js/create_certificate.js
1

  
2
    // VUE instance of certificate creation page
1 3
    var createCertificateApp = new Vue({
2 4
            el: "#create-certificate-content",
3 5
            data: {
4
                authorities: [{id: 5, CN: "Test"}],
6
                // available certificate authorities
7
                authorities: [],
8
                // data of the selected certificate authorities to be displayed in the form
5 9
                selectedCAData: {
6 10
                    CN: "",
7 11
                    C:  "",
......
11 15
                    OU: "",
12 16
                    emailAddress: ""
13 17
                },
18
                // Data of the new certificate to be created received from the input fields
14 19
                certificateData: {
15 20
                    subject: {
16 21
                        CN: "",
......
32 37
                    CA: null
33 38
                }
34 39
            },
40
            // actions to be performed when the page is loaded
41
            // - initialize notBefore and notAfter with current date and current date + 1 month respectively
35 42
            mounted () {
36
              this.certificateData.notBefore = new Date().toDateInputValue();
43
              this.certificateData.notBefore = new Date().toDateInputValue(); // init notBefore to current date
37 44
              var endDate = new Date(new Date().getTime()+(30*24*60*60*1000));
38
              this.certificateData.notAfter = endDate.toDateInputValue();
45
              this.certificateData.notAfter = endDate.toDateInputValue(); // init notAfter to notBefore + 30 days
39 46
            },
40 47
            methods: {
48
                // handle certificate creation request
41 49
                onCreateCertificate: function () {
42

  
50
                    // validate input data
51
                    // - validate if subject CN is filled in
52
                    if(this.certificateData.subject.CN === "") {
53
                        alert("CN field must be filled in!"); // TODO highlight the field
54
                        return;
55
                    }
56
                    // - validate if notAfter is > notBefore
57
                    if(new Date(this.certificateData.notBefore) > new Date(this.certificateData.notAfter)) {
58
                        alert("notBefore must chronologically lower than notAfter"); // TODO highlight the field
59
                        return;
60
                    }
61
                    // send the request and handle response
43 62
                    axios.post(API_URL + "certificates", this.certificateData)
44 63
                        .then(function (response) {
64
                            // on success return to index page
45 65
                            if(response.data["success"]) {
46 66
                                alert("Certificate was successfully created.");
47 67
                                window.location.href = "/static/index.html";
48 68
                            }
69
                            // on error display server response message
49 70
                            else {
50 71
                                alert(response.data["data"]);
51 72
                            }
......
55 76
                        });
56 77
                }
57 78
            },
79
            // data watches
58 80
            watch: {
81
                // if the selected CA is changed, the Issuer input fileds must be filled in
59 82
                'certificateData.CA': function (val, oldVal) {
83
                    // self-signed certificate - all fields are empty
60 84
                    if (val === "null" || val == null) {
61 85
                        createCertificateApp.selectedCAData = {
62 86
                            CN: "",
......
68 92
                            emailAddress: ""
69 93
                        };
70 94
                    }
95
                    // a CA is selected - get CA's details and display them
71 96
                    else {
72 97
                        axios.get(API_URL + "certificates/" + val + "/details")
73 98
                            .then(function (response) {
......
85 110
            }
86 111
        });
87 112

  
113
    // Initialize available CA select values
88 114
    axios.get(API_URL+"certificates", {
89 115
            params: {
90 116
                filtering: {

Také k dispozici: Unified diff