Skip to content
Permalink
Browse files

Add support to save credentials to a password manager #1607

  • Loading branch information...
Paul de Vries
Paul de Vries committed Dec 5, 2016
1 parent 229f3a2 commit e52fbf061dde4639cb5ba81cdc73235e0cd46b7b
@@ -1297,6 +1297,7 @@ def collect_core_assets(enable_gcodeviewer=True, preferred_stylesheet="css"):
'js/app/bindings/slimscrolledforeach.js',
'js/app/bindings/toggle.js',
'js/app/bindings/togglecontent.js',
'js/app/bindings/valuewithinit.js',
'js/app/viewmodels/appearance.js',
'js/app/viewmodels/connection.js',
'js/app/viewmodels/control.js',
@@ -0,0 +1,11 @@
ko.bindingHandlers.valueWithInit = {
init: function(element, valueAccessor, allBindingsAccessor, context) {
var observable = valueAccessor();
var value = element.value;

observable(value);

ko.bindingHandlers.value.init(element, valueAccessor, allBindingsAccessor, context);
},
update: ko.bindingHandlers.value.update
};

This comment has been minimized.

Copy link
@BillyBlaze

BillyBlaze Dec 5, 2016

Collaborator

I created this binding because you want to grab the username and password placed by a password manager and not to override them by setting the value to "" or undefined.

@@ -76,6 +76,10 @@ $(function() {
self.loginUser("");
self.loginPass("");
self.loginRemember(false);

if (history && history.replaceState) {

This comment has been minimized.

Copy link
@BillyBlaze

BillyBlaze Dec 5, 2016

Collaborator

So this should trigger - in Chrome - on SSL - the prompt dialog.

history.replaceState({success: true}, document.title, window.location.pathname);
}
})
.fail(function() {
new PNotify({title: gettext("Login failed"), text: gettext("User unknown or wrong password"), type: "error"});
@@ -95,14 +99,9 @@ $(function() {
});
};

self.onLoginUserKeyup = function(data, event) {
if (event.keyCode == 13) {
self.elementPasswordInput.focus();
}
};

self.onLoginPassKeyup = function(data, event) {
if (event.keyCode == 13) {
self.prepareLogin = function(data, event, extra) {
if (event.type === "submit" || (event.type === "keyup" && event.keyCode == 13)) {
event.preventDefault();
self.login();
}
};
@@ -3,14 +3,16 @@
<b class="caret"></b>
</a>
<div id="login_dropdown_loggedout" style="padding: 15px" class="dropdown-menu" data-bind="css: {hide: loginState.loggedIn(), 'dropdown-menu': !loginState.loggedIn()}">
<label for="login_user">{{ _('Username') }}</label>
<input type="text" id="login_user" data-bind="value: loginState.loginUser, event: {'keyup': loginState.onLoginUserKeyup}" placeholder="{{ _('Username') }}" autocapitalize="none">
<label for="login_pass">{{ _('Password') }}</label>
<input type="password" id="login_pass" data-bind="value: loginState.loginPass, event: {'keyup': loginState.onLoginPassKeyup}" placeholder="{{ _('Password') }}">
<label class="checkbox">
<input type="checkbox" id="login_remember" data-bind="checked: loginState.loginRemember"> {{ _('Remember me') }}
</label>
<button class="btn btn-block btn-primary" id="login_button" data-bind="click: function() { loginState.login(); }">{{ _('Login') }}</button>
<form id="loginForm" data-bind="event: {'submit': loginState.prepareLogin }" autocomplete="on">
<label for="login_user">{{ _('Username') }}</label>
<input type="text" id="login_user" name="username" data-bind="valueWithInit: loginState.loginUser, event: {'keyup': loginState.prepareLogin }" placeholder="{{ _('Username') }}" autocapitalize="none" autocomplete="on">
<label for="login_pass">{{ _('Password') }}</label>
<input type="password" id="login_pass" name="password" data-bind="valueWithInit: loginState.loginPass, event: {'keyup': loginState.prepareLogin }" placeholder="{{ _('Password') }}" autocomplete="on">
<label class="checkbox">
<input type="checkbox" id="login_remember" data-bind="checked: loginState.loginRemember"> {{ _('Remember me') }}
</label>
<button type="submit" class="btn btn-block btn-primary" id="login_button">{{ _('Login') }}</button>
</form>
</div>
<ul id="login_dropdown_loggedin" class="hide" data-bind="css: {hide: !loginState.loggedIn(), 'dropdown-menu': loginState.loggedIn()}">
<li><a href="#" id="usersettings_button" data-bind="click: function() { usersettings.show(); }">{{ _('User Settings') }}</a></li>

0 comments on commit e52fbf0

Please sign in to comment.
You can’t perform that action at this time.