75 lines
2.7 KiB
JavaScript
Executable File
75 lines
2.7 KiB
JavaScript
Executable File
'use strict';
|
|
/*** controller for Wizard Form example***/
|
|
app.controller('changePasswordCtrl', ["$scope", "$filter", "ngTableParams", "API_POINTS", "$http", "SweetAlert", "$state", 'md5', 'ipCookie', function ($scope, $filter, ngTableParams, apiPoint, $http, SweetAlert, $state, md5, ipCookie) {
|
|
$scope.myModel = {
|
|
curr: "",
|
|
password: "",
|
|
password2: ""
|
|
};
|
|
|
|
$scope.currentStep = 1;
|
|
|
|
// get local cliend details
|
|
var localDetail = JSON.parse(localStorage.getItem('localObj'));
|
|
var localDetails = ipCookie('cookiechk');
|
|
|
|
// Initial Value
|
|
$scope.form = {
|
|
|
|
submit: function (form, myModel) {
|
|
var firstError = null;
|
|
if (form.$invalid) {
|
|
|
|
var field = null, firstError = null;
|
|
for (field in form) {
|
|
if (field[0] != '$') {
|
|
if (firstError === null && !form[field].$valid) {
|
|
firstError = form[field].$name;
|
|
}
|
|
|
|
if (form[field].$pristine) {
|
|
form[field].$dirty = true;
|
|
}
|
|
}
|
|
}
|
|
angular.element('.ng-invalid[name=' + firstError + ']').focus();
|
|
} else {
|
|
|
|
var req = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'changePassword/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
oldPassword: md5.createHash($scope.myModel.curr || ''),
|
|
newPassword: md5.createHash($scope.myModel.password || '') ,
|
|
UserId: localDetails.localUserID,
|
|
}
|
|
};
|
|
$http(req).then(function (response) {
|
|
if (response.data.changePassStatus == true) {
|
|
// SweetAlert.swal("Hello!", "Password changed Succesfully");
|
|
// $state.go($state.current, {}, { reload: true });
|
|
swal("Success!", response.data.message, "success");
|
|
form.$setPristine(true);
|
|
$scope.myModel = {
|
|
curr: "",
|
|
password1: "",
|
|
password2: ""
|
|
};
|
|
} else {
|
|
swal("Warning!", response.data.message, "warning");
|
|
// $state.go($state.current, {}, { reload: true });
|
|
}
|
|
}, function (error) {
|
|
//error function
|
|
});
|
|
}
|
|
},
|
|
reset: function () {
|
|
}
|
|
};
|
|
|
|
}]);
|