stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject git commit: Adding validation for the login page
Date Thu, 06 Feb 2014 08:15:15 GMT
Updated Branches:
  refs/heads/master 6474a7916 -> 15401c071


Adding validation for the login page


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/15401c07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/15401c07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/15401c07

Branch: refs/heads/master
Commit: 15401c071838aa552b18cfba432d94809ca232d2
Parents: 6474a79
Author: Chanaka <chanaka@chanaka-TECRA-M11.(none)>
Authored: Thu Feb 6 13:05:23 2014 +0530
Committer: rekathiru <rthirunavukkarasu23@gmail.com>
Committed: Thu Feb 6 13:45:06 2014 +0530

----------------------------------------------------------------------
 .../console/controllers/loginSubmit.jag         | 38 ++++++-----
 .../console/login.jag                           |  7 +-
 .../console/themes/theme1/partials/login.hbs    | 12 ++--
 .../console/themes/theme1/renderers/login.js    | 11 +++-
 .../console/themes/theme1/ui/css/main.css       |  9 ++-
 .../console/themes/theme1/ui/js/login.js        | 68 ++++++++++++++++++++
 6 files changed, 122 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/15401c07/components/org.apache.stratos.manager.console/console/controllers/loginSubmit.jag
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/controllers/loginSubmit.jag
b/components/org.apache.stratos.manager.console/console/controllers/loginSubmit.jag
index 6fb41f4..0ade4d8 100644
--- a/components/org.apache.stratos.manager.console/console/controllers/loginSubmit.jag
+++ b/components/org.apache.stratos.manager.console/console/controllers/loginSubmit.jag
@@ -7,25 +7,33 @@
     //TODO: handle the angry path...
     var username = request.getParameter("username").trim();
     var password = request.getParameter("password"); // not trimming the password
+    if(username || password){
+        session.put("error","Enter your username and password.");
+    }
     //authenticate with carbon usr-store
     log.info("Username : " + username);
     log.info("Password : "+ password);
     var auth = server.authenticate(username, password);
-    var userObject = carbon.server.tenantUser(username);
-    var um = new carbon.user.UserManager({}, userObject.tenantId);
-    var user = um.getUser('admin');
-    var roles = user.getRoles();
-    //storing in session
-    session.put("TENANT_DOMAIN",userObject.domain);
-    session.put("ROLE_ARRAY",roles);
-    //call the authentication rest-endpoint and get the JSESSION_ID
-    var result =  utils.consoleAppUtil.getSessionCookie(username,password);
-    log.info(result.data.Success.sessionId);
-    //TODO: handle the error scenario
-    //save the JSESSION_ID in current console.session.
-    var jSessionId = result.data.Success.sessionId;
-    session.put("JSESSIONID",jSessionId);
-    require('console').server.current(session,username);
+    if(!auth){
+        session.put("error","The username or password you entered is incorrect.")
+    }else{
+        var userObject = carbon.server.tenantUser(username);
+        var um = new carbon.user.UserManager({}, userObject.tenantId);
+        var user = um.getUser('admin');
+        var roles = user.getRoles();
+        //storing in session
+        session.put("TENANT_DOMAIN",userObject.domain);
+        session.put("ROLE_ARRAY",roles);
+        //call the authentication rest-endpoint and get the JSESSION_ID
+        var result =  utils.consoleAppUtil.getSessionCookie(username,password);
+        log.info(result.data.Success.sessionId);
+        //TODO: handle the error scenario
+        //save the JSESSION_ID in current console.session.
+        var jSessionId = result.data.Success.sessionId;
+        session.put("JSESSIONID",jSessionId);
+        require('console').server.current(session,username);
+    }
+
     //redirect
     response.sendRedirect(request.getContextPath()+'/index.jag');
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/15401c07/components/org.apache.stratos.manager.console/console/login.jag
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/login.jag b/components/org.apache.stratos.manager.console/console/login.jag
index b63847d..8d0255c 100644
--- a/components/org.apache.stratos.manager.console/console/login.jag
+++ b/components/org.apache.stratos.manager.console/console/login.jag
@@ -1,5 +1,10 @@
 <%
 var caramel = require('caramel');
+var error = session.get("error");
+if(error == null) {
+    error = "";
+}
+session.remove("error"); // remove previous errors if any
 
-caramel.render({});
+caramel.render({error:error});
 %>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/15401c07/components/org.apache.stratos.manager.console/console/themes/theme1/partials/login.hbs
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/themes/theme1/partials/login.hbs
b/components/org.apache.stratos.manager.console/console/themes/theme1/partials/login.hbs
index 5857e5c..fd4c090 100644
--- a/components/org.apache.stratos.manager.console/console/themes/theme1/partials/login.hbs
+++ b/components/org.apache.stratos.manager.console/console/themes/theme1/partials/login.hbs
@@ -5,16 +5,17 @@
             <div class="login-box">
                 <div class="login-box-top">
                     <h2 class="login-sub-title">Login to create cartridges</h2>
-                    <form method="post" action="{{url "/loginSubmit"}}">
+                    <form method="post" action="{{url "/loginSubmit"}}" id="loginForm">
                         <div class="username-wrapper">
-                            <input name="username" class="input-username" type="text"
placeholder="Email" />
+                            <input name="username" id="username" class="input-username"
type="text" placeholder="Username" />
                         </div>
                         <div class="password-wrapper">
-                            <input name="password" class="input-password" type="text"
placeholder="Password" />
+                            <input name="password" id="password" class="input-password"
type="password" placeholder="Password" />
                         </div>
 
                         <div class="login-button-wrapper">
-                            <button class="btn btn-primary login-button" type="submit">Sign
In</button>
+                            <div class="loginError" id="loginError" {{#unless hasError}}style="display:
none"{{/unless}} >{{#if hasError}}{{error}}{{/if}}</div>
+                            <button class="btn btn-primary login-button" type="button"
id="loginButton">Sign In</button>
                         </div>
                     </form>
                 </div>
@@ -28,4 +29,5 @@
             <div class="login-box-footer"></div>
         </div>
     </div>
-</div>
\ No newline at end of file
+</div>
+<script src="{{url "/themes/theme1/ui/js/login.js"}}"></script>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/15401c07/components/org.apache.stratos.manager.console/console/themes/theme1/renderers/login.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/themes/theme1/renderers/login.js
b/components/org.apache.stratos.manager.console/console/themes/theme1/renderers/login.js
index c2f5e56..4481965 100644
--- a/components/org.apache.stratos.manager.console/console/themes/theme1/renderers/login.js
+++ b/components/org.apache.stratos.manager.console/console/themes/theme1/renderers/login.js
@@ -1,9 +1,18 @@
 var render = function (theme, data, meta, require) {
+    var log = new Log();
+    log.info(data.error);
+    var hasError = true;
+    if(data.error == ""){
+        hasError = false;
+    }
     theme('index', {
         body: [
             {
                 partial: 'login',
-                context: {}
+                context: {
+                    error:data.error,
+                    hasError:hasError
+                }
             }
         ],
         header: [

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/15401c07/components/org.apache.stratos.manager.console/console/themes/theme1/ui/css/main.css
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/themes/theme1/ui/css/main.css
b/components/org.apache.stratos.manager.console/console/themes/theme1/ui/css/main.css
index 8dad3c2..66800d9 100644
--- a/components/org.apache.stratos.manager.console/console/themes/theme1/ui/css/main.css
+++ b/components/org.apache.stratos.manager.console/console/themes/theme1/ui/css/main.css
@@ -87,7 +87,7 @@ h2.login-sub-title{
     padding-left:40px;
 }
 .login-button-wrapper{
-    margin:20px 10px;
+    margin:34px 10px 20px;
 }
 div.username-wrapper input.input-username{
     height:60px;
@@ -486,4 +486,11 @@ li.dropdown ul.dropdown-menu li a i{
 label.error{
     color: #be0000;
     padding-bottom: 10px;
+}
+.loginError{
+    color: #BE0000;
+    margin-top: -27px;
+    position: absolute;
+    text-align: center;
+    width: 395px;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/15401c07/components/org.apache.stratos.manager.console/console/themes/theme1/ui/js/login.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager.console/console/themes/theme1/ui/js/login.js
b/components/org.apache.stratos.manager.console/console/themes/theme1/ui/js/login.js
new file mode 100644
index 0000000..93d80bb
--- /dev/null
+++ b/components/org.apache.stratos.manager.console/console/themes/theme1/ui/js/login.js
@@ -0,0 +1,68 @@
+$(function(){
+    var $username = $('#username');
+    var $password = $('#password');
+    var $loginForm = $('#loginForm');
+    var isValidForm = function(){
+        if($username.val() == "" || $password.val() == ""){
+            var error = "Enter your username";
+            if($username.val() == ""){
+                $username.addClass('error');
+            }else{
+                $username.removeClass('error');
+                error = "";
+            }
+
+            if($password.val() == ""){
+                $password.addClass('error');
+                if(error == ""){
+                    error = "Enter your password";
+                }else{
+                    error = "Enter your username and password";
+                }
+            }else{
+                $password.removeClass('error');
+            }
+            $('#loginError').html(error).show();
+            return false;
+        }else{
+            $username.removeClass('error');
+            $password.removeClass('error');
+            $('#loginError').hide();
+            return true;
+        }
+
+    };
+    var submitForm = function(){
+        if(isValidForm()){
+            $loginForm.submit();
+        }else{
+            if($password.val() == ""){
+                $password.focus();
+            }
+            if($username.val() == ""){
+                $username.focus();
+            }
+
+            $username.keyup(function(){
+                isValidForm();
+            });
+            $password.keyup(function(){
+                isValidForm();
+            });
+        }
+    }
+    $('#loginButton').click(function(){
+        submitForm();
+    });
+    $username.keyup(function(e){
+          if(e.which == "13"){
+              submitForm();
+          }
+    });
+    $password.keyup(function(e){
+          if(e.which == "13"){
+              submitForm();
+          }
+    });
+    $username.focus();
+});
\ No newline at end of file


Mime
View raw message