Skip to content
Snippets Groups Projects
Commit 7066fc82 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

Add UI check when register as member, from WalletController

parent 6838d664
Branches
Tags
No related merge requests found
...@@ -84,7 +84,8 @@ ...@@ -84,7 +84,8 @@
"PSEUDO": "Pseudonym", "PSEUDO": "Pseudonym",
"PSEUDO_HELP": "joe123", "PSEUDO_HELP": "joe123",
"PASSWORD_CONFIRM": "Confirm Password", "PASSWORD_CONFIRM": "Confirm Password",
"PASSWORD_CONFIRM_HELP": "Confirm Password" "PASSWORD_CONFIRM_HELP": "Confirm Password",
"MSG_UID_ALREADY_USED": "This pseudonym is alreadey used by an existing member.<br/>Please choose another one."
}, },
"POPUP_REGISTER": { "POPUP_REGISTER": {
"TITLE": "Enter a pseudonym", "TITLE": "Enter a pseudonym",
......
...@@ -41,7 +41,7 @@ angular.module('cesium.wallet.controllers', ['cesium.services', 'cesium.currency ...@@ -41,7 +41,7 @@ angular.module('cesium.wallet.controllers', ['cesium.services', 'cesium.currency
.controller('TransferCtrl', TransferController) .controller('TransferCtrl', TransferController)
; ;
function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $translate) { function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, BMA, $translate) {
$scope.walletData = {}; $scope.walletData = {};
$scope.convertedBalance = 0; $scope.convertedBalance = 0;
...@@ -115,7 +115,6 @@ function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $tra ...@@ -115,7 +115,6 @@ function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $tra
//don't allow the user to close unless he enters a uid //don't allow the user to close unless he enters a uid
e.preventDefault(); e.preventDefault();
} else { } else {
// TODO : check if not already used
return $scope.walletData.uid; return $scope.walletData.uid;
} }
} }
...@@ -123,17 +122,43 @@ function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $tra ...@@ -123,17 +122,43 @@ function WalletController($scope, $state, $q, $ionicPopup, UIUtils, Wallet, $tra
] ]
}) })
.then(function(uid) { .then(function(uid) {
if (!uid) { if (!uid) { // user cancel
$scope.walletData.uid = null; $scope.walletData.uid = null;
UIUtils.loading.hide();
return;
} }
else { var doSendSelf = function() {
UIUtils.loading.show();
Wallet.self(uid) Wallet.self(uid)
.then(function() { .then(function() {
UIUtils.loading.hide(); UIUtils.loading.hide();
}) })
.catch(UIUtils.onError('ERROR.SEND_SELF_REGISTRATION')); .catch(UIUtils.onError('ERROR.SEND_SELF_REGISTRATION'));
};
// Check uid is not used by another member
UIUtils.loading.show();
BMA.wot.lookup({ search: uid })
.then(function(res) {
var found = typeof res.results != "undefined" && res.results != null && res.results.length > 0
&& res.results.some(function(pub){
return typeof pub.uids != "undefined" && pub.uids != null && pub.uids.length > 0
&& pub.uids.some(function(idty){
return (idty.uid == uid);
});
});
if (found) { // uid is already used : display a message and reopen the popup
UIUtils.loading.hide();
UIUtils.alert.info('ACCOUNT.NEW.MSG_UID_ALREADY_USED')
.then(function(){
$scope.self();
});
} }
else {
doSendSelf();
}
})
.catch(function() {
doSendSelf();
});
}); });
}); });
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
angular.module('cesium.utils.services', ['ngResource']) angular.module('cesium.utils.services', ['ngResource'])
.factory('UIUtils', function($ionicLoading, $ionicPopup, $translate) { .factory('UIUtils', function($ionicLoading, $ionicPopup, $translate, $q) {
function alertError(err, subtitle) { function alertError(err, subtitle) {
$translate([err, 'ERROR.POPUP_TITLE', 'ERROR.UNKNOWN_ERROR', 'COMMON.BTN_OK']) $translate([err, 'ERROR.POPUP_TITLE', 'ERROR.UNKNOWN_ERROR', 'COMMON.BTN_OK'])
.then(function (translations) { .then(function (translations) {
...@@ -22,21 +22,25 @@ angular.module('cesium.utils.services', ['ngResource']) ...@@ -22,21 +22,25 @@ angular.module('cesium.utils.services', ['ngResource'])
} }
function alertInfo(message, subtitle) { function alertInfo(message, subtitle) {
return $q(function(resolve, reject) {
$translate([message, 'INFO.POPUP_TITLE', 'COMMON.BTN_OK']) $translate([message, 'INFO.POPUP_TITLE', 'COMMON.BTN_OK'])
.then(function (translations) { .then(function (translations) {
var message = translations[message];
return $ionicPopup.show({ return $ionicPopup.show({
template: '<p>' + message + '</p>', template: '<p>' + translations[message] + '</p>',
title: translations['INFO.POPUP_TITLE'], title: translations['INFO.POPUP_TITLE'],
subTitle: subtitle, subTitle: subtitle,
buttons: [ buttons: [
{ {
text: '<b>'+translations['COMMON.BTN_OK']+'</b>', text: '<b>'+translations['COMMON.BTN_OK']+'</b>',
type: 'button-positive' type: 'button-positive',
onTap: function(e) {
resolve(e);
}
} }
] ]
}); });
}); });
});
} }
function hideLoading(){ function hideLoading(){
...@@ -59,7 +63,8 @@ angular.module('cesium.utils.services', ['ngResource']) ...@@ -59,7 +63,8 @@ angular.module('cesium.utils.services', ['ngResource'])
return { return {
alert: { alert: {
error: alertError error: alertError,
info: alertInfo
}, },
loading: { loading: {
show: showLoading, show: showLoading,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment