Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by vvn050 on 08.04.16.
- */
- (function () {
- 'use strict';
- angular
- .module('portal.client')
- .factory('loginService', ['$http', '$q', 'CONSTANTS', 'authenticationData','$location', function ($http, $q, CONSTANTS, authenticationData,$location) {
- var loginService = this,
- tokenEndPoint = CONSTANTS.BASE + CONSTANTS.TOKEN,
- deferred,
- userInfo;
- loginService.login = function (username, password, rememberMeChecked) {
- deferred = $q.defer();
- var data = "grant_type=password&username=" + username + "&password=" + password;
- $http.post(tokenEndPoint, data, {
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- }).success(function (response) {
- console.log(response);
- console.log('hoiata11111111111111');
- userInfo = {
- access_token: response.access_token,
- refresh_token: response.refresh_token,
- username: response.sub,
- expires_in: response.expires_in
- };
- if (rememberMeChecked) {
- authenticationData.setLocalStorage(userInfo);
- authenticationData.userInfo.storageInUse = 'localStorage';
- }
- else {
- authenticationData.setSessionStorage(userInfo);
- authenticationData.userInfo.storageInUse = 'sessionStorage';
- }
- authenticationData.userInfo.clientIsAuthenticated = true;
- authenticationData.userInfo.clientUsername = response.username;
- $location.path('dashboard');
- //TODO send user to a state
- // $state.go('index.');
- deferred.resolve(null);
- })
- .error(function (err) {
- console.log(err);
- authenticationData.userInfo.clientIsAuthenticated = false;
- authenticationData.userInfo.clientUsername = '';
- deferred.resolve(err);
- });
- return deferred.promise;
- };
- return this;
- }]);
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement