diff --git a/modules/distribution/src/repository/jaggeryapps/iot/api/user-api.jag b/modules/distribution/src/repository/jaggeryapps/iot/api/user-api.jag index 31d1d0f9..42066cdc 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/api/user-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iot/api/user-api.jag @@ -30,71 +30,94 @@ var utility = require("/modules/utility.js").utility; var result; if (uriMatcher.match("/{context}/api/user/login/")) { - username = request.getParameter("username"); - password = request.getParameter("password"); - try { - userModule.login(username, password, function(user) { - if (log.isDebugEnabled()) { - log.debug("User Logged In : " + user); - } - utility.insertAppPermissions(userModule, "login"); - response.sendRedirect(constants.WEB_APP_CONTEXT); - }, function() { - response.sendRedirect(dcProps.appContext + "login?#auth-failed"); - }); - } catch (e) { - log.error("Exception occurred while a user tried to login to DC", e); - response.sendRedirect(dcProps.appContext + "login?#error"); - } -} else if (uriMatcher.match("/{context}/api/user/logout/")){ - userModule.logout(function() { - response.sendRedirect(dcProps.appContext + "login"); - }); + username = request.getParameter("username"); + password = request.getParameter("password"); + try { + userModule.login(username, password, function (user) { + if (log.isDebugEnabled()) { + log.debug("User Logged In : " + user); + } + utility.insertAppPermissions(userModule, "login"); + response.sendRedirect(constants.WEB_APP_CONTEXT); + }, function () { + response.sendRedirect(dcProps.appContext + "login?#auth-failed"); + }); + } catch (e) { + log.error("Exception occurred while a user tried to login to DC", e); + response.sendRedirect(dcProps.appContext + "login?#error"); + } +} else if (uriMatcher.match("/{context}/api/user/logout/")) { + userModule.logout(function () { + response.sendRedirect(dcProps.appContext + "login"); + }); +} else if (uriMatcher.match("/{context}/api/users/register")) { + addUserFormData = request.getContent(); + + username = addUserFormData.username; + firstname = addUserFormData.firstname; + lastname = addUserFormData.lastname; + emailAddress = addUserFormData.emailAddress; + password = addUserFormData.password; + + if (!addUserFormData.userRoles) { + userRoles = null; + } else { + userRoles = String(addUserFormData.userRoles).split(","); + } + + try { + result = userModule.registerUser(username, firstname, lastname, emailAddress, password, + userRoles); + } catch (e) { + log.error("Exception occurred while trying to registering a new user to DC User Store", e); + // http status code 400 refers to - Bad request. + result = 400; + } } else if (uriMatcher.match("/{context}/api/users/add")) { - if (userModule.isAuthorized("/permission/device-mgt/admin/users/add")) { - addUserFormData = request.getContent(); + if (userModule.isAuthorized("/permission/device-mgt/admin/users/add")) { + addUserFormData = request.getContent(); - username = addUserFormData.username; - firstname = addUserFormData.firstname; - lastname = addUserFormData.lastname; - emailAddress = addUserFormData.emailAddress; + username = addUserFormData.username; + firstname = addUserFormData.firstname; + lastname = addUserFormData.lastname; + emailAddress = addUserFormData.emailAddress; - if (!addUserFormData.userRoles) { - userRoles = null; - } else { - userRoles = String(addUserFormData.userRoles).split(","); - } + if (!addUserFormData.userRoles) { + userRoles = null; + } else { + userRoles = String(addUserFormData.userRoles).split(","); + } - try { - result = userModule.addUser(username, firstname, lastname, emailAddress, userRoles); - } catch (e) { - log.error("Exception occurred while trying to add a user to DC User Store", e); - // http status code 400 refers to - Bad request. - result = 400; - } - } else { - // http status code 403 refers to - forbidden. - result = 403; - } + try { + result = userModule.addUser(username, firstname, lastname, emailAddress, userRoles); + } catch (e) { + log.error("Exception occurred while trying to add a user to DC User Store", e); + // http status code 400 refers to - Bad request. + result = 400; + } + } else { + // http status code 403 refers to - forbidden. + result = 403; + } } else if (uriMatcher.match("/{context}/api/users/{username}/remove")) { - if (userModule.isAuthorized("/permission/device-mgt/admin/users/remove")) { - elements = uriMatcher.elements(); - username = elements.username; - try { - result = userModule.removeUser(username); - } catch (e) { - log.error("Exception occurred while trying to remove a user from DC User Store", e); - // http status code 400 refers to - Bad request. - result = 400; - } - } else { - // http status code 403 refers to - forbidden. - result = 403; - } + if (userModule.isAuthorized("/permission/device-mgt/admin/users/remove")) { + elements = uriMatcher.elements(); + username = elements.username; + try { + result = userModule.removeUser(username); + } catch (e) { + log.error("Exception occurred while trying to remove a user from DC User Store", e); + // http status code 400 refers to - Bad request. + result = 400; + } + } else { + // http status code 403 refers to - forbidden. + result = 403; + } } // returning the result. if (result) { - print(result); + print(result); } %> diff --git a/modules/distribution/src/repository/jaggeryapps/iot/lib/handlebars-helpers.js b/modules/distribution/src/repository/jaggeryapps/iot/lib/handlebars-helpers.js index 3f1ed03c..80342019 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/lib/handlebars-helpers.js +++ b/modules/distribution/src/repository/jaggeryapps/iot/lib/handlebars-helpers.js @@ -24,7 +24,7 @@ var getScope = function (unit,configs) { }; onRequestCb = script.onRequest; cbResult = onRequestCb(templateConfigs); - log.info("passing configs to unit "+unit+" configs: "+stringify(templateConfigs)); + log.debug("passing configs to unit "+unit+" configs: "+stringify(templateConfigs)); //If the execution does not yield an object we will print //a warning as the unit author may have forgotten to return a data object if(cbResult===undefined){ @@ -157,7 +157,7 @@ Handlebars.registerHelper('unit', function (unitName,options) { //TODO warn when unspecified decencies are included. fuseState.zoneStack.push('main'); var template = fuse.getFile(baseUnit, '', '.hbs'); - log.info('[' + requestId + '] including "' + baseUnit + '"'+" with configs "+stringify(templateConfigs)); + log.debug('[' + requestId + '] including "' + baseUnit + '"'+" with configs "+stringify(templateConfigs)); var result = new Handlebars.SafeString(Handlebars.compileFile(template)(getScope(baseUnit,templateConfigs))); fuseState.zoneStack.pop(); return result; diff --git a/modules/distribution/src/repository/jaggeryapps/iot/modules/user.js b/modules/distribution/src/repository/jaggeryapps/iot/modules/user.js index db86177c..a392d7b1 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/modules/user.js +++ b/modules/distribution/src/repository/jaggeryapps/iot/modules/user.js @@ -56,6 +56,47 @@ userModule = function () { } }; + /** + * Register user to dc-user-store. + * + * @param username Username of the user + * @param firstname First name of the user + * @param lastname Last name of the user + * @param emailAddress Email address of the user + * @param password Password of the user + * @param userRoles Roles assigned to the user + * + * @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists + */ + publicMethods.registerUser = function (username, firstname, lastname, emailAddress, password, userRoles) { + var carbon = require('carbon'); + var tenantId = carbon.server.tenantId(); + var url = carbon.server.address('https') + "/admin/services"; + var server = new carbon.server.Server(url); + var userManager = new carbon.user.UserManager(server, tenantId); + + try { + if (userManager.userExists(username)) { + if (log.isDebugEnabled()) { + log.debug("A user with name '" + username + "' already exists."); + } + // http status code 409 refers to - conflict. + return 409; + } else { + var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress); + + userManager.addUser(username, password, userRoles, defaultUserClaims, "default"); + if (log.isDebugEnabled()) { + log.debug("A new user with name '" + username + "' was created."); + } + // http status code 201 refers to - created. + return 201; + } + } catch (e) { + throw e; + } + }; + /** * Add user to dc-user-store. * diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.hbs b/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.hbs index 86c9867a..6ea68338 100755 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.hbs @@ -132,7 +132,7 @@
- +
@@ -145,15 +145,19 @@ Username :
- Password:
+ Password:
- +
+{{/zone}} + +{{#zone "bottomJs"}} + {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.json b/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.json index 5e32dcda..6240cff5 100755 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.json +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/appbar.json @@ -1,3 +1,3 @@ { - "predicate": "true" + "predicate": "false" } \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/public/scripts/validate-register.js b/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/public/scripts/validate-register.js new file mode 100644 index 00000000..b03487d9 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/appbar/public/scripts/validate-register.js @@ -0,0 +1,140 @@ +var emailIsValid = function (email) { + var atPosition = email.indexOf("@"); + var dotPosition = email.lastIndexOf("."); + return !(atPosition < 1 || ( dotPosition - atPosition < 2 )); +}; + +var validatePassword = function (psswd, conPass) { + var error = ""; + var illegalChars = /[\W_]/; // allow only letters and numbers + + if ((psswd.length < 5) || (psswd.length > 15)) { + error = "The password is of wrong length. Should be between 5 and 15 characters. \n"; + $('.wr-validation-summary strong').text(error); + $('.wr-validation-summary').removeClass("hidden"); + return false; + + } else if (illegalChars.test(psswd)) { + error = "The password contains illegal characters.\n"; + $('.wr-validation-summary strong').text(error); + $('.wr-validation-summary').removeClass("hidden"); + return false; + + } else if ((psswd.search(/[a-zA-Z]+/) == -1) || (psswd.search(/[0-9]+/) == -1)) { + error = "The password must contain at least one numeral and one character.\n"; + $('.wr-validation-summary strong').text(error); + $('.wr-validation-summary').removeClass("hidden"); + return false; + + } else if (psswd != conPass) { + error = "The password and confirm-password should match.\n"; + $('.wr-validation-summary strong').text(error); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + + } else { + return true; + } + +}; + +$(function () { + $("button#add-user-btn").click(function () { + //e.preventDefault(); + var username = $("input#user_name").val(); + var firstname = $("input#first_name").val(); + var lastname = $("input#last_name").val(); + var emailAddress = $("input#email").val(); + var password = $("input#password").val(); + var passwordConfirm = $("input#password_confirmation").val(); + + // var userRoles = $("select#roles").val(); + + if (!firstname) { + $('.wr-validation-summary strong').text("Firstname is a required field. It cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!lastname) { + $('.wr-validation-summary strong').text("Lastname is a required field. It cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!username) { + $('span.wr-validation-summary strong').text("Username is a required field. It cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!emailAddress) { + $('.wr-validation-summary strong').text("Email is a required field. It cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!emailIsValid(emailAddress)) { + $('.wr-validation-summary strong').text("Email is not valid. Please enter a correct email address."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!password) { + $('.wr-validation-summary strong').text("Please enter a user login password."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!passwordConfirm) { + $('.wr-validation-summary strong').text("Please re-type password"); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } else if (!validatePassword(password, passwordConfirm)) { + // return false; + } else if (!$('#t_and_c').is(':checked')) { + $('.wr-validation-summary strong').text("Please accept our terms and conditions"); + $('.wr-validation-summary').removeClass("hidden"); + } else { + + var addUserFormData = {}; + addUserFormData.username = username; + addUserFormData.firstname = firstname; + addUserFormData.lastname = lastname; + addUserFormData.emailAddress = emailAddress; + addUserFormData.password = password; + addUserFormData.userRoles = null; + + var addUserAPI = "/iot/api/users/register"; + + $.ajax({ + type: 'POST', + url: addUserAPI, + contentType: 'application/json', + data: JSON.stringify(addUserFormData), + success: function (data) { + if (data == 200) { + $('.wr-validation-summary strong').text("Successfully Submitted."); + $('.wr-validation-summary strong').removeClass("label-danger"); + $('.wr-validation-summary strong').addClass("label-success"); + } else if (data == 201) { + $('.wr-validation-summary strong').text("User created."); + $('.wr-validation-summary strong').removeClass("label-danger"); + $('.wr-validation-summary strong').addClass("label-success"); + $(".sign-panel").delay(2000).slideUp(); + } else if (data == 400) { + $('.wr-validation-summary strong').text("Exception at backend."); + $('.wr-validation-summary strong').removeClass("label-danger"); + $('.wr-validation-summary strong').addClass("label-warning"); + } else if (data == 403) { + $('.wr-validation-summary strong').text("Action not permitted."); + } else if (data == 409) { + $('.wr-validation-summary strong').text("User exists."); + $('.wr-validation-summary strong').removeClass("label-default"); + $('.wr-validation-summary strong').addClass("label-success"); + } + $('.wr-validation-summary').removeClass("hidden"); + $('#password').val(''); + $('#password_confirmation').val(''); + // return true; + }, + error: function () { + $('.wr-validation-summary strong').text("An unexpected error occurred."); + $('.wr-validation-summary').removeClass("hidden"); + // return false; + } + }); + } + }); +}); + + + diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/public/scripts/validate-register.js b/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/public/scripts/validate-register.js deleted file mode 100644 index 457ebe61..00000000 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/public/scripts/validate-register.js +++ /dev/null @@ -1,143 +0,0 @@ - -var emailIsValid = function(email) { - var atPosition = email.indexOf("@"); - var dotPosition = email.lastIndexOf("."); - return !(atPosition < 1 || ( dotPosition - atPosition < 2 )); -}; - -var validatePassword = function (psswd, conPass) { - var error = ""; - var illegalChars = /[\W_]/; // allow only letters and numbers - - if ((psswd.length < 5) || (psswd.length > 15)) { - error = "The password is of wrong length. Should be between 5 and 15 characters. \n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - return false; - - } else if (illegalChars.test(psswd)) { - error = "The password contains illegal characters.\n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - return false; - - } else if ( (psswd.search(/[a-zA-Z]+/)==-1) || (psswd.search(/[0-9]+/)==-1) ) { - error = "The password must contain at least one numeral and one character.\n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - return false; - - } else if ( psswd != conPass ) { - error = "The password and confirm-password should match.\n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - - } else { - return true; - } - -}; - - - - $(function () { - $("button#add-user-btn").click(function(){ - //e.preventDefault(); - var username = $("input#user_name").val(); - var firstname = $("input#first_name").val(); - var lastname = $("input#last_name").val(); - var emailAddress = $("input#email").val(); - var password = $("input#password").val(); - var passwordConfirm = $("input#password_confirmation").val(); - - - // var userRoles = $("select#roles").val(); - - if (!firstname) { - $('.wr-validation-summary strong').text("Firstname is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!lastname) { - $('.wr-validation-summary strong').text("Lastname is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!username) { - $('span.wr-validation-summary strong').text("Username is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - }else if (!emailAddress) { - $('.wr-validation-summary strong').text("Email is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!emailIsValid(emailAddress)) { - $('.wr-validation-summary strong').text("Email is not valid. Please enter a correct email address."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!password) { - $('.wr-validation-summary strong').text("Please enter a user login password."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!passwordConfirm) { - $('.wr-validation-summary strong').text("Please re-type password"); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!validatePassword(password, passwordConfirm)) { - // return false; - } else if (!$('#t_and_c').is(':checked')) { - $('.wr-validation-summary strong').text("Please accept our terms and conditions"); - $('.wr-validation-summary').removeClass("hidden"); - } else { - - var addUserFormData = {}; - addUserFormData.username = username; - addUserFormData.firstname = firstname; - addUserFormData.lastname = lastname; - addUserFormData.emailAddress = emailAddress; - addUserFormData.password = password; - addUserFormData.userRoles = null; - - var addUserAPI = "/login/users/registration"; - - $.ajax({ - type:'POST', - url:addUserAPI, - contentType:'application/json', - data:JSON.stringify(addUserFormData), - success:function(data){ - if (data == 200) { - $('.wr-validation-summary strong').text("Successfully Submitted."); - $('.wr-validation-summary strong').removeClass("label-danger"); - $('.wr-validation-summary strong').addClass("label-success"); - } else if (data == 201) { - $('.wr-validation-summary strong').text("User created."); - $('.wr-validation-summary strong').removeClass("label-danger"); - $('.wr-validation-summary strong').addClass("label-success"); - } else if (data == 400) { - $('.wr-validation-summary strong').text("Exception at backend."); - $('.wr-validation-summary strong').removeClass("label-danger"); - $('.wr-validation-summary strong').addClass("label-warning"); - } else if (data == 403) { - $('.wr-validation-summary strong').text("Action not permitted."); - } else if (data == 409) { - $('.wr-validation-summary strong').text("User exists."); - $('.wr-validation-summary strong').removeClass("label-default"); - $('.wr-validation-summary strong').addClass("label-success"); - } - $('.wr-validation-summary').removeClass("hidden"); - $('#password').val(''); - $('#password_confirmation').val(''); - // return true; - }, - error:function(){ - $('.wr-validation-summary strong').text("An unexpected error occurred."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } - }); - } - }); - }); - - - diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/showcase.hbs b/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/showcase.hbs index ab12e611..1d1a70b3 100755 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/showcase.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/showcase/showcase.hbs @@ -69,7 +69,3 @@ {{/zone}} - -{{#zone "bottomJs"}} - -{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/custom-theme.css b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/custom-theme.css index 28b2b25b..2c318e88 100755 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/custom-theme.css +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/custom-theme.css @@ -35,4 +35,9 @@ input[type="checkbox"], input[type="radio"] { line-height: normal; margin-top: -3px; width: 30px; +} +.navbar-default .navbar-nav>li>a:focus, +.navbar-default .navbar-nav>li>a:hover { + color: #747474; + outline: 0; } \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/main.css b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/main.css index 057a4f44..e13b511c 100755 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/main.css +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/css/main.css @@ -255,7 +255,7 @@ h5{ font-size:30px;font-weight:100; line-height:Auto; font-style: normal; color: .black{color:#000;} .grey{color:#333;} .white{color:#FFF;} -.blue{color: #00979c;} +.blue{color: #00979c;} .blue:hover{color: #03c5cb;} .bold{font-weight:bold;} .no-underline{text-decoration:none;} diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/js/toggle.js b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/js/toggle.js index b66f1e28..86c5232a 100755 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/js/toggle.js +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/js/toggle.js @@ -5,4 +5,8 @@ $(document).ready(function(){ $(container).slideToggle("fast"); $(container).siblings('div.sign-panel').slideUp("fast"); }); + + $(".cancel-btn").click(function(){ + $(".sign-panel").slideUp(); + }); }); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/scripts/register.js b/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/scripts/register.js deleted file mode 100644 index caf53bdc..00000000 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/theme/public/scripts/register.js +++ /dev/null @@ -1,143 +0,0 @@ - -var emailIsValid = function(email) { - var atPosition = email.indexOf("@"); - var dotPosition = email.lastIndexOf("."); - return !(atPosition < 1 || ( dotPosition - atPosition < 2 )); -}; - -var validatePassword = function (psswd, conPass) { - var error = ""; - var illegalChars = /[\W_]/; // allow only letters and numbers - - if ((psswd.length < 5) || (psswd.length > 15)) { - error = "The password is of wrong length. Should be between 5 and 15 characters. \n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - return false; - - } else if (illegalChars.test(psswd)) { - error = "The password contains illegal characters.\n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - return false; - - } else if ( (psswd.search(/[a-zA-Z]+/)==-1) || (psswd.search(/[0-9]+/)==-1) ) { - error = "The password must contain at least one numeral and one character.\n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - return false; - - } else if ( psswd != conPass ) { - error = "The password and confirm-password should match.\n"; - $('.wr-validation-summary strong').text(error); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - - } else { - return true; - } - - }; - - - -// $(function () { - $("button#add-user-btn").click(function(){ - //e.preventDefault(); - var username = $("input#user_name").val(); - var firstname = $("input#first_name").val(); - var lastname = $("input#last_name").val(); - var emailAddress = $("input#email").val(); - var password = $("input#password").val(); - var passwordConfirm = $("input#password_confirmation").val(); - - - // var userRoles = $("select#roles").val(); - - if (!username) { - $('span.wr-validation-summary strong').text("Username is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!firstname) { - $('.wr-validation-summary strong').text("Firstname is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!lastname) { - $('.wr-validation-summary strong').text("Lastname is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!emailAddress) { - $('.wr-validation-summary strong').text("Email is a required field. It cannot be empty."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!emailIsValid(emailAddress)) { - $('.wr-validation-summary strong').text("Email is not valid. Please enter a correct email address."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!password) { - $('.wr-validation-summary strong').text("Please enter a user login password."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!passwordConfirm) { - $('.wr-validation-summary strong').text("Please re-type password"); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } else if (!validatePassword(password, passwordConfirm)) { - // return false; - } else if (!$('#t_and_c').is(':checked')) { - $('.wr-validation-summary strong').text("Please accept our terms and conditions"); - $('.wr-validation-summary').removeClass("hidden"); - } else { - - var addUserFormData = {}; - addUserFormData.username = username; - addUserFormData.firstname = firstname; - addUserFormData.lastname = lastname; - addUserFormData.emailAddress = emailAddress; - addUserFormData.password = password; - addUserFormData.userRoles = null; - - var addUserAPI = "/login/users/registration"; - - $.ajax({ - type:'POST', - url:addUserAPI, - contentType:'application/json', - data:JSON.stringify(addUserFormData), - success:function(data){ - if (data == 200) { - $('.wr-validation-summary strong').text("Successfully Submitted."); - $('.wr-validation-summary strong').removeClass("label-danger"); - $('.wr-validation-summary strong').addClass("label-success"); - } else if (data == 201) { - $('.wr-validation-summary strong').text("User created."); - $('.wr-validation-summary strong').removeClass("label-danger"); - $('.wr-validation-summary strong').addClass("label-success"); - } else if (data == 400) { - $('.wr-validation-summary strong').text("Exception at backend."); - $('.wr-validation-summary strong').removeClass("label-danger"); - $('.wr-validation-summary strong').addClass("label-warning"); - } else if (data == 403) { - $('.wr-validation-summary strong').text("Action not permitted."); - } else if (data == 409) { - $('.wr-validation-summary strong').text("User exists."); - $('.wr-validation-summary strong').removeClass("label-default"); - $('.wr-validation-summary strong').addClass("label-success"); - } - $('.wr-validation-summary').removeClass("hidden"); - $('#password').val(''); - $('#password_confirmation').val(''); - // return true; - }, - error:function(){ - $('.wr-validation-summary strong').text("An unexpected error occurred."); - $('.wr-validation-summary').removeClass("hidden"); - // return false; - } - }); - } - }); -// }); - - -