Projekt

Obecné

Profil

Stáhnout (3.82 KB) Statistiky
| Větev: | Tag: | Revize:
1
    var createCertificateApp = new Vue({
2
            el: "#create-certificate-content",
3
            data: {
4
                authorities: [{id: 5, CN: "Test"}],
5
                selectedCAData: {
6
                    CN: "",
7
                    C:  "",
8
                    L:  "",
9
                    ST: "",
10
                    O:  "",
11
                    OU: "",
12
                    emailAddress: ""
13
                },
14
                certificateData: {
15
                    subject: {
16
                        CN: "",
17
                        C: "",
18
                        L: "",
19
                        ST: "",
20
                        O: "",
21
                        OU: "",
22
                        emailAddress: ""
23
                    },
24
                    notBefore: "",
25
                    notAfter: "",
26
                    usage: {
27
                        CA: false,
28
                        authentication: false,
29
                        digitalSignature: false,
30
                        SSL: false
31
                    },
32
                    CA: null
33
                }
34
            },
35
            mounted () {
36
              this.certificateData.notBefore = new Date().toDateInputValue();
37
              var endDate = new Date(new Date().getTime()+(30*24*60*60*1000));
38
              this.certificateData.notAfter = endDate.toDateInputValue();
39
            },
40
            methods: {
41
                onCreateCertificate: function () {
42

    
43
                    axios.post(API_URL + "certificates", this.certificateData)
44
                        .then(function (response) {
45
                            if(response.data["success"]) {
46
                                alert("Certificate was successfully created.");
47
                                window.location.href = "/static/index.html";
48
                            }
49
                            else {
50
                                alert(response.data["data"]);
51
                            }
52
                        })
53
                        .catch(function (error) {
54
                            console.log(error);
55
                        });
56
                }
57
            },
58
            watch: {
59
                'certificateData.CA': function (val, oldVal) {
60
                    if (val === "null" || val == null) {
61
                        createCertificateApp.selectedCAData = {
62
                            CN: "",
63
                            C:  "",
64
                            L:  "",
65
                            ST: "",
66
                            O:  "",
67
                            OU: "",
68
                            emailAddress: ""
69
                        };
70
                    }
71
                    else {
72
                        axios.get(API_URL + "certificates/" + val + "/details")
73
                            .then(function (response) {
74
                                if (response.data["success"]) {
75
                                    createCertificateApp.selectedCAData = response.data["data"]["subject"];
76
                                }
77
                                else
78
                                    console.log("Error occurred while fetching CA details");
79
                            })
80
                            .catch(function (error) {
81
                                console.log(error);
82
                            });
83
                    }
84
                }
85
            }
86
        });
87

    
88
    axios.get(API_URL+"certificates", {
89
            params: {
90
                filtering: {
91
                    CA: true
92
                }
93
            }
94
        })
95
        .then(function (response) {
96
            if (response.data["success"]) {
97
                createCertificateApp.authorities = response.data["data"];
98
            }
99
            else
100
                console.log("Error occurred while fetching list of available certificate authorities");
101
        })
102
        .catch(function (error) {
103
            console.log(error);
104
        });
(7-7/10)