-
Notifications
You must be signed in to change notification settings - Fork 44
Handle required input types #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
28a9fd4
Initial commit
MrBurrBurr 5631a25
Handle all input types
MrBurrBurr 1ca55a5
Fix info and label text
MrBurrBurr d78be7c
Merge branch 'master' into handle-2fa
MrBurrBurr 1d2b5e9
Merge branch 'master' into handle-2fa
MrBurrBurr 802c9ac
Misc
MrBurrBurr aea93a6
Verify that requiredInput has not changed
MrBurrBurr 3072521
Submit input on enter key press
MrBurrBurr 1e8ffae
Show error if code is empty
MrBurrBurr f358205
Show info about required input as bot status
MrBurrBurr 4656608
Merge branch 'master' into handle-2fa
MrBurrBurr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Todo: Read EUserInputType from api | ||
|
|
||
| const types = { | ||
| None: 0, | ||
| Login: 1, | ||
| Password: 2, | ||
| SteamGuard: 3, | ||
| SteamParentalCode: 4, | ||
| TwoFactorAuthentication: 5, | ||
| }; | ||
|
|
||
| export default function getUserInputType(id) { | ||
| return Object.keys(types)[id]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| <template> | ||
| <main v-if="bot" class="main-container"> | ||
| <h2 v-if="bot.nickname && nicknames" class="title">{{ bot.nickname }}</h2> | ||
| <h2 v-else class="title">{{ bot.name }}</h2> | ||
|
|
||
| <div class="form-item"> | ||
| <div class="form-item__info">{{ $t(`input-info-${inputType}`) }}</div> | ||
| <div class="form-item__code"> | ||
| <div> | ||
| <label for="input" class="form-item__label">{{ $t(`input-label-${inputType}`) }}</label> | ||
| <input id="input" class="form-item__input" type="password" autocomplete="new-password" v-model="code" /> | ||
| </div> | ||
| <div class="form-item__buttons form-item__buttons--column"> | ||
| <button class="button button--helper" :title="$t('input-switch-visibility')" @click="switchInputType"> | ||
| <font-awesome-icon v-if="inputHidden" icon="eye" size="lg"></font-awesome-icon> | ||
| <font-awesome-icon v-else icon="eye-slash" size="lg"></font-awesome-icon> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| <div class="form-item__buttons form-item__buttons--center"> | ||
| <button class="button button--confirm" @click="submit"> | ||
| <font-awesome-icon v-if="submitting" icon="spinner" spin></font-awesome-icon> | ||
| <span v-else>{{ $t('input-submit') }}</span> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { mapGetters } from 'vuex'; | ||
| import getUserInputType from '../../utils/getUserInputType'; | ||
|
|
||
| export default { | ||
| name: 'bot-input', | ||
| data() { | ||
| return { | ||
| submitting: false, | ||
| code: '', | ||
| inputHidden: true, | ||
| }; | ||
| }, | ||
| computed: { | ||
| ...mapGetters({ nicknames: 'settings/nicknames' }), | ||
| bot() { | ||
| return this.$store.getters['bots/bot'](this.$route.params.bot); | ||
| }, | ||
| inputType() { | ||
| return this.$route.params.type.toLowerCase(); | ||
| }, | ||
| }, | ||
| created() { | ||
| if (!this.bot || !this.$route.params.type) this.$router.replace({ name: 'bots' }); | ||
| document.addEventListener('keydown', this.onEnterClick); | ||
| }, | ||
| beforeDestroy() { | ||
| document.removeEventListener('keydown', this.onEnterClick); | ||
| }, | ||
| mounted() { | ||
| document.getElementById('input').focus(); | ||
| }, | ||
| methods: { | ||
| switchInputType() { | ||
| this.inputHidden = !this.inputHidden; | ||
| const field = document.getElementById('input'); | ||
|
|
||
| if (field.getAttribute('type') === 'password') field.setAttribute('type', 'text'); | ||
| else field.setAttribute('type', 'password'); | ||
| }, | ||
| onEnterClick(e) { | ||
| const charCode = (e.which) ? e.which : e.keyCode; | ||
|
|
||
| if (charCode === 13) { | ||
| this.submit(); | ||
| return e.preventDefault(); | ||
| } | ||
| }, | ||
| async submit() { | ||
| if (this.submitting) return; | ||
|
|
||
| if (this.code === '') { | ||
| this.$error(this.$t(`input-no-code-${this.inputType}`)); | ||
| return; | ||
| } | ||
|
|
||
| this.submitting = true; | ||
|
|
||
| try { | ||
| const inputType = getUserInputType(this.bot.requiredInput); | ||
| if (inputType === this.$route.params.type) await this.$http.post(`bot/${this.bot.name}/input`, { type: this.bot.requiredInput, value: this.code }); | ||
| await this.$http.botAction(this.bot.name, 'start'); | ||
| await this.$store.dispatch('bots/updateBot', { name: this.bot.name, active: true }); | ||
|
|
||
| this.$router.back(); | ||
| } catch (err) { | ||
| this.$error(err.message); | ||
| } finally { | ||
| this.submitting = false; | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
| </script> | ||
|
|
||
| <style lang="scss"> | ||
| .form-item__info { | ||
| padding-bottom: 1em; | ||
| } | ||
|
|
||
| .form-item__code { | ||
| display: grid; | ||
| grid-column-gap: 0.5em; | ||
| grid-template-columns: 1fr auto; | ||
| align-items: flex-end; | ||
| padding-bottom: 1em; | ||
|
|
||
| :focus { | ||
| outline: none; | ||
| } | ||
| } | ||
|
|
||
| .button--helper { | ||
| max-width: 2em; | ||
| } | ||
| </style> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.