{"id":15184741,"url":"https://github.com/piyalidas10/login-logout-in-angularjs","last_synced_at":"2026-03-04T10:01:13.742Z","repository":{"id":120845937,"uuid":"109466396","full_name":"piyalidas10/Login-logout-in-angularjs","owner":"piyalidas10","description":"AngularJS Login Application and Session Create","archived":false,"fork":false,"pushed_at":"2017-11-04T07:34:31.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T14:51:57.682Z","etag":null,"topics":["angular","angular1","angularjs","authentication","authorization","form","localstorage","login","login-logout","loginform","session","session-management"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piyalidas10.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-04T04:20:14.000Z","updated_at":"2017-11-05T07:00:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"747dffdf-f8c1-4b69-b3be-9426290df652","html_url":"https://github.com/piyalidas10/Login-logout-in-angularjs","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"ace67299de731119dade7a0bc234c5ac63cdef23"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/piyalidas10/Login-logout-in-angularjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FLogin-logout-in-angularjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FLogin-logout-in-angularjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FLogin-logout-in-angularjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FLogin-logout-in-angularjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piyalidas10","download_url":"https://codeload.github.com/piyalidas10/Login-logout-in-angularjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyalidas10%2FLogin-logout-in-angularjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30078306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T08:01:56.766Z","status":"ssl_error","status_checked_at":"2026-03-04T08:00:42.919Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular1","angularjs","authentication","authorization","form","localstorage","login","login-logout","loginform","session","session-management"],"created_at":"2024-09-27T17:22:58.345Z","updated_at":"2026-03-04T10:01:13.724Z","avatar_url":"https://github.com/piyalidas10.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Login-logout-in-angularjs\n\nAngularJS Login Controller\n\nThe login function exposed by the controller calls the Authentication Service to authenticate the username and password entered into the view.\n\n\tapp.controller('loginCtrl', function($scope,$location,$rootScope,$sce){\n\t\t$rootScope.isLoggedIn = false;\n\t\t$scope.login = function(){\t\t\n\t\t\t\tif ($scope.loginform.$valid) {\n\t\t\t\t\tif($scope.email == 'admin@gmail.com' \u0026\u0026 $scope.pass == 'admin123')\n\t\t\t\t\t{\n\t\t\t\t\t\talert('login successful');\n\t\t\t\t\t\t$rootScope.isLoggedIn = true;\n\t\t\t\t\t\t$scope.UserId = $scope.email;\n\t\t\t\t\t\t$scope.session = $scope.email;\n\t\t\t\t\t\t$scope.sessionName = 'admin';\n\t\t\t\t\t\twindow.localStorage.setItem(\"SessionId\", $scope.session);\n\t\t\t\t\t\twindow.localStorage.setItem(\"SessionName\", $scope.sessionName);\n\t\t\t\t\t\twindow.localStorage.setItem(\"isLoggedIn\", $scope.isLoggedIn);\n\t\t\t\t\t\t\n\t\t\t\t\t\t//userDetails.SessionId = $scope.session;\n\t\t\t\t\t\t\n\t\t\t\t\t\t$location.path('/dashboard');\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\t$rootScope.isLoggedIn = false;\n\t\t\t\t\t\twindow.localStorage.setItem(\"isLoggedIn\", $rootScope.isLoggedIn);\n\t\t\t\t\t\t$scope.loginMessage = $sce.trustAsHtml('\u003ci class=\"fa fa-exclamation-triangle\"\u003e\u003c/i\u003e check your email id and password');\n\t\t\t\t\t\tconsole.log($scope.loginMessage);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t} \n\t\t\n\t});\n\t\n\t\nAngularJS Login View\n\nThe Login View contains a small form with the usual fields for emailid and password, and some validation messages.\n\n\t\t\u003cdiv class=\"container\"\u003e\n\t\t\t\t\t\t\n\t\t\t\t\t\t\u003cdiv class=\"col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-12\"\u003e\n\t\t\t\t\t\t\t\u003cdiv class=\"login clearfix\"\u003e\n\t\t\t\t\t\t\t\t\u003ch4\u003eLogin\u003c/h4\u003e    \n\t\t\t\t\t\t\t\t\u003cform name=\"loginform\" ng-submit=\"login()\"\u003e\n\t\t\t\t\t\t\t\t\t\u003cdiv class=\"header header-primary text-center\"\u003e\n\t\t\t\t\t\t\t\t\t\t\u003cdiv class=\"logo-container\"\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003cimg src=\"../assets/img/now-logo.png\" alt=\"\"\u003e\n\t\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\u003cdiv class=\"content\"\u003e\n\t\t\t\t\t\t\t\t\t\t\u003cdiv class=\"input-group form-group-no-border input-lg\"\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003cspan class=\"input-group-addon\"\u003e\n\t\t\t\t\t\t\t\t\t\t\t\t\u003ci class=\"fa fa-envelope\"\u003e\u003c/i\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003c/span\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003cinput type=\"email\" name=\"email\" ng-model=\"email\" class=\"form-control\" placeholder=\"Email...\"  required/\u003e\n\t\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n                                        \u003cdiv class=\"alert alert-danger\" ng-show=\"loginform.email.$dirty \u0026\u0026 loginform.email.$invalid\"\u003e\n      \t\t\t\t\t\t\t\t\t\t\u003cspan ng-show=\"loginform.email.$error.required\"\u003eEmail is required.\u003c/span\u003e\n      \t\t\t\t\t\t\t\t\t\t\u003cspan ng-show=\"loginform.email.$error.email\"\u003eInvalid email address.\u003c/span\u003e\n      \t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\t\u003cdiv class=\"input-group form-group-no-border input-lg\"\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003cspan class=\"input-group-addon\"\u003e\n\t\t\t\t\t\t\t\t\t\t\t\t\u003ci class=\"fa fa-lock\"\u003e\u003c/i\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003c/span\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003cinput type=\"password\" name=\"pass\" ng-model=\"pass\" placeholder=\"Password...\" ng-minlength=\"8\" ng-maxlength=\"15\" class=\"form-control\" required/\u003e\n\t\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n                                        \u003cdiv class=\"alert alert-danger\" ng-show=\"loginform.pass.$dirty \u0026\u0026 loginform.pass.$invalid\"\u003e\n      \t\t\t\t\t\t\t\t\t\t\u003cspan ng-show=\"loginform.pass.$error.required\"\u003ePassword is required.\u003c/span\u003e\n                                            \u003cspan ng-if=\"!loginform.pass.$valid\"\u003e\n                                            \t\u003cspan ng-show=\"loginform.pass.$error.minlength\"\u003eThe length is too short.\u003c/span\u003e\n                                                \u003cspan ng-show=\"loginform.pass.$error.maxlength\"\u003eThe length is too long.\u003c/span\u003e\n                                            \u003c/span\u003e\n      \t\t\t\t\t\t\t\t\t\u003c/div\u003e\n                                        \u003cspan class=\"badge\" ng-bind-html=\"loginMessage\"\u003e\u003c/span\u003e\n\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\u003cdiv class=\"footer col-xs-12 text-center\"\u003e\n\t\t\t\t\t\t\t\t\t\t\u003cbutton type=\"submit\" class=\"btn btn-success btn-simple btn-round btn-block\" ng-disabled=\"loginform.$invalid\"\u003eLog In\u003c/button\u003e\n\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\u003cdiv class=\"col-xs-12\"\u003e\n\t\t\t\t\t\t\t\t\t\t\u003ch6 class=\"text-center\"\u003e\n\t\t\t\t\t\t\t\t\t\t\t\u003ca href=\"#/forgotpass\" class=\"link\"\u003eForgot Password?\u003c/a\u003e\n\t\t\t\t\t\t\t\t\t\t\u003c/h6\u003e\n\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\u003c/form\u003e\n\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\u003c/div\u003e\n\n\nAngularJS App.js\n\nThe part of this file related to authentication is in the run function, when the app starts it checks if there's a localStorage containing user credentials meaning the user has already logged in, this is to keep the user logged in after a page refresh.\n\nOn each location change there's a check using checkAuth factory to verify that the user is logged in if trying to access a restricted page, if not they're redirected to the login page.\n\nWrite the following code to call factory after window.localStorage.getItem(\"isLoggedIn\") because with eachtime page refresh isLoggedIn variable's value will be null and have to fetch the value from localstorage.\n$scope.check = checkAuth.getuserInfo();\n\n\t\tvar app = angular.module('loginApp',['ngRoute']);\n\n\t\tapp.config([ '$routeProvider', '$locationProvider',\n\t\t    function($routeProvider, $locationProvider) {   \n\t\t\t$routeProvider\n\n\t\t\t\t.when('/',{\n\t\t\t\t\t\ttemplateUrl : 'view/login.html',\n\t\t\t\t\t\tcontroller : 'loginCtrl'\n\t\t\t\t})\n\n\t\t\t\t.when('/dashboard',{\n\t\t\t\t\t\ttemplateUrl : 'view/dashboard.html',\n\t\t\t\t\t\tcontroller : 'dashCtrl'\n\t\t\t\t})\t\t\n\n\t\t\t} \n\t\t]);\t\t\n\n\t\t/* Create factory to Disable Browser Back Button only after Logout */\n\t\tapp.factory(\"checkAuth\", function($location,$rootScope){\n\t\t    return {\n\t\t\tgetuserInfo : function(){\n\t\t\t\t\tif($rootScope.isLoggedIn === undefined || $rootScope.isLoggedIn === null){\n\t\t\t\t\t\t$location.path('/');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t    };\n\t\t});\n\n\t\tapp.controller('loginCtrl', function($scope,$location,$rootScope,$sce){\n\t\t\t\t$rootScope.isLoggedIn = false;\n\t\t\t\t$scope.login = function(){\t\t\n\t\t\t\t\t\tif ($scope.loginform.$valid) {\n\t\t\t\t\t\t\tif($scope.email == 'admin@gmail.com' \u0026\u0026 $scope.pass == 'admin123')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\talert('login successful');\n\t\t\t\t\t\t\t\t$rootScope.isLoggedIn = true;\n\t\t\t\t\t\t\t\t$scope.UserId = $scope.email;\n\t\t\t\t\t\t\t\t$scope.session = $scope.email;\n\t\t\t\t\t\t\t\t$scope.sessionName = 'admin';\n\t\t\t\t\t\t\t\twindow.localStorage.setItem(\"SessionId\", $scope.session);\n\t\t\t\t\t\t\t\twindow.localStorage.setItem(\"SessionName\", $scope.sessionName);\n\t\t\t\t\t\t\t\twindow.localStorage.setItem(\"isLoggedIn\", $scope.isLoggedIn);\n\n\t\t\t\t\t\t\t\t//userDetails.SessionId = $scope.session;\n\n\t\t\t\t\t\t\t\t$location.path('/dashboard');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t$rootScope.isLoggedIn = false;\n\t\t\t\t\t\t\t\twindow.localStorage.setItem(\"isLoggedIn\", $rootScope.isLoggedIn);\n\t\t\t\t\t\t\t\t$scope.loginMessage = $sce.trustAsHtml('\u003ci class=\"fa fa-exclamation-triangle\"\u003e\u003c/i\u003e check your email id and password');\n\t\t\t\t\t\t\t\tconsole.log($scope.loginMessage);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t} \n\n\t\t\t});\n\t\n\t\tapp.controller('dashCtrl', function($scope,$location,$rootScope,$http,checkAuth){\t\t\n\n\t\t\t$rootScope.session = window.localStorage.getItem(\"SessionId\");\n\t\t\t$rootScope.userName = window.localStorage.getItem(\"SessionName\");\n\t\t\t$rootScope.isLoggedIn = window.localStorage.getItem(\"isLoggedIn\");\n\n\t\t\t// Call checkAuth factory for cheking login details\n\t\t\t$scope.check = checkAuth.getuserInfo();\n\n\t\t\t$scope.logout = function () {\n\t\t\t\t\twindow.localStorage.clear();\n\t\t\t\t\t$rootScope.isLoggedIn = false;\n\t\t\t\t\t$location.path(\"/\");\n\t\t\t};\n\n\t\t});\n\t\n\t\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyalidas10%2Flogin-logout-in-angularjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiyalidas10%2Flogin-logout-in-angularjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyalidas10%2Flogin-logout-in-angularjs/lists"}