Commit 3459bcf483931a1b127cbeb55eec05091b80ca5d
1 parent
66ee5529fa
Exists in
master
modify new module
Showing
3 changed files
with
41 additions
and
152 deletions
Show diff stats
src/app/components/authentication/authentication.controller.js
1 | (function(){ | 1 | (function(){ |
2 | 'use strict'; | 2 | 'use strict'; |
3 | 3 | ||
4 | angular.module('sbAdminApp') | 4 | angular.module('sbAdminApp') |
5 | .controller('LoginCtrl', ['$scope', '$rootScope', '$state','$mdDialog','$log', 'AUTH_EVENTS', 'LoginService', 'toaster', loginCtrl]); | 5 | .controller('LoginCtrl', ['$scope', '$rootScope', '$state','$mdDialog','$log', 'AUTH_EVENTS', 'LoginService', 'toaster', loginCtrl]); |
6 | 6 | ||
7 | function loginCtrl($scope, $rootScope, $state, $mdDialog,$log, AUTH_EVENTS, LoginService ,toaster) { | 7 | function loginCtrl($scope, $rootScope, $state, $mdDialog,$log, AUTH_EVENTS, LoginService ,toaster) { |
8 | $scope.doLogin = function() { | 8 | $scope.data={} |
9 | $rootScope.auth = window.btoa($scope.loginData.email + ':' + $scope.loginData.password); | 9 | $scope.create = function() { |
10 | LoginService.doLogin().save($scope.loginData).$promise.then(function(result) { | 10 | LoginService.createForm().save($scope.data).$promise.then(function(result) { |
11 | console.log("result",result); | 11 | if(result != null){ |
12 | if(result){ | 12 | toaster.success("form successfully created"); |
13 | $rootScope.$broadcast(AUTH_EVENTS.updateUser); | 13 | // $state.go('app.awards'); |
14 | LoginService.setUser(result); | 14 | } |
15 | /*if(result.role === 'admin'){ | 15 | }, function error(error) { |
16 | $state.go("app.user"); | 16 | if(error){ |
17 | } else { | 17 | toaster.error("Server error"); |
18 | $state.go("app."); | 18 | } |
19 | } */ | ||
20 | $state.go("app.user"); | ||
21 | } | ||
22 | if (Notification.permission !== 'denied') { | ||
23 | Notification.requestPermission(function(permission) { | ||
24 | // If the user accepts, let's create a notification | ||
25 | if (permission === "granted") { | ||
26 | /*var notification = new Notification("Hello!");*/ | ||
27 | } | ||
28 | }); | ||
29 | } | ||
30 | }, | ||
31 | function error(error) { | ||
32 | console.log("ererrorror",error); | ||
33 | if(error){ | ||
34 | toaster.error("server error"); | ||
35 | } | ||
36 | }); | ||
37 | |||
38 | } | ||
39 | $scope.signUp=function(){ | ||
40 | |||
41 | LoginService.signUp().save($scope.signupData).$promise.then(function(result) { | ||
42 | console.log("result",result); | ||
43 | // toaster.success("signed up successfully") | ||
44 | $mdDialog.show( | ||
45 | $mdDialog.alert() | ||
46 | .clickOutsideToClose(true) | ||
47 | .title() | ||
48 | .textContent("Please check your email and click on the verification link before logging in.") | ||
49 | .ariaLabel('Alert') | ||
50 | .ok('ok') | ||
51 | ); | ||
52 | |||
53 | }); | 19 | }); |
54 | 20 | ||
55 | |||
56 | } | ||
57 | |||
58 | } | 21 | } |
22 |
src/app/components/authentication/authentication.service.js
1 | (function(){ | 1 | (function(){ |
2 | 'use strict'; | 2 | 'use strict'; |
3 | 3 | ||
4 | angular.module('sbAdminApp') | 4 | angular.module('sbAdminApp') |
5 | .service('LoginService', ['$q', '$http', '$rootScope', '$resource', 'BASE_URL', 'USER_ROLES', LoginService]); | 5 | .service('LoginService', ['$q', '$http', '$rootScope', '$resource', 'BASE_URL', 'USER_ROLES', LoginService]); |
6 | 6 | ||
7 | function LoginService($q, $http, $rootScope, $resource, BASE_URL, USER_ROLES) { | 7 | function LoginService($q, $http, $rootScope, $resource, BASE_URL, USER_ROLES) { |
8 | 8 | ||
9 | var authService = {}, | 9 | this.createForm = function(){ |
10 | admin = '', | 10 | return $resource(BASE_URL+'/userProfiles', |
11 | user = '', | 11 | {}); |
12 | role = '', | 12 | |
13 | isAuthenticated = false; | ||
14 | |||
15 | if (window.localStorage.getItem("loginStatus")) { | ||
16 | isAuthenticated = true; | ||
17 | $rootScope.userDetails = JSON.parse(localStorage.getItem("userDetails")); | ||
18 | role = $rootScope.userDetails.role.toUpperCase(); | ||
19 | } | ||
20 | |||
21 | this.setUser = function (res) { | ||
22 | localStorage.setItem('loginStatus', true); | ||
23 | localStorage.setItem('userDetails', JSON.stringify(res)); | ||
24 | isAuthenticated = true; | ||
25 | $rootScope.userDetails = JSON.parse(localStorage.getItem("userDetails")); | ||
26 | role = $rootScope.userDetails.role.toUpperCase(); | ||
27 | } | ||
28 | |||
29 | this.isAuthenticated = function () { | ||
30 | return isAuthenticated; | ||
31 | }; | ||
32 | |||
33 | this.role = function () { | ||
34 | return role; | ||
35 | }; | ||
36 | |||
37 | this.getUser = function () { | ||
38 | return JSON.parse(window.localStorage.getItem("userDetails")); | ||
39 | } | ||
40 | |||
41 | this.isAuthorized = function (authorizedRoles) { | ||
42 | if (!angular.isArray(authorizedRoles)) { | ||
43 | authorizedRoles = [authorizedRoles]; | ||
44 | } | ||
45 | return (this.isAuthenticated() && authorizedRoles.indexOf(role) !== -1); | ||
46 | } | 13 | } |
47 | 14 | ||
48 | this.signUp = function() { | ||
49 | return $resource(BASE_URL+'/users/signUp'); | ||
50 | } | ||
51 | |||
52 | //Resource for REST APIs | ||
53 | this.doLogin = function() { | ||
54 | return $resource(BASE_URL+'/users/login'); | ||
55 | } | ||
56 | |||
57 | this.logOut = function(){ | ||
58 | return $resource(BASE_URL+'/users/logout', | ||
59 | {access_token:$rootScope.userDetails.id}) | ||
60 | } | ||
61 | |||
62 | this.deleteUser = function () { | ||
63 | isAuthenticated = false; | ||
64 | $rootScope.$loginStatus = false; | ||
65 | localStorage.clear(); | ||
66 | } | ||
67 | |||
68 | } | 15 | } |
69 | 16 | ||
70 | })(); | 17 | })(); |
src/app/components/authentication/template/login.html
1 | <h1 class="heading" style="text-align:center;">Startup Jalsa</h1> | 1 | <md-content class="md-padding" layout="row" layout-wrap layout-align="center start" style="width: 100%;background-color: #F1F1F1;"> |
2 | <md-content class="md-padding" layout="row" layout-wrap layout-align="end center" style="width: 100%;background-color: #e0e0e0;"> | 2 | <md-card style="padding: 20px 40px;width: 70%;"> |
3 | <md-card style="padding: 0px 20px;width:55%;margin-top: -180px;"> | ||
4 | <md-card-title> | 3 | <md-card-title> |
5 | <md-card-title-text style="text-align: center;color: dodgerblue;"> | 4 | <md-card-title-text style="text-align: center;color: black"> |
6 | <span class="md-headline">Login</span> | 5 | <span class="md-headline">Start Up Jalsa</span> |
7 | </md-card-title-text> | 6 | </md-card-title-text> |
8 | </md-card-title> | 7 | </md-card-title> |
9 | |||
10 | <form name="loginForm"> | 8 | <form name="loginForm"> |
11 | <div layout="column"> | ||
12 | <md-input-container class="md-block md-icon-float"> | 9 | <md-input-container class="md-block md-icon-float"> |
13 | <label>Email</label> | 10 | <label>Name</label> |
14 | <md-icon md-svg-src="assets/images/ic_email_black_24px.svg" class="name"></md-icon> | 11 | <md-icon md-svg-src="assets/images/ic_person_black_24px.svg"></md-icon> |
15 | <input ng-model="loginData.email"> | 12 | <input type="text" ng-model="data.name"> |
16 | </md-input-container> | 13 | </md-input-container> |
17 | <md-input-container class="md-block md-icon-float"> | 14 | <md-input-container class="md-block md-icon-float"> |
18 | <label>Password</label> | 15 | <label>Email</label> |
19 | <md-icon md-svg-src="assets/images/ic_remove_red_eye_black_24px.svg" class="password"></md-icon> | 16 | <md-icon md-svg-src="assets/images/ic_email_black_24px.svg" class="password"></md-icon> |
20 | <input type="password" ng-model="loginData.password"> | 17 | <input type="text" ng-model="data.password"> |
21 | </md-input-container> | ||
22 | <section layout="column" layout-align="start"> | ||
23 | <md-button class="md-primary md-raised" ng-click="doLogin()">Login</md-button> | ||
24 | </section> | ||
25 | </div> | ||
26 | </form> | ||
27 | </md-card> | ||
28 | </md-content> | ||
29 | <md-content class="md-padding" layout="row" layout-wrap layout-align="start center" style="width: 100%;background-color:#e0e0e0;"> | ||
30 | <md-card style="padding: 0px 20px;width:60%;"> | ||
31 | <md-card-title> | ||
32 | <md-card-title-text style="text-align: center;color: dodgerblue;"> | ||
33 | <span class="md-headline">Sign Up</span> | ||
34 | </md-card-title-text> | ||
35 | </md-card-title> | ||
36 | <div layout="column"> | ||
37 | <md-input-container class="md-block md-icon-float"> | ||
38 | <label>Username</label> | ||
39 | <md-icon md-svg-src="assets/images/ic_person_black_24px.svg" class="name"></md-icon> | ||
40 | <input ng-model="signupData.username"> | ||
41 | </md-input-container> | 18 | </md-input-container> |
42 | <md-input-container class="md-block md-icon-float"> | 19 | <md-input-container class="md-block md-icon-float"> |
43 | <label>Email</label> | 20 | <label>Mobile No.</label> |
44 | <md-icon md-svg-src="assets/images/ic_email_black_24px.svg" class="email"></md-icon> | 21 | <md-icon md-svg-src="assets/images/ic_phone_black_24px.svg"></md-icon> |
45 | <input ng-model="signupData.email"> | 22 | <input type="number" ng-model="data.phone"> |
46 | </md-input-container> | 23 | </md-input-container> |
47 | <md-input-container class="md-block md-icon-float"> | 24 | <md-input-container class="md-block md-icon-float"> |
48 | <label>Password</label> | 25 | <label>City</label> |
49 | <md-icon md-svg-src="assets/images/ic_remove_red_eye_black_24px.svg" class="password"></md-icon> | 26 | <md-icon <i class="material-icons">place</i></md-icon> |
50 | <input type="password" ng-model="signupData.password"> | 27 | <input type="text" ng-model="data.city"> |
51 | </md-input-container> | 28 | </md-input-container> |
52 | <md-input-container class="md-block md-icon-float"> | 29 | <md-input-container class="md-block md-icon-float"> |
53 | <label>Confirm Password</label> | 30 | <label>Monthly Income</label> |
54 | <md-icon md-svg-src="assets/images/ic_remove_red_eye_black_24px.svg" class="confirmPassword"></md-icon> | 31 | <md-icon <i class="material-icons">payment</i></md-icon> |
55 | <input type="password" ng-model="signupData.confirmPassword"> | 32 | <input type="text" ng-model="data.monthlyIncome"> |
56 | </md-input-container> | 33 | </md-input-container> |
57 | <section layout="column" layout-align="start"> | 34 | <div layout="row" layout-align="center center"> |
58 | <md-button class="md-primary md-raised" ng-click="signUp()">sign up</md-button> | 35 | <md-button class="md-raised md-primary" id="createPass" ng-disabled="loginForm.$invalid" ng-click="create()">submit</md-button> |
59 | </section> | 36 | </div> |
60 | </div> | ||
61 | </form> | 37 | </form> |
62 | </md-card> | 38 | </md-card> |
63 | </md-content> | 39 | </md-content> |
64 | <toaster-container toaster-options="{'time-out': 2000, 'close-button':true, 'animation-class': 'toast-top-right'}"></toaster-container> | 40 | <toaster-container toaster-options="{'time-out': 2000, 'close-button':true, 'animation-class': 'toast-top-right'}"></toaster-container> |