Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1b9fc014

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

Re #8475 - Changed notBefore & notAfter to validityDays

Zobrazit rozdíly:

static/create_certificate.html
26 26
            <tr>
27 27
                <div class="form-group">
28 28
                    <td><label for="validity_start">Validity start:</label></td>
29
                    <td class="pl-3"><input v-model="certificateData.notBefore" type="date" id="validity_start" name="validity_start" class="form-control"></td>
29
                    <td class="pl-3"><input v-bind:value="notBefore" type="date" id="validity_start" name="validity_start" class="form-control" disabled></td>
30 30
                </div>
31 31
            </tr>
32 32
            <tr>
33 33
                <div class="form-group">
34 34
                    <td><label for="validity_end">Validity end:</label></td>
35
                    <td class="pl-3"><input v-model="certificateData.notAfter" type="date" id="validity_end" name="validity_end" class="form-control"></td>
35
                    <td class="pl-3"><input v-bind:value="notAfter" type="date" id="validity_end" name="validity_end" class="form-control" disabled></td>
36
                    <td class="pl-3">
37
                        <span>
38
                            <input v-model="certificateData.validityDays" type="number" min="1" id="validity_days" name="validity_days" class="form-control custom-control-inline" style="width: 70px; margin-right: 0">
39
                            <label for="validity_days">days</label>
40
                        </span>
41
                    </td>
36 42
                </div>
37 43
            </tr>
38 44
            <tr>
static/js/create_certificate.js
3 3
    var createCertificateApp = new Vue({
4 4
            el: "#create-certificate-content",
5 5
            data: {
6
                notBefore: "",
7
                notAfter: "",
6 8
                // available certificate authorities
7 9
                authorities: [],
8 10
                // data of the selected certificate authorities to be displayed in the form
......
26 28
                        OU: "",
27 29
                        emailAddress: ""
28 30
                    },
29
                    notBefore: "",
30
                    notAfter: "",
31
                    validityDays: 30,
31 32
                    usage: {
32 33
                        CA: false,
33 34
                        authentication: false,
......
40 41
            // actions to be performed when the page is loaded
41 42
            // - initialize notBefore and notAfter with current date and current date + 1 month respectively
42 43
            mounted () {
43
              this.certificateData.notBefore = new Date().toDateInputValue(); // init notBefore to current date
44
              this.notBefore = new Date().toDateInputValue(); // init notBefore to current date
44 45
              var endDate = new Date(new Date().getTime()+(30*24*60*60*1000));
45
              this.certificateData.notAfter = endDate.toDateInputValue(); // init notAfter to notBefore + 30 days
46
              this.notAfter = endDate.toDateInputValue(); // init notAfter to notBefore + 30 days
46 47
            },
47 48
            methods: {
48 49
                // handle certificate creation request
......
53 54
                        alert("CN field must be filled in!"); // TODO highlight the field
54 55
                        return;
55 56
                    }
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 57
                    // send the request and handle response
62 58
                    axios.post(API_URL + "certificates", this.certificateData)
63 59
                        .then(function (response) {
......
79 75
            // data watches
80 76
            watch: {
81 77
                // if the selected CA is changed, the Issuer input fileds must be filled in
78
                'certificateData.validityDays': function (val, oldVal) {
79
                    var endDate = new Date(new Date().getTime()+(val*24*60*60*1000));
80
                    this.notAfter = endDate.toDateInputValue(); // init notAfter to today + validityDays
81
                },
82 82
                'certificateData.CA': function (val, oldVal) {
83 83
                    // self-signed certificate - all fields are empty
84 84
                    if (val === "null" || val == null) {

Také k dispozici: Unified diff