<commit_before>angular.module('app')


.factory('UserSrv', function($q, $http, ParseUtils, StorageUtils, Utils){
  'use strict';
  var storageKey = 'user';
  var defaultUser = { username: '', role: routingConfig.userRoles.public };
  var userCrud = null;
  var service = {
    getCurrent: getCurrent,
    isAuthorized: isAuthorized,
    isAuthorizedAsync: isAuthorizedAsync,
    isLoggedIn: isLoggedIn,
    isLoggedInAsync: isLoggedInAsync,
    signup: signup,
    login: login,
    passwordRecover: passwordRecover,
    logout: logout,
    saveUser: saveUser,
    savePartialUser: savePartialUser,
    accessLevels: routingConfig.accessLevels,
    userRoles: routingConfig.userRoles
  };
  getCurrent().then(function(user){
    //userCrud = CrudRestUtils.createCrud('/users');
    userCrud = ParseUtils.createUserCrud(user.sessionToken);
  });

  function getCurrent(){ return StorageUtils.get(storageKey, defaultUser); }
  function getCurrentSync(){ return StorageUtils.getSync(storageKey, defaultUser); }

  function saveUser(user){
    if(userCrud){
      return userCrud.save(user).then(function(){
        return StorageUtils.set(storageKey, user);
      });
    } else {
      return StorageUtils.set(storageKey, user);
    }
  }
  function savePartialUser(data){
    return getCurrent().then(function(user){
      if(userCrud){
        return userCrud.savePartial(user, data).then(function(){
          Utils.extendDeep(user, data);
          return StorageUtils.set(storageKey, user).then(function(){
            return user;
          });
        });
      } else {
        Utils.extendDeep(user, data);
        return StorageUtils.set(storageKey, user).then(function(){
          return user;
        });
      }
    });
  }

  function isAuthorized(accessLevel, _role){
    var role = _role !== undefined ? _role : getCurrentSync().role;
    return accessLevel.bitMask & role.bitMask;
  }
  function isAuthorizedAsync(accessLevel, _role){
    var rolePromise = _role !== undefined ? $q.when(_role) : getCurrent().then(function(user){ return user.role; });
    return rolePromise.then(function(role){
      return accessLevel.bitMask & role.bitMask;
    });
  }

  function isLoggedIn(_user){
    var user = _user !== undefined ? _user : getCurrentSync();
    return user.role && user.role.title !== routingConfig.userRoles.public.title;
  }
  function isLoggedInAsync(_user){
    var userPromise = _user !== undefined ? $q.when(_user) : getCurrent();
    return userPromise.then(function(user){
      return user.role && user.role.title !== routingConfig.userRoles.public.title;
    });
  }

  function signup(credentials){
    if(credentials.email && credentials.password){
      return _signupProxy({
        username: credentials.email,
        password: <PASSWORD>,
        email: credentials.email,
        role: routingConfig.userRoles.user
      }).then(function(user){
        return StorageUtils.set(storageKey, user).then(function(){
          return user;
        });
      }, function(err){
        return $q.reject({message: err.data.error});
      });
    } else {
      return $q.reject({message: 'Error: please fill email AND password !'});
    }
  }

  function login(credentials){
    if(credentials.email && credentials.password){
      return _loginProxy(credentials.email, credentials.password).then(function(user){
        return StorageUtils.set(storageKey, user).then(function(){
          return user;
        });
      }, function(err){
        return $q.reject({message: err.data.error});
      });
    } else {
      return $q.reject({message: 'Error: please fill email AND password !'});
    }
  }

  function passwordRecover(credentials){
    if(credentials.email){
      return _passwordRecoverProxy(credentials.email).then(null, function(err){
        return $q.reject({message: err.data.error});
      });
    } else {
      return $q.reject({message: 'Error: please fill email for account to recover !'});
    }
  }

  function logout(){
    return StorageUtils.remove(storageKey);
  }

  function _signupProxy(user){
    //return $q.when(user);
    return ParseUtils.signup(user);
  }

  function _loginProxy(email, password){
    //return $q.when({ email: email, username: email, role: routingConfig.userRoles.user });
    return ParseUtils.login(email, password);
  }

  function _passwordRecoverProxy(email){
    //return $q.when();
    return ParseUtils.passwordRecover(email);
  }

  return service;
});
<commit_msg>bugfix on UserSrv<commit_after>angular.module('app')


.factory('UserSrv', function($q, $http, ParseUtils, StorageUtils, Utils){
  'use strict';
  var storageKey = 'user';
  var defaultUser = { username: '', role: routingConfig.userRoles.public };
  var userCrud = null;
  var service = {
    getCurrent: getCurrent,
    isAuthorized: isAuthorized,
    isAuthorizedAsync: isAuthorizedAsync,
    isLoggedIn: isLoggedIn,
    isLoggedInAsync: isLoggedInAsync,
    signup: signup,
    login: login,
    passwordRecover: passwordRecover,
    logout: logout,
    saveUser: saveUser,
    savePartialUser: savePartialUser,
    accessLevels: routingConfig.accessLevels,
    userRoles: routingConfig.userRoles
  };
  getCurrent().then(function(user){
    //userCrud = CrudRestUtils.createCrud('/users');
    userCrud = ParseUtils.createUserCrud(user.sessionToken);
  });

  function getCurrent(){ return StorageUtils.get(storageKey, defaultUser); }
  function getCurrentSync(){ return StorageUtils.getSync(storageKey, defaultUser); }

  function saveUser(user){
    if(userCrud){
      return userCrud.save(user).then(function(){
        return StorageUtils.set(storageKey, user);
      });
    } else {
      return StorageUtils.set(storageKey, user);
    }
  }
  function savePartialUser(data){
    return getCurrent().then(function(user){
      if(userCrud){
        return userCrud.savePartial(user, data).then(function(){
          Utils.extendDeep(user, data);
          return StorageUtils.set(storageKey, user).then(function(){
            return user;
          });
        });
      } else {
        Utils.extendDeep(user, data);
        return StorageUtils.set(storageKey, user).then(function(){
          return user;
        });
      }
    });
  }

  function isAuthorized(accessLevel, _role){
    var role = _role !== undefined ? _role : getCurrentSync().role;
    return accessLevel.bitMask & role.bitMask;
  }
  function isAuthorizedAsync(accessLevel, _role){
    var rolePromise = _role !== undefined ? $q.when(_role) : getCurrent().then(function(user){ return user.role; });
    return rolePromise.then(function(role){
      return accessLevel.bitMask & role.bitMask;
    });
  }

  function isLoggedIn(_user){
    var user = _user !== undefined ? _user : getCurrentSync();
    return user.role && user.role.title !== routingConfig.userRoles.public.title;
  }
  function isLoggedInAsync(_user){
    var userPromise = _user !== undefined ? $q.when(_user) : getCurrent();
    return userPromise.then(function(user){
      return user.role && user.role.title !== routingConfig.userRoles.public.title;
    });
  }

  function signup(credentials){
    if(credentials.email && credentials.password){
      return _signupProxy({
        username: credentials.email,
        password: <PASSWORD>,
        email: credentials.email,
        role: routingConfig.userRoles.user
      }).then(function(user){
        return StorageUtils.set(storageKey, user).then(function(){
          userCrud = ParseUtils.createUserCrud(user.sessionToken);
          return user;
        });
      }, function(err){
        return $q.reject({message: err.data.error});
      });
    } else {
      return $q.reject({message: 'Error: please fill email AND password !'});
    }
  }

  function login(credentials){
    if(credentials.email && credentials.password){
      return _loginProxy(credentials.email, credentials.password).then(function(user){
        return StorageUtils.set(storageKey, user).then(function(){
          userCrud = ParseUtils.createUserCrud(user.sessionToken);
          return user;
        });
      }, function(err){
        return $q.reject({message: err.data.error});
      });
    } else {
      return $q.reject({message: 'Error: please fill email AND password !'});
    }
  }

  function passwordRecover(credentials){
    if(credentials.email){
      return _passwordRecoverProxy(credentials.email).then(null, function(err){
        return $q.reject({message: err.data.error});
      });
    } else {
      return $q.reject({message: 'Error: please fill email for account to recover !'});
    }
  }

  function logout(){
    return StorageUtils.remove(storageKey);
  }

  function _signupProxy(user){
    //return $q.when(user);
    return ParseUtils.signup(user);
  }

  function _loginProxy(email, password){
    //return $q.when({ email: email, username: email, role: routingConfig.userRoles.user });
    return ParseUtils.login(email, password);
  }

  function _passwordRecoverProxy(email){
    //return $q.when();
    return ParseUtils.passwordRecover(email);
  }

  return service;
});

{'fraction_non_alphanumeric': 0.13246638748071413, 'fraction_numerical': 0.0, 'mean_word_length': 3.2746113989637307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2229227', 'n_tokens_mistral': 2712, 'n_tokens_neox': 2663, 'n_words': 530}