Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 9894938

Browse files
committed
Merge pull request #522 from appirio-tech/SUP-2361-social-no-password
Sup 2361 social no password
2 parents f7ae8f4 + 86ee084 commit 9894938

File tree

6 files changed

+120
-77
lines changed

6 files changed

+120
-77
lines changed

app/settings/account-info/account-info.controller.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33

44
angular.module('tc.settings').controller('AccountInfoController', AccountInfoController);
55

6-
AccountInfoController.$inject = ['userData', 'UserService', 'ProfileService', '$log', 'ISO3166', 'toaster', '$scope', '$timeout'];
6+
AccountInfoController.$inject = ['userData', 'UserService', 'ProfileService', '$log', 'ISO3166', 'toaster', '$scope', '$timeout', '$state'];
77

8-
function AccountInfoController(userData, UserService, ProfileService, $log, ISO3166, toaster, $scope, $timeout) {
8+
function AccountInfoController(userData, UserService, ProfileService, $log, ISO3166, toaster, $scope, $timeout, $state) {
99
var vm = this;
10-
vm.saveAccountInfo = saveAccountInfo;
11-
vm.updateCountry = updateCountry;
12-
vm.submitNewPassword = submitNewPassword;
13-
vm.isSocialRegistrant = false;
14-
vm.formProcessing = {
15-
accountInfoForm: false,
16-
newPasswordForm: false
17-
};
1810
var originalUserData = userData;
11+
vm.saveAccountInfo = saveAccountInfo;
12+
vm.updateCountry = updateCountry;
13+
vm.submitNewPassword = submitNewPassword;
1914

2015
activate();
2116

2217
function activate() {
18+
vm.isSocialRegistrant = false;
19+
20+
vm.formProcessing = {
21+
accountInfoForm: false,
22+
newPasswordForm: false
23+
};
24+
2325
vm.userData = userData.clone();
2426
processData(vm.userData);
27+
2528
UserService.getUserProfile({fields: 'credential'})
2629
.then(function(res) {
2730
vm.isSocialRegistrant = !res.credential.hasPassword;

app/settings/account-info/account-info.jade

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@
1111
.form-label Email
1212
input.form-field.grey(name="email", value="{{vm.userData.email}}", disabled=true)
1313

14-
div(ng-hide="vm.isSocialRegistration")
14+
div(ng-hide="vm.isSocialRegistrant")
1515
form(name="vm.newPasswordForm", role="form", ng-submit="vm.newPasswordForm.$valid && vm.submitNewPassword()", novalidate)
1616
.form-label Current password
1717

1818
.validation-bar(ng-class="{ 'error-bar': (vm.newPasswordForm.currentPassword.$dirty && vm.newPasswordForm.currentPassword.$invalid) }")
19-
toggle-password.tc-input.password(
20-
ng-model="vm.currentPassword"
21-
)
19+
toggle-password.tc-input.password(ng-model="vm.currentPassword")
2220

2321
.form-input-error(ng-show="vm.newPasswordForm.currentPassword.$dirty && vm.newPasswordForm.currentPassword.$invalid")
2422
p(ng-show="vm.newPasswordForm.currentPassword.$error.required") This is a required field.
2523

2624
p(ng-show="vm.newPasswordForm.currentPassword.$error.incorrect") Your current password is incorrect. Please check that you entered the right one.
2725

2826
.form-label New Password
27+
2928
.validation-bar
30-
toggle-password-with-tips.tc-input.password(
31-
placeholder="Pick a new password"
32-
)
29+
toggle-password-with-tips.tc-input.password(placeholder="Pick a new password")
30+
3331
.tips.password-tips(ng-show="vm.passwordFocus")
3432
.arrow
33+
3534
h3 Password Tips:
3635

3736
p Your password must have:
@@ -46,49 +45,48 @@
4645
button.tc-btn.save(type="submit", tc-busy-button, tc-busy-when="vm.formProcessing.newPasswordForm", ng-disabled="vm.newPasswordForm.$invalid || vm.newPasswordForm.$pristine", ng-class="{'disabled': vm.newPasswordForm.$invalid || vm.newPasswordForm.$pristine}") Change Password
4746

4847

49-
div(ng-show="vm.isSocialRegistration")
48+
div(ng-show="vm.isSocialRegistrant")
5049
p You joined Topcoder by using an external account, so we don't have a password for you.
5150

52-
5351
form(name="vm.accountInfoForm", role="form", novalidate, autocomplete="off")
54-
5552
.settings-section.name
5653
.section-info
5754
h2 Name
55+
5856
.description Required for legal purposes; will be kept private and not shared with anyone.
5957

6058
.section-fields
59+
// Stops Chrome from autofilling and autocompleting (along with autocomplete="off" on the form)
60+
input(autocomplete="false", name="hidden", type="text", style="display:none;")
6161

62-
// Stops Chrome from autofilling and autocompleting (along with autocomplete="off" on the form)
63-
input(autocomplete="false", name="hidden", type="text", style="display:none;")
64-
.form-label.first First name
65-
span(style="text-transform: none;")  (Given name)
66-
span.mandatory *mandatory
67-
.validation-bar(ng-class="{ 'error-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.firstname.$invalid), 'success-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.firstname.$valid)}")
68-
input.tc-input(
69-
name="firstname", type="text",
70-
placeholder="First",
71-
ng-model="vm.userData.firstName",
72-
maxlength="64", required,
73-
ng-class="{'form-field-focused': hasFocus==true}"
74-
)
75-
.form-input-error(ng-show="vm.accountInfoForm.firstname.$invalid")
76-
p(ng-show="vm.accountInfoForm.firstname.$error.required") This is a required field.
77-
78-
.form-label Last name
79-
span(style="text-transform: none;")  (Surname)
80-
span.mandatory *mandatory
81-
.validation-bar(ng-class="{ 'error-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.lastname.$invalid), 'success-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.lastname.$valid)}")
82-
input.tc-input(
83-
name="lastname", type="text",
84-
placeholder="Last",
85-
ng-model="vm.userData.lastName",
86-
maxlength="64", required,
87-
ng-class="{'form-field-focused': hasFocus==true}"
88-
)
89-
.form-input-error(ng-show="vm.accountInfoForm.lastname.$invalid")
90-
p(ng-show="vm.accountInfoForm.lastname.$error.required") This is a required field.
62+
.form-label.first First name
63+
span(style="text-transform: none;")  (Given name)
9164

65+
span.mandatory *mandatory
66+
.validation-bar(ng-class="{ 'error-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.firstname.$invalid), 'success-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.firstname.$valid)}")
67+
input.tc-input(
68+
name="firstname", type="text",
69+
placeholder="First",
70+
ng-model="vm.userData.firstName",
71+
maxlength="64", required,
72+
ng-class="{'form-field-focused': hasFocus==true}"
73+
)
74+
.form-input-error(ng-show="vm.accountInfoForm.firstname.$invalid")
75+
p(ng-show="vm.accountInfoForm.firstname.$error.required") This is a required field.
76+
77+
.form-label Last name
78+
span(style="text-transform: none;")  (Surname)
79+
span.mandatory *mandatory
80+
.validation-bar(ng-class="{ 'error-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.lastname.$invalid), 'success-bar': (vm.accountInfoForm.$dirty && vm.accountInfoForm.lastname.$valid)}")
81+
input.tc-input(
82+
name="lastname", type="text",
83+
placeholder="Last",
84+
ng-model="vm.userData.lastName",
85+
maxlength="64", required,
86+
ng-class="{'form-field-focused': hasFocus==true}"
87+
)
88+
.form-input-error(ng-show="vm.accountInfoForm.lastname.$invalid")
89+
p(ng-show="vm.accountInfoForm.lastname.$error.required") This is a required field.
9290

9391
.settings-section.address
9492
.section-info
Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,97 @@
11
/* jshint -W117, -W030 */
22
describe('Account Info Controller', function() {
33
var controller;
4+
var vm;
5+
var credential = {hasPassword: true};
6+
var deferred;
7+
var fakeStateGo;
48

59
beforeEach(function() {
610
bard.appModule('tc.settings');
711
bard.inject(this, '$controller', '$rootScope', '$q');
812

13+
deferred = $q.defer();
14+
915
var userService = {
1016
getUserIdentity: function() {
1117
return {handle: 'nicktest', email: '[email protected]'};
1218
},
1319
resetPassword: function() {
1420
return $q.when({});
21+
},
22+
getUserProfile: function() {
23+
return deferred.promise;
1524
}
1625
};
1726

1827
var userData = {
1928
handle: 'nicktest',
2029
21-
homeCountryCode: 'USA'
30+
homeCountryCode: 'USA',
31+
clone: function() {
32+
return angular.copy(this);
33+
}
2234
};
2335

36+
var state = {
37+
go: function(transitionTo) {
38+
return transitionTo;
39+
}
40+
}
41+
42+
fakeStateGo = sinon.spy(state, 'go');
43+
2444
controller = $controller('AccountInfoController', {
2545
UserService: userService,
26-
userData: userData
46+
userData: userData,
47+
$scope: $rootScope.$new(),
48+
$state: state
2749
});
50+
51+
vm = controller;
2852
});
2953

3054
bard.verifyNoOutstandingHttpRequests();
3155

32-
// TODO: re-add tests!
33-
// it('should be created successfully', function() {
34-
// expect(controller).to.exist;
35-
// });
36-
//
37-
// describe('updating a user\'s password', function() {
38-
// beforeEach(function() {
39-
// $rootScope.$apply();
40-
// });
41-
//
42-
// xit('should update a user\'s password if the current password was entered correctly', function() {
43-
// controller.submitNewPassword();
44-
// });
45-
//
46-
// xit('should return an error if the user entered an incorrect current password', function() {
47-
//
48-
// });
49-
//
50-
// xit('should return an error if there was a server error', function() {
51-
//
52-
// });
53-
// });
56+
it('should be created successfully', function() {
57+
expect(controller).to.exist;
58+
});
59+
60+
describe('updating a user\'s password', function() {
61+
// beforeEach(function() {
62+
// $rootScope.$apply();
63+
// });
64+
65+
xit('should return an error if the user entered an incorrect current password', function() {
66+
67+
});
68+
});
69+
70+
describe('vm.isSocialRegistrant', function() {
71+
it('should be false if a user has a password', function() {
72+
deferred.resolve({credential: credential});
73+
74+
$rootScope.$apply();
75+
76+
expect(vm.isSocialRegistrant).to.be.false;
77+
});
78+
79+
it('should be true if a user does not have a password', function() {
80+
credential.hasPassword = false;
81+
82+
deferred.resolve({credential: credential});
83+
84+
$rootScope.$apply();
5485

86+
expect(vm.isSocialRegistrant).to.be.true;
87+
});
88+
89+
it('should go to the edit page on error', function() {
90+
deferred.reject();
91+
92+
$rootScope.$apply();
93+
94+
expect(fakeStateGo).to.have.been.calledWith('settings.profile');
95+
});
96+
});
5597
});

app/specs.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ <h1><a href="specs.html">Spec Runner</a></h1>
239239
<script src="/app/my-dashboard/my-dashboard.spec.js"></script>
240240
<script src="/app/my-srms/my-srms.spec.js"></script>
241241
<script src="/app/profile/profile.controller.spec.js"></script>
242+
<script src="/app/settings/settings.spec.js"></script>
242243
<script src="/app/services/authToken.service.spec.js"></script>
243244
<script src="/app/services/challenge.service.spec.js"></script>
244245
<script src="/app/services/helpers.service.spec.js"></script>
@@ -247,7 +248,6 @@ <h1><a href="specs.html">Spec Runner</a></h1>
247248
<script src="/app/services/tcAuth.service.spec.js"></script>
248249
<script src="/app/services/user.service.spec.js"></script>
249250
<script src="/app/services/userStats.service.spec.js"></script>
250-
<script src="/app/settings/settings.spec.js"></script>
251251
<script src="/app/skill-picker/skill-picker.spec.js"></script>
252252
<script src="/app/account/login/login.spec.js"></script>
253253
<script src="/app/account/reset-password/reset-password.spec.js"></script>
@@ -256,6 +256,7 @@ <h1><a href="specs.html">Spec Runner</a></h1>
256256
<script src="/app/directives/badges/badge-tooltip.spec.js"></script>
257257
<script src="/app/directives/busy-button/busy-button.directive.spec.js"></script>
258258
<script src="/app/directives/challenge-tile/challenge-tile.spec.js"></script>
259+
<script src="/app/directives/empty-state-placeholder/empty-state-placeholder.spec.js"></script>
259260
<script src="/app/directives/external-account/external-account.directive.spec.js"></script>
260261
<script src="/app/directives/empty-state-placeholder/empty-state-placeholder.spec.js"></script>
261262
<script src="/app/directives/tc-endless-paginator/tc-endless-paginator.spec.js"></script>

assets/css/directives/toggle-password.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ toggle-password {
88
align-items: center;
99
justify-content: space-between;
1010

11-
1211
input#current-password-input {
1312
width: 155px;
1413
margin-bottom: 0;

assets/css/settings/account-info.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
display: flex;
4343
flex-direction: column;
4444
align-items: flex-start;
45-
45+
4646
.form-label {
4747
width: 100%;
4848
margin-top: 10px;
49-
49+
5050
&.first {
5151
margin-top: 0;
5252
}

0 commit comments

Comments
 (0)