Skip to content
Snippets Groups Projects
Select Git revision
  • b3e0a73f93245339dc170563c203fdc40e6231e5
  • master default protected
  • gitkeep
  • dev protected
  • Issue/2309-docs
  • Hotfix/2097-fixTimeFormat
  • Issue/1910-MigrationtoNET6.0
  • Sprint/2022-01
  • Sprint/2021-05
  • Product/1188-LoggingExtended
  • Topic/1221-LogginExtendedNew
  • Sprint/2021-03
  • Product/1287-dotnet5Sharepoint
  • Topic/1334-dotnet5migration
  • Topic/1221-LoggingExtended
  • Sprint/2021-01
  • Product/407-net5migration
  • Topic/1226-loggingLibraryMigration
  • v2.2.2
  • v2.2.1
  • v2.2.0
  • v2.1.0
  • v2.0.0
  • v1.3.0
  • v1.2.0
  • v1.1.0
  • v1.0.1
  • v1.0.0
28 results

AnalyticsLogObject.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AccessToken.vue 8.34 KiB
    <template>
      <div id="accesstoken">
        <!-- modal for create access-token -->    
        <coscine-modal 
          v-model="isCreateModalVisible"
          :title="$t('CreateModalTitle')"
          :headerText="$t('CreateModalText')">
          <div class="create-modal-content">
            <b-button-group id="tokenButtonGroup" style="width: 100%">
              <b-form-input
                id="accessToken"
                v-model="$v.token.AccessToken.$model"
                :readonly="true"
              />
              <b-button id="copyButton" @click="copyToken" style="margin: inherit"><b-icon-clipboard /></b-button>
              <b-tooltip ref="tooltip" target="copyButton" triggers="focus">{{ $t('CopyToClipboard') }}</b-tooltip>
            </b-button-group>
          </div>
          <div align="right">
            <b-button name="close" @click="isCreateModalVisible = false">{{ $t('CreateModalCloseBtn') }}</b-button>
          </div>
        </coscine-modal>
        <!-- modal for revoke token  -->  
        <coscine-modal 
          v-model="isRevokeModalVisible"
          :title="$t('RevokeModalTitle')"
          :headerText="$t('RevokeModalText')">
          <br/>
          <div class="revoke-modal-content">{{ selectedTokenName }}</div>
          <br/>
          <b-button name="close" @click="isRevokeModalVisible = false">{{ $t('buttons.cancel') }}</b-button>
          <b-button name="deleteToken" @click="confirmeRevoke" variant="danger" style="float: right">{{ $t('TokenRevokeBtn') }}</b-button>
        </coscine-modal>
        <div class="h-divider"></div>
        <h4 style="text-align: left;">{{ $t('AccessTokenHeader') }}</h4>
        <b-form-group
          label-for="TokenBodytext"
          label-cols-sm="3"
          label-align-sm="right"
        >
          <b-form-text
            id="TokenBodytext"
            style="text-align: left;">
            {{ $t('AccessTokenBodytext') }}
          </b-form-text>
        </b-form-group>
        <b-form-group
          class="mandatory"
          label-for="TokenName"
          label-cols-sm="3"
          label-align-sm="right"
          :label="$t('TokenNameLabel')"
        >
          <b-form-input
            id="TokenName"
            v-model="$v.token.TokenName.$model"
            :placeholder="$t('TokenName')"
          />
        </b-form-group>
        <b-form-group
          label-for="ExpiredDate"
          label-cols-sm="3"
          label-align-sm="right"
          :label="$t('TokenExpireLabel')"
        >
          <datepicker
            id="ExpiredDate"
            v-model="$v.token.TokenExpirationDate.$model"
            :language="datepickerLanguage[$i18n.locale]"
            :calendar-button="true"
            calendar-button-icon="material-icons"
            calendar-button-icon-content="date_range"
            :placeholder="$t('TokenExpire')"
            :bootstrap-styling="true"
            :full-month-name="true"
            format="dd MMMM yyyy"
            :disabledDates="disabledExpirationDates"
            :typeable="true"
          >
          </datepicker>
        </b-form-group>
        <b-form-group
          label-cols-sm="3"
          label-align-sm="right"
         >
          <b-button
            type="button"
            variant="secondary"
            class="float-right"
            name="create-token"
            style="margin-right: 0px;"
            @click.prevent="createToken"
            :disabled="$v.token.$invalid">{{ $t('TokenCreateBtn') }}</b-button>
        </b-form-group>
        <b-form-group
          label-for="Token-List"
          label-cols-sm="3"
          label-align-sm="right"
        >
          <b-table
            id="Token-List"
            :fields="headers"
            :items="currentTokens"
            :locale="$i18n.locale"
            :show-empty="true"
            :empty-text="$t('emptyTableText')"
            style="margin-bottom: 0"
            fixed
            sticky-header="100%"
            no-border-collapse>
              <template v-slot:cell(expires)="row">
                <div :class="{ 'text-danger': checkExpiration(row.item.expires) } ">{{row.item.expires}}</div>
              </template>
              <template v-slot:cell(actions)="selectedToken">
                <b-button v-on:click="revokeToken(selectedToken.item)" variant="danger">{{ $t('TokenRevokeBtn') }}</b-button>
              </template>
          </b-table>
        </b-form-group>  
      </div>
    </template>
    
    <script lang="ts">
    import Vue from 'vue';
    
    import { validationMixin } from 'vuelidate';
    import { required } from 'vuelidate/lib/validators';
    
    import { TokenApi } from '@coscine/api-connection';
    
    import { BootstrapVue } from 'bootstrap-vue';
    import { BIconClipboard } from 'bootstrap-vue';
    
    import Datepicker from 'vuejs-datepicker';
    import { de, en } from 'vuejs-datepicker/dist/locale';
    
    import { CoscineModal } from '@coscine/component-library';
    import '@coscine/component-library/dist/index.css';
    
    import moment from 'moment';
    
    Vue.use(BootstrapVue);
    
    const today = moment();
    
    export default Vue.extend({
      mixins: [validationMixin],
      name: 'accesstoken',
      components: {
        Datepicker,
        CoscineModal,
        BIconClipboard,
      },
      validations: {
        token: {
          TokenExpirationDate: {},
          TokenName: {
            required,
          },
          AccessToken: {},
        },
      },
      data() {
        return {
          isCreateModalVisible: false,
          isRevokeModalVisible: false,
          headers: [
            {
              label: this.$t('TokenTableName'),
              key: 'name',
            },
            {
              label: this.$t('TokenTableCreated'),
              key: 'created',
            },
            {
              label: this.$t('TokenTableExpires'),
              key: 'expires',
            },
            {
              label: this.$t('TokenTableAction'),
              key: 'actions',
            },
          ],
          disabledExpirationDates: {
            to: moment(today).add(6, 'days').toDate(),
            from: moment(today).add(371, 'days').toDate(),
          },
          currentTokens: [] as object[],
          datepickerLanguage: {
            de,
            en,
          },
          selectedTokenId: '',
          selectedTokenName: '',
          externalUser: true,
          token: {
            TokenExpirationDate: moment(today).add(7, 'days').toDate(),
            TokenName: '',
            AccessToken: '',
          },
          languages: [] as object[],
          Language: [] as object[],
        };
      },
      mounted() {
        this.getTokens();
      },
      methods: {
        getTokens() {
          TokenApi.GetUserTokens((response: any) => {
            this.currentTokens = [];
            for (const data of response.data) {
              data.expires = this.format_date(data.expires);
              data.created = this.format_date(data.created);
              this.currentTokens.push(data);
            }
            this.$v.token.$reset();
          });
        },
        createToken() {
          const data = {
            name: this.token.TokenName,
            expiration: 0,
          };
          const expDate = this.token.TokenExpirationDate;
          data.expiration = moment(expDate).diff(today, 'days') + 1;
          TokenApi.AddToken(data,
            (response: any) => {
              this.getTokens();
              this.token.AccessToken = response.data.token;
              this.isCreateModalVisible = true;
              this.token.TokenName = '';
            });
        },
        copyToken() {
          navigator.clipboard.writeText(this.token.AccessToken);
        },
        // -- delete selected token
        revokeToken(selectedToken: any) {
          this.selectedTokenId = selectedToken.tokenId;
          this.selectedTokenName = selectedToken.name;
          this.isRevokeModalVisible = true;
        },
        confirmeRevoke() {
          TokenApi.RevokeToken(this.selectedTokenId,
            (response: any) => {
              this.getTokens();
            });
          this.isRevokeModalVisible = false;
        },
        // -- format displayed date
        format_date(date: any) {
          if (date) {
            return moment(date).format('DD.MM.YYYY');
          }
        },
        checkExpiration(expires: any) {
          const expiration = moment(expires, 'DD.MM.YYYY');
          if (today.isAfter(expiration)) {
            return true;
          } else {
            return false;
          }
        },
      },
    });
    </script>
    
    <style>
    #accesstoken .vdp-datepicker .form-control {
      background-color: #ffffff;
    }
    #accesstoken .vdp-datepicker__calendar-button {
      height: calc(1.4em + 0.75rem + 2px);
    }
    .table td {
      vertical-align: middle;
      padding: 0px;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
    .table .btn {
      margin: 2px;
    }
    .table .b-table-empty-row {
      background-color: #f5f5f5;
    }
    .h-divider {
      margin-top: 5px;
      margin-bottom: 10px;
      height: 1px;
      width: 100%;
      border-top: 1px solid #bebbbb;
    }
    .btn-danger:focus {
      outline: none; 
      box-shadow: none; 
      /* Default color codes for bootsrap btn-danger */
      color: #fff;
      background-color: #cc071e;
      border-color: #cc071e;
    }
    .create-modal-content {
      margin-bottom: 1rem;
      margin-top: 0.5rem;
      border: 0;
    }
    .revoke-modal-content {
      font-size: 1.2rem;
      margin-bottom: 1rem;
    }
    </style>