Skip to content
This repository was archived by the owner on Apr 22, 2022. It is now read-only.

Commit d36f5d6

Browse files
author
taleksashina
committed
sign up form: check if user name and email exists on the fly
1 parent c4bb955 commit d36f5d6

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

src/main/webapp/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,21 @@ <h5 class="modal-title green bold" data-i18n="_register_"></h5>
123123
<div class="form-group">
124124
<label for="username" class="col-lg-2 control-label" data-i18n="_username_"></label>
125125
<div class="col-lg-10">
126-
<input type="text" id="username" name="username" class="form-control" data-i18n-attr="_username_|placeholder" ng-model="signUp.username" required/>
126+
<input type="text" id="username" name="username" class="form-control" data-i18n-attr="_username_|placeholder" ng-model="signUp.username" required unique-user-name/>
127127
<div class="error" ng-show="signUpForm.username.$dirty && signUpForm.username.$invalid">{{'_invalid-field-message_' | i18n}}:
128128
<span ng-show="signUpForm.username.$error.required" data-i18n="_username-missed-message_"></span>
129+
<span ng-show="signUpForm.username.$error.uniqueUserName" data-i18n="_user-already-exists-error_"></span>
129130
</div>
130131
</div>
131132
</div>
132133
<div class="form-group">
133134
<label for="email" class="col-lg-2 control-label" data-i18n="_email_"></label>
134135
<div class="col-lg-10">
135-
<input type="email" id="email" name="email" class="form-control" data-i18n-attr="_email_|placeholder" ng-model="signUp.email" required/>
136+
<input type="email" id="email" name="email" class="form-control" data-i18n-attr="_email_|placeholder" ng-model="signUp.email" required unique-email/>
136137
<div class="error" ng-show="signUpForm.email.$dirty && signUpForm.email.$invalid">{{'_invalid-field-message_' | i18n}}:
137138
<span ng-show="signUpForm.email.$error.required" data-i18n="_email-missed-message_"></span>
138139
<span ng-show="signUpForm.email.$error.email" data-i18n="_malformed-email-message_"></span>
140+
<span ng-show="signUpForm.email.$error.uniqueEmail" data-i18n="_user-already-exists-error_"></span>
139141
</div>
140142
</div>
141143
</div>

src/main/webapp/js/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ app.config(function($routeSegmentProvider, $routeProvider)
9999
resolve: {
100100
settings: function (Config) {
101101
return Config.read();
102+
},
103+
userInfo : function(UsersService) {
104+
return UsersService.readUserNamesEmails();
102105
}
103106
}
104107
})
@@ -190,6 +193,9 @@ app.config(function($routeSegmentProvider, $routeProvider)
190193
resolve: {
191194
settings: function (Config) {
192195
return Config.read();
196+
},
197+
userInfo : function(UsersService) {
198+
return UsersService.readUserNamesEmails();
193199
}
194200
}
195201
})

src/main/webapp/js/directives.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,32 @@ app.directive('uniqueIdentifier', ['$compile', 'ConfigurationService', function(
216216
});
217217
}
218218
};
219+
}]);
220+
221+
app.directive('uniqueUserName', ['$compile', 'UsersService', function($compile, UsersService){
222+
return {
223+
restrict: 'A',
224+
require: 'ngModel',
225+
link: function(scope, elem, attr, ngModel) {
226+
var list = UsersService.getUserNames();
227+
ngModel.$parsers.unshift(function (value) {
228+
ngModel.$setValidity('uniqueUserName', list.indexOf(value) === -1);
229+
return value;
230+
});
231+
}
232+
};
233+
}]);
234+
235+
app.directive('uniqueEmail', ['$compile', 'UsersService', function($compile, UsersService){
236+
return {
237+
restrict: 'A',
238+
require: 'ngModel',
239+
link: function(scope, elem, attr, ngModel) {
240+
var list = UsersService.getEmails();
241+
ngModel.$parsers.unshift(function (value) {
242+
ngModel.$setValidity('uniqueEmail', list.indexOf(value) === -1);
243+
return value;
244+
});
245+
}
246+
};
219247
}]);

src/main/webapp/js/services/users-service.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ module.factory("UsersService", function($http, Config, AccountService) {
66
var users = [];
77
var roles = {};
88

9+
var userNames = [];
10+
var emails = [];
11+
12+
var readUserNamesEmails = function() {
13+
var requestData = {
14+
format: "application/sparql-results+json",
15+
query: "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
16+
+ " prefix gkg: <" + Config.getFrameworkOntologyNS() + "> "
17+
+ " SELECT ?s ?p ?o FROM <" + Config.getAccountsGraph() + "> "
18+
+ " WHERE {?s ?p ?o . ?s rdf:type gkg:Account . filter(?p=foaf:accountName || ?p=foaf:mbox) } "
19+
+ " ORDER BY ?s ?p ?o",
20+
mode: "settings"
21+
};
22+
return $http.post("RdfStoreProxy", $.param(requestData)).then(function(response) {
23+
var parsedResult = Config.parseSparqlResults(response.data);
24+
for (var ind in parsedResult) {
25+
userNames.push(parsedResult[ind]["foaf:accountName"][0]);
26+
emails.push(parsedResult[ind]["foaf:mbox"][0].replace("mailto:",""));
27+
}
28+
return parsedResult;
29+
});
30+
};
31+
32+
var getUserNames = function() {
33+
return userNames;
34+
};
35+
36+
var getEmails = function() {
37+
return emails;
38+
};
39+
940
var readUsers = function() {
1041
var requestData = {
1142
mode: "getProfiles",
@@ -189,6 +220,9 @@ module.factory("UsersService", function($http, Config, AccountService) {
189220
};
190221

191222
return {
223+
readUserNamesEmails : readUserNamesEmails,
224+
getUserNames : getUserNames,
225+
getEmails : getEmails,
192226
readUsers : readUsers,
193227
getAllUsers : getAllUsers,
194228
reloadUsers : reloadUsers,

0 commit comments

Comments
 (0)