Beispiel #1
0
        public IActionResult Post([FromBody] ExternalUser externalUser)
        {
            int idUser = 0;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            using (var transaction = new TransactionScope())
            {
                try
                {
                    HashSalt salt = new HashSalt();
                    salt = PasswordUtil.GenerateSaltedHash(32, externalUser.Password);
                    externalUser.Password = salt.Hash;
                    externalUser.Help     = salt.Salt;
                    idUser = _unitOfWork.ExternalUser.Insert(externalUser);
                    transaction.Complete();
                }
                catch (Exception ex)
                {
                    transaction.Dispose();
                    return(StatusCode(500, "Internal server error: " + ex.Message));
                }
            }
            return(Ok(idUser));
        }
Beispiel #2
0
 public IActionResult ChangePassword([FromBody] ChangePassword request)
 {
     try
     {
         string     idUser = User.Claims.Where(c => c.Type.Equals(ClaimTypes.PrimarySid)).FirstOrDefault().Value;
         SystemUser user   = _unitOfWork.User.GetById(int.Parse(idUser));
         if (user != null)
         {
             SystemUser _user = _unitOfWork.User.ValidateUserPassword(user.Login, request.Password);
             if (_user != null)
             {
                 // Actualizamos la contraseña
                 _user.Password       = request.NewPassword;
                 _user.ChangePassword = false;
                 HashSalt salt = new HashSalt();
                 salt           = PasswordUtil.GenerateSaltedHash(32, _user.Password);
                 _user.Password = salt.Hash;
                 _user.Help     = salt.Salt;
                 return(Ok(_unitOfWork.User.Update(_user)));
             }
             else
             {
                 return(StatusCode(500, "La clave ingresada no corresponde a la clave del usuario"));
             }
         }
         return(StatusCode(500, "No se encuentra el usuario"));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, "Internal server error: " + ex.Message));
     }
 }
Beispiel #3
0
 public IActionResult Put([FromBody] ExternalUser externalUser)
 {
     try
     {
         HashSalt salt = new HashSalt();
         salt = PasswordUtil.GenerateSaltedHash(32, externalUser.Password);
         externalUser.Password = salt.Hash;
         externalUser.Help     = salt.Salt;
         if (ModelState.IsValid && _unitOfWork.ExternalUser.Update(externalUser))
         {
             return(Ok(new { Message = "El usuario externo se ha actualizado" }));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         return(StatusCode(500, "Internal server error: " + ex.Message));
     }
 }
Beispiel #4
0
 public IActionResult Put([FromBody] SystemUser user)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     using (var transaction = new TransactionScope())
     {
         try
         {
             HashSalt salt = new HashSalt();
             salt = PasswordUtil.GenerateSaltedHash(32, user.Password);
             //Hash = password
             //Salt = help
             user.Password = salt.Hash;
             user.Help     = salt.Salt;
             //Debemos traer campos no visibles para que se conserven
             SystemUser _user = _unitOfWork.User.GetById(user.Id);
             user.IdSalesman   = _user.IdSalesman;
             user.Authorizing  = _user.Authorizing;
             user.CancelOrders = _user.CancelOrders;
             user.Roles        = _user.Roles;
             _unitOfWork.User.Update(user);
             //UserProfile
             UserProfile userProfile = _unitOfWork.UserProfile.UserProfileByUser(user.Id);
             _unitOfWork.UserProfile.Delete(userProfile);
             userProfile.IdProfile = user.IdProfile;
             _unitOfWork.UserProfile.Insert(userProfile);
             transaction.Complete();
         }
         catch (Exception ex)
         {
             transaction.Dispose();
             return(StatusCode(500, "Internal server error: " + ex.Message));
         }
     }
     return(Ok(new { Message = "El usuario se ha actualizado" }));
 }
Beispiel #5
0
        public IActionResult Post([FromBody] SystemUser user)
        {
            int idUser = 0;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            using (var transaction = new TransactionScope())
            {
                try
                {
                    HashSalt salt = new HashSalt();
                    salt = PasswordUtil.GenerateSaltedHash(32, user.Password);
                    //Hash = password
                    //Salt = help
                    user.Password = salt.Hash;
                    user.Help     = salt.Salt;
                    user.Roles    = "user";
                    idUser        = _unitOfWork.User.Insert(user);
                    //UserProfile
                    UserProfile userProfile = new UserProfile
                    {
                        IdUser    = idUser,
                        IdProfile = user.IdProfile
                    };
                    _unitOfWork.UserProfile.Insert(userProfile);
                    transaction.Complete();
                }
                catch (Exception ex)
                {
                    transaction.Dispose();
                    return(StatusCode(500, "Internal server error: " + ex.Message));
                }
            }
            return(Ok(idUser));
        }