Skip to content

Commit

Permalink
Fix login autofill
Browse files Browse the repository at this point in the history
Add <form> element, as some browsers won't autofill fields
not contained in form.

Remove username and password bindings, and explicitly read
inputs instead. Some browsers do not fire onChange events
when a field is autofilled for security reasons, so Vue
bindings don't register the change.

facebook/react#1159 (comment)
  • Loading branch information
deanishe committed Dec 13, 2019
1 parent 9f7c8bf commit a5cb2c6
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 82 deletions.
46 changes: 26 additions & 20 deletions internal/view/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@
<div id="login-scene" :class="{night: nightMode}">
<p class="error-message" v-if="error !== ''">{{error}}</p>
<div id="login-box">
<div id="logo-area">
<p id="logo">
<span></span>shiori
</p>
<p id="tagline">simple bookmark manager</p>
</div>
<div id="input-area">
<label for="username">Username: </label>
<input type="text" name="username" v-model.trim="username" placeholder="Username" tabindex="1">
<label for="password">Password: </label>
<input type="password" name="password" v-model.trim="password" placeholder="Password" tabindex="2" @keyup.enter="login">
<label class="checkbox-field"><input type="checkbox" name="remember" v-model="remember" tabindex="3">Remember me</label>
</div>
<div id="button-area">
<a v-if="loading">
<i class="fas fa-fw fa-spinner fa-spin"></i>
</a>
<a v-else class="button" tabindex="4" @click="login" @keyup.enter="login">Log In</a>
</div>
<form @submit.prevent="login">
<div id="logo-area">
<p id="logo">
<span></span>shiori
</p>
<p id="tagline">simple bookmark manager</p>
</div>
<div id="input-area">
<label for="username">Username: </label>
<input id="username" type="text" name="username" placeholder="Username" tabindex="1">
<label for="password">Password: </label>
<input id="password" type="password" name="password" placeholder="Password" tabindex="2" @keyup.enter="login">
<label class="checkbox-field"><input type="checkbox" name="remember" v-model="remember" tabindex="3">Remember me</label>
</div>
<div id="button-area">
<a v-if="loading">
<i class="fas fa-fw fa-spinner fa-spin"></i>
</a>
<a v-else class="button" tabindex="4" @click="login" @keyup.enter="login">Log In</a>
</div>
</form>
</div>
</div>

Expand Down Expand Up @@ -72,6 +74,10 @@
}
},
login() {
// needed to work around autofill issue
// https://github.com/facebook/react/issues/1159#issuecomment-506584346
this.username = document.querySelector('#username').value;
this.password = document.querySelector('#password').value;
// Validate input
if (this.username === "") {
this.error = "Username must not empty";
Expand Down Expand Up @@ -139,4 +145,4 @@
</script>
</body>

</html>
</html>
124 changes: 62 additions & 62 deletions internal/webserver/assets-prod.go

Large diffs are not rendered by default.

0 comments on commit a5cb2c6

Please sign in to comment.