Revize ac94bd92
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
static/js/create_certificate.js | ||
---|---|---|
42 | 42 |
}, |
43 | 43 |
// actions to be performed when the page is loaded |
44 | 44 |
// - initialize notBefore and notAfter with current date and current date + 1 month respectively |
45 |
mounted() { |
|
45 |
async mounted() {
|
|
46 | 46 |
this.notBefore = new Date().toDateInputValue(); // init notBefore to current date |
47 | 47 |
var endDate = new Date(new Date().getTime() + (30 * 24 * 60 * 60 * 1000)); |
48 | 48 |
this.notAfter = endDate.toDateInputValue(); // init notAfter to notBefore + 30 days |
49 | 49 |
|
50 | 50 |
// Initialize available CA select values |
51 |
axios.get(API_URL + "certificates", { |
|
52 |
params: { |
|
53 |
filtering: { |
|
54 |
CA: true |
|
55 |
} |
|
56 |
} |
|
57 |
}) |
|
58 |
.then(function (response) { |
|
59 |
if (response.data["success"]) { |
|
60 |
createCertificateApp.authorities = response.data["data"]; |
|
61 |
} else { |
|
62 |
createCertificateApp.authorities = [] |
|
51 |
try { |
|
52 |
const response = await axios.get(API_URL + "certificates", { |
|
53 |
params: { |
|
54 |
filtering: { |
|
55 |
CA: true |
|
56 |
} |
|
63 | 57 |
} |
64 |
}) |
|
65 |
.catch(function (error) { |
|
66 |
console.log(error); |
|
67 | 58 |
}); |
59 |
if (response.data["success"]) { |
|
60 |
createCertificateApp.authorities = response.data["data"]; |
|
61 |
} else { |
|
62 |
createCertificateApp.authorities = [] |
|
63 |
} |
|
64 |
} catch (error) { |
|
65 |
console.log(error); |
|
66 |
} |
|
68 | 67 |
}, |
69 | 68 |
methods: { |
70 | 69 |
showError: function (message) { |
... | ... | |
73 | 72 |
this.errorMessage = message; |
74 | 73 |
}, |
75 | 74 |
// handle certificate creation request |
76 |
onCreateCertificate: function () { |
|
75 |
onCreateCertificate: async function () {
|
|
77 | 76 |
// validate input data |
78 | 77 |
// - validate if subject CN is filled in |
79 | 78 |
if (!this.isSelfSigned && this.certificateData.CA == null) { |
... | ... | |
86 | 85 |
return; |
87 | 86 |
} |
88 | 87 |
this.certificateData.validityDays = parseInt(this.certificateData.validityDays); |
89 |
axios.post(API_URL + "certificates", this.certificateData) |
|
90 |
.then(function (response) { |
|
91 |
// on success return to index page |
|
92 |
if (response.data["success"]) { |
|
93 |
window.location.href = "/static/index.html?success=Certificate+successfully+created"; |
|
94 |
} |
|
95 |
// on error display server response message |
|
96 |
else { |
|
97 |
createCertificateApp.showError(response.data["data"]); |
|
98 |
} |
|
99 |
}) |
|
100 |
.catch(function (error) { |
|
101 |
console.log(error); |
|
102 |
}); |
|
88 |
try { |
|
89 |
const response = await axios.post(API_URL + "certificates", this.certificateData); |
|
90 |
if (response.data["success"]) { |
|
91 |
window.location.href = "/static/index.html?success=Certificate+successfully+created"; |
|
92 |
} |
|
93 |
// on error display server response message |
|
94 |
else { |
|
95 |
createCertificateApp.showError(response.data["data"]); |
|
96 |
} |
|
97 |
} catch (error) { |
|
98 |
console.log(error); |
|
99 |
} |
|
103 | 100 |
} |
104 | 101 |
}, |
105 | 102 |
// data watches |
... | ... | |
123 | 120 |
'certificateData.subject.CN': function (val, oldVal) { |
124 | 121 |
if (val !== '') this.invalidCN = false; |
125 | 122 |
}, |
126 |
'certificateData.CA': function (val, oldVal) { |
|
123 |
'certificateData.CA': async function (val, oldVal) {
|
|
127 | 124 |
// self-signed certificate - all fields are empty |
128 | 125 |
if (val === "null" || val == null) { |
129 | 126 |
createCertificateApp.selectedCAData = { |
... | ... | |
138 | 135 |
} |
139 | 136 |
// a CA is selected - get CA's details and display them |
140 | 137 |
else { |
141 |
axios.get(API_URL + "certificates/" + val + "/details") |
|
142 |
.then(function (response) { |
|
143 |
if (response.data["success"]) { |
|
144 |
createCertificateApp.selectedCAData = response.data["data"]["subject"]; |
|
145 |
} else |
|
146 |
console.log("Error occurred while fetching CA details"); |
|
147 |
}) |
|
148 |
.catch(function (error) { |
|
149 |
console.log(error); |
|
150 |
}); |
|
138 |
try { |
|
139 |
const response = await axios.get(API_URL + "certificates/" + val + "/details"); |
|
140 |
if (response.data["success"]) |
|
141 |
createCertificateApp.selectedCAData = response.data["data"]["subject"]; |
|
142 |
else |
|
143 |
console.log("Error occurred while fetching CA details"); |
|
144 |
} catch (error) { |
|
145 |
console.log(error); |
|
146 |
} |
|
151 | 147 |
} |
152 | 148 |
} |
153 | 149 |
} |
Také k dispozici: Unified diff
Re #8583 - create_certificate.js uses await