diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.hbs new file mode 100644 index 0000000000..e9dd3b4abf --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.hbs @@ -0,0 +1,5 @@ +{{unit "cdmf.unit.ui.title" pageTitle="Register"}} + +{{#zone "content"}} + {{unit "iot.unit.user.register"}} +{{/zone}} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.js new file mode 100644 index 0000000000..1f2b0affa4 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.js @@ -0,0 +1,3 @@ +function onRequest(context) { + +} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.json new file mode 100644 index 0000000000..13a1bda7e0 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/pages/iot.page.register/register.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/register", + "layout": "uuf.layout.sign-in" +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/public/js/validate-register.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/public/js/validate-register.js new file mode 100644 index 0000000000..df42e7c09a --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/public/js/validate-register.js @@ -0,0 +1,145 @@ +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 context = $(".form-login-box").attr("action"); + + var addUserAPI = context + "/api/user/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. You will be redirected to login page"); + $('.wr-validation-summary strong').removeClass("label-danger"); + $('.wr-validation-summary strong').addClass("label-success"); + setTimeout(function () { + window.location = context + "/login"; + }, 2000); + } 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 (err) { + $('.wr-validation-summary strong').text("An unexpected error occurred."); + $('.wr-validation-summary').removeClass("hidden"); + return false; + } + }); + } + return false; + }); +}); + + + diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs new file mode 100644 index 0000000000..4cf428d124 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.hbs @@ -0,0 +1,65 @@ +
+ +

Register

+ +

Create new account on IoT Server

+ + + + +
+ +
+ + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ +
+ + I Agree by Clicking register, you agree to the Terms and Conditions set out by this site +
+ +
+ + +
+
+ +
+{{#zone "bottomLoginJs"}} + {{js "js/validate-register.js"}} +{{/zone}} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.js new file mode 100644 index 0000000000..1009781180 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.js @@ -0,0 +1,4 @@ +function onRequest(context){ + context.registerPath = "api/user/register"; + return context; +} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.json new file mode 100644 index 0000000000..9eecd8f5bf --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.register/register.json @@ -0,0 +1,3 @@ +{ + "version": "1.0.0" +} \ No newline at end of file diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/public/js/login.js b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/public/js/login.js new file mode 100644 index 0000000000..1feefb379b --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/public/js/login.js @@ -0,0 +1,50 @@ +function post(path, method) { + method = method || "post"; // Set method to post by default if not specified. + form.submit(); +} + + +$( document ).ready(function() { + var currentHash = window.location.hash, + submitPath = $("#signInForm").attr("action"); + if(currentHash=="#auth-failed") { + $('.wr-validation-summary p').text("Sorry!, Please make sure to enter correct username and password"); + $('.wr-validation-summary').removeClass("hidden"); + }else if(currentHash=="#error"){ + $('.wr-validation-summary p').text("Sorry!, Error occured"); + $('.wr-validation-summary').removeClass("hidden"); + } + $('#signIn').click(function(){ + var username = $("input#username").val(), + password = $("input#password").val(); + + if (!username) { + $('.wr-validation-summary p').text("Sorry!, Username cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + } else if (!password){ + $('.wr-validation-summary p').text("Sorry!, Password cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + } else { + post(submitPath,"POST"); + } + }); +}); + + +function submitLoginForm() { + var submitPath = $("#signInForm").attr("action"); + $('form input').keypress(function() { + if(e.which == 10 || e.which == 13) { + if (!username) { + alert() + $('.wr-validation-summary p').text("Sorry!, Username cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + } else if (!password){ + $('.wr-validation-summary p').text("Sorry!, Password cannot be empty."); + $('.wr-validation-summary').removeClass("hidden"); + } else { + post(submitPath,"POST"); + } + } + }); +} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/sign-in.hbs b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/sign-in.hbs new file mode 100644 index 0000000000..9792da2d52 --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/sign-in.hbs @@ -0,0 +1,44 @@ +
+ +

Login

+
+ + +
+
+
+ + +
+
+ + +
+
+ +
+
+ {{#if showRememberMe}} + + Remember me + + {{/if}} + {{#if showCreateAccount}} + + {{/if}} +
+
+
+
+ +{{#zone "bottomLoginJs"}} + {{js "js/login.js" }} +{{/zone}} diff --git a/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/sign-in.json b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/sign-in.json new file mode 100644 index 0000000000..93112184fa --- /dev/null +++ b/features/device-mgt-iot-feature/org.wso2.carbon.device.mgt.iot.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.user.sign-in/sign-in.json @@ -0,0 +1,4 @@ +{ + "version": "1.0.0", + "extends" : "cdmf.unit.user.sign-in" +} \ No newline at end of file