You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.vue 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!--
  2. - @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
  3. -
  4. - @author Roeland Jago Douma <roeland@famdouma.nl>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -
  21. -->
  22. <template>
  23. <div id="oauth2" class="section">
  24. <h2>{{ t('oauth2', 'OAuth 2.0 clients') }}</h2>
  25. <p class="settings-hint">
  26. {{ t('oauth2', 'OAuth 2.0 allows external services to request access to {instanceName}.', { instanceName: OC.theme.name}) }}
  27. </p>
  28. <table v-if="clients.length > 0" class="grid">
  29. <thead>
  30. <tr>
  31. <th id="headerContent" />
  32. <th id="headerRemove">
  33. &nbsp;
  34. </th>
  35. </tr>
  36. </thead>
  37. <tbody>
  38. <OAuthItem v-for="client in clients"
  39. :key="client.id"
  40. :client="client"
  41. @delete="deleteClient" />
  42. </tbody>
  43. </table>
  44. <br>
  45. <h3>{{ t('oauth2', 'Add client') }}</h3>
  46. <span v-if="newClient.error" class="msg error">{{ newClient.errorMsg }}</span>
  47. <form @submit.prevent="addClient">
  48. <input id="name"
  49. v-model="newClient.name"
  50. type="text"
  51. name="name"
  52. :placeholder="t('oauth2', 'Name')">
  53. <input id="redirectUri"
  54. v-model="newClient.redirectUri"
  55. type="url"
  56. name="redirectUri"
  57. :placeholder="t('oauth2', 'Redirection URI')">
  58. <input type="submit" class="button" :value="t('oauth2', 'Add')">
  59. </form>
  60. </div>
  61. </template>
  62. <script>
  63. import axios from '@nextcloud/axios'
  64. import OAuthItem from './components/OAuthItem'
  65. import { generateUrl } from '@nextcloud/router'
  66. export default {
  67. name: 'App',
  68. components: {
  69. OAuthItem,
  70. },
  71. props: {
  72. clients: {
  73. type: Array,
  74. required: true,
  75. },
  76. },
  77. data() {
  78. return {
  79. newClient: {
  80. name: '',
  81. redirectUri: '',
  82. errorMsg: '',
  83. error: false,
  84. },
  85. }
  86. },
  87. methods: {
  88. deleteClient(id) {
  89. axios.delete(generateUrl('apps/oauth2/clients/{id}', { id }))
  90. .then((response) => {
  91. this.clients = this.clients.filter(client => client.id !== id)
  92. })
  93. },
  94. addClient() {
  95. this.newClient.error = false
  96. axios.post(
  97. generateUrl('apps/oauth2/clients'),
  98. {
  99. name: this.newClient.name,
  100. redirectUri: this.newClient.redirectUri,
  101. }
  102. ).then(response => {
  103. this.clients.push(response.data)
  104. this.newClient.name = ''
  105. this.newClient.redirectUri = ''
  106. }).catch(reason => {
  107. this.newClient.error = true
  108. this.newClient.errorMsg = reason.response.data.message
  109. })
  110. },
  111. },
  112. }
  113. </script>
  114. <style scoped>
  115. table {
  116. max-width: 800px;
  117. }
  118. </style>