Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Commit

Permalink
Merge 43f75cc into a3917b1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Dec 15, 2015
2 parents a3917b1 + 43f75cc commit 33a7a98
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 144 deletions.
60 changes: 29 additions & 31 deletions app/partials/signup.jade
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
div
header
h2.em-300(translate="NEW_ACCT_WELCOME", ng-show="currentStep == 1")
h2.em-300(translate="NEW_ACCT_WELCOME")
form.form-horizontal(role="form",name="form",novalidate)
div(ng-switch="currentStep")
div(ng-switch-when="1")
.security-red.mbl.em-400.flex-center
i.ti-hand-stop.mrm.h3.mvn.hidden-xs
span(translate="ALPHA_WARNING")
.form-group(ng-class="{'has-error': errors.email, 'has-success': success.email}")
label.col-sm-4.control-label(translate="EMAIL")
.col-sm-8
input.form-control(type="email",ng-model="fields.email",autofocus,ng-blur="validate()", ng-focus="errors.email = null")
span.help-block
p {{ errors.email }}
.form-group(ng-class="{'has-error': errors.password, 'has-success': success.password}")
label.col-sm-4.control-label(translate="NEW_PASSWORD")
.col-sm-8
input.form-control(type="password", name="password",ng-model="fields.password",autofocus,ng-blur="validate()", ng-focus="errors.password = null", ng-maxlength="255", min-entropy="25" required)
password-entropy(password="fields.password").help-block
span.help-block {{ errors.password }}
.form-group(ng-class="{'has-error': errors.confirmation, 'has-success': success.confirmation}")
label.col-sm-4.control-label(translate="CONFIRM_PASSWORD")
.col-sm-8
input.form-control(type="password",ng-model="fields.confirmation",on-enter="tryNextStep()",autofocus,ng-blur="validate()", ng-focus="errors.confirmation = null")
span.help-block
p {{ errors.confirmation }}
.form-group.flex-center.mtm
.col-sm-4
input#agreement_accept.pull-right(ng-model="fields.acceptedAgreement" type="checkbox" name="agreement_accept" ng-change="validate()")
label.em-300.col-sm-8
| I have read and agree to the
a.em-500(ng-click="showAgreement()") Alpha Program Participation Agreement
.security-red.mbl.em-400.flex-center
i.ti-hand-stop.mrm.h3.mvn.hidden-xs
span(translate="ALPHA_WARNING")
.form-group(ng-class="{'has-error': errors.email, 'has-success': success.email}")
label.col-sm-4.control-label(translate="EMAIL")
.col-sm-8
input.form-control(type="email",ng-model="fields.email",autofocus,ng-blur="validate()", ng-focus="errors.email = null")
span.help-block
p {{ errors.email }}
.form-group(ng-class="{'has-error': errors.password, 'has-success': success.password}")
label.col-sm-4.control-label(translate="NEW_PASSWORD")
.col-sm-8
input.form-control(type="password", name="password",ng-model="fields.password",autofocus,ng-blur="validate()", ng-focus="errors.password = null", ng-maxlength="255", min-entropy="25" required)
password-entropy(password="fields.password").help-block
span.help-block {{ errors.password }}
.form-group(ng-class="{'has-error': errors.confirmation, 'has-success': success.confirmation}")
label.col-sm-4.control-label(translate="CONFIRM_PASSWORD")
.col-sm-8
input.form-control(type="password",ng-model="fields.confirmation",on-enter="trySignup()",autofocus,ng-blur="validate()", ng-focus="errors.confirmation = null")
span.help-block
p {{ errors.confirmation }}
.form-group.flex-center.mtm
.col-sm-4
input#agreement_accept.pull-right(ng-model="fields.acceptedAgreement" type="checkbox" name="agreement_accept" ng-change="validate()")
label.em-300.col-sm-8
| I have read and agree to the
a.em-500(ng-click="showAgreement()") Alpha Program Participation Agreement
.flex-center.flex-end.mbl
button.button-primary(ng-click="nextStep()",ng-disabled="!form.$valid || !isValid[0] || !fields.acceptedAgreement", translate="CONTINUE", ng-show="currentStep == 1 && !working")
button.button-primary(ng-click="signup()",ng-disabled="!form.$valid || !isValid || !fields.acceptedAgreement", translate="CONTINUE", ng-show="!working")
img(ng-show="working" src="img/spinner.gif")
67 changes: 29 additions & 38 deletions assets/js/controllers/signup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ angular
.controller("SignupCtrl", SignupCtrl);

function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModal, $translate, $cookieStore, $filter, $state, $http, languages) {
$scope.currentStep = 1;
$scope.working = false;
$scope.languages = languages;
$scope.currencies = currency.currencies;
$scope.alerts = Alerts.alerts;
$scope.status = Wallet.status;

Expand All @@ -17,18 +14,17 @@ function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModa
}
});

$scope.isValid = [true, true];
$scope.isValid = true;
let language_guess = $filter("getByProperty")("code", $translate.use(), languages);
if (language_guess == null) {
language_guess = $filter("getByProperty")("code", "en", languages);
$scope.language_guess = $filter("getByProperty")("code", "en", languages);
}
const currency_guess = $filter("getByProperty")("code", "USD", currency.currencies);
$scope.currency_guess = $filter("getByProperty")("code", "USD", currency.currencies);

$scope.fields = {
email: "",
password: "",
confirmation: "",
language: language_guess,
currency: currency_guess,
acceptedAgreement: false
};

Expand All @@ -45,33 +41,29 @@ function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModa
$state.go("wallet.common.home");
};

$scope.tryNextStep = () => {
if ($scope.isValid[0]) $scope.nextStep();
$scope.trySignup = () => {
if ($scope.isValid) $scope.signup();
};

$scope.nextStep = () => {
$scope.signup = () => {
$scope.validate();
if ($scope.isValid[$scope.currentStep - 1]) {
if ($scope.currentStep === 1) {
$scope.working = true;
$scope.createWallet( uid => {
$scope.working = false;
if (uid != null) {
$cookieStore.put("uid", uid);
}
if ($scope.savePassword) {
$cookieStore.put("password", $scope.fields.password);
}
$scope.currentStep++;
$scope.close("");
});
}
if ($scope.isValid) {
$scope.working = true;
$scope.createWallet( uid => {
$scope.working = false;
if (uid != null) {
$cookieStore.put("uid", uid);
}
if ($scope.savePassword) {
$cookieStore.put("password", $scope.fields.password);
}
$scope.close("");
});
}
};

$scope.createWallet = successCallback => {
Wallet.create($scope.fields.password, $scope.fields.email, $scope.fields.language, $scope.fields.currency, uid => {
$cookieStore.put("uid", uid);
successCallback(uid);
});
};
Expand All @@ -86,8 +78,7 @@ function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModa
if (visual == null) {
visual = true;
}
$scope.isValid[0] = true;
$scope.isValid[1] = true;
$scope.isValid = true;
$scope.errors = {
email: null,
password: null,
Expand All @@ -99,12 +90,12 @@ function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModa
confirmation: false
};
if ($scope.fields.email === "") {
$scope.isValid[0] = false;
$scope.isValid = false;
$translate("EMAIL_ADDRESS_REQUIRED").then( translation => {
$scope.errors.email = translation;
});
} else if ($scope.form && $scope.form.$error.email) {
$scope.isValid[0] = false;
$scope.isValid = false;
$translate("EMAIL_ADDRESS_INVALID").then( translation => {
$scope.errors.email = translation;
});
Expand All @@ -113,25 +104,25 @@ function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModa
}
if ($scope.form && $scope.form.$error) {
if ($scope.form.$error.minEntropy) {
$scope.isValid[0] = false;
$scope.isValid = false;
$translate("TOO_WEAK").then( translation => {
$scope.errors.password = translation;
});
}
if ($scope.form.$error.maxlength) {
$scope.isValid[0] = false;
$scope.isValid = false;
$translate("TOO_LONG").then( translation => {
$scope.errors.password = translation;
});
}
}
if ($scope.fields.confirmation === "") {
$scope.isValid[0] = false;
$scope.isValid = false;
} else {
if ($scope.fields.confirmation === $scope.fields.password) {
$scope.success.confirmation = true;
} else {
$scope.isValid[0] = false;
$scope.isValid = false;
if (visual) {
$translate("NO_MATCH").then( translation => {
$scope.errors.confirmation = translation;
Expand All @@ -140,19 +131,19 @@ function SignupCtrl($scope, $rootScope, $log, Wallet, Alerts, currency, $uibModa
}
}
if (!$scope.fields.acceptedAgreement) {
$scope.isValid[0] = false;
$scope.isValid = false;
}
};
$scope.validate();

$scope.$watch("fields.language", (newVal, oldVal) => {
$scope.$watch("language_guess", (newVal, oldVal) => {
if (newVal != null) {
$translate.use(newVal.code);
Wallet.changeLanguage(newVal);
}
});

$scope.$watch("fields.currency", (newVal, oldVal) => {
$scope.$watch("currency_guess", (newVal, oldVal) => {
if (newVal != null) {
Wallet.changeCurrency(newVal);
}
Expand Down

0 comments on commit 33a7a98

Please sign in to comment.