Better connection / password error handling

This commit is contained in:
Tor Hveem 2014-02-14 09:14:55 -05:00 committed by David Cormier
parent e68e7dd01d
commit 0f44465faa
3 changed files with 18 additions and 4 deletions

View file

@ -60,11 +60,15 @@
<input type="text" class="form-control monospace" id="host" ng-model="host" placeholder="Address"> <input type="text" class="form-control monospace" id="host" ng-model="host" placeholder="Address">
<input type="text" class="form-control monospace" id="port" ng-model="port" placeholder="9001"> <input type="text" class="form-control monospace" id="port" ng-model="port" placeholder="9001">
</div> </div>
<label class="control-label" for="password">WeeChat relay password</label>
<input type="password" class="form-control monospace" id="password" ng-model="password" placeholder="Password">
<div class="alert alert-danger" ng-show="passwordError"> <div class="alert alert-danger" ng-show="passwordError">
Error: wrong password Error: wrong password
</div> </div>
<label class="control-label" for="password">WeeChat relay password</label> <label class="control-label" for="password">WeeChat relay password</label>
<input type="password" class="form-control monospace" id="password" ng-model="password" placeholder="Password"> <input type="password" class="form-control monospace" id="password" ng-model="password" placeholder="Password">
<div class="checkbox"> <div class="checkbox">
<label class="control-label" for="savepassword"> <label class="control-label" for="savepassword">
<input type="checkbox" id="savepassword" ng-model="savepassword"> <input type="checkbox" id="savepassword" ng-model="savepassword">

View file

@ -263,6 +263,8 @@ function($rootScope,
]).then( ]).then(
null, null,
function() { function() {
// Connection got closed, lets check if we ever was connected successfully
if(!$rootScope.waseverconnected)
$rootScope.passwordError = true; $rootScope.passwordError = true;
} }
); );
@ -310,12 +312,19 @@ function($rootScope,
}; };
var onmessage = function(event) {
// If we recieve a message from WeeChat it means that
// password was OK. Store that result and check for it
// in the failure handler.
$rootScope.waseverconnected = true;
}
var onclose = function () { var onclose = function () {
/* /*
* Handles websocket disconnection * Handles websocket disconnection
*/ */
$log.info("Disconnected from relay"); $log.info("Disconnected from relay");
failCallbacks('disconnection'); failCallbacks('disconnection');
$rootScope.connected = false; $rootScope.connected = false;
$rootScope.$apply(); $rootScope.$apply();
@ -345,6 +354,7 @@ function($rootScope,
'binaryType': "arraybuffer", 'binaryType': "arraybuffer",
'onopen': onopen, 'onopen': onopen,
'onclose': onclose, 'onclose': onclose,
'onmessage': onmessage,
'onerror': onerror, 'onerror': onerror,
}); });
@ -518,7 +528,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.buffers = models.model.buffers; $scope.buffers = models.model.buffers;
$scope.activeBuffer = models.getActiveBuffer; $scope.activeBuffer = models.getActiveBuffer;
$rootScope.commands = []; $rootScope.waseverconnected = false;
$rootScope.models = models; $rootScope.models = models;

View file

@ -106,7 +106,7 @@ function($rootScope, $q) {
// otherwise emit it // otherwise emit it
$rootScope.$emit('onMessage', message); $rootScope.$emit('onMessage', message);
} }
$rootScope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type);
$rootScope.$apply(); $rootScope.$apply();
}; };