Beispiel #1
0
        public async Task <UpdatePasswordResponse> UpdatePassword(UpdatePasswordRequest request)
        {
            var response = new UpdatePasswordResponse();
            var user     = await _sessionManager.GetUser();

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                await uow.UserRepo.UpdateUserPassword(new Repositories.DatabaseRepos.UserRepo.Models.UpdateUserPasswordRequest()
                {
                    User_Id       = user.Id,
                    Password_Hash = PasswordHelper.HashPassword(request.NewPassword),
                    Updated_By    = ApplicationConstants.SystemUserId
                });

                uow.Commit();
            }

            await _sessionManager.WriteSessionLogEvent(new Models.ManagerModels.Session.CreateSessionLogEventRequest()
            {
                EventKey = SessionEventKeys.PasswordUpdated
            });

            response.Notifications.Add($"Your password has been updated", NotificationTypeEnum.Success);
            return(response);
        }
        public static BaseResponse GetResponse(UserMaintenance.Methods methodCalled, returntype sfgReturn)
        {
            string       className    = "SFGWrapper.UserMaintTranslators";
            BaseResponse baseResponse = new BaseResponse();

            foreach (var item in sfgReturn.error)
            {
                Message ahError = new Message(item.errno, MessageSources.UserMaint);
                foreach (string message in item.errmsg)
                {
                    ahError.SfgMessages.Add(message);
                }
                baseResponse.Messages.Add(ahError);
            }

            switch (methodCalled)
            {
            case UserMaintenance.Methods.CREATELOGIN:
                CreateLoginResponse createLoginResponse = new CreateLoginResponse();
                createLoginResponse.UpdateSucceeded = sfgReturn.response.UPDATE_SUCCEEDED == "Y";
                baseResponse.TypedResponse          = createLoginResponse;
                break;

            case UserMaintenance.Methods.UPDATEPASSWORD:
                UpdatePasswordResponse updatePasswordResponse = new UpdatePasswordResponse();
                updatePasswordResponse.UpdateSucceeded = sfgReturn.response.UPDATE_SUCCEEDED == "Y";
                baseResponse.TypedResponse             = updatePasswordResponse;
                break;

            case UserMaintenance.Methods.UPDATEUSERNAME:
                UpdateUsernameResponse updateUserName = new UpdateUsernameResponse();
                updateUserName.UpdateSucceeded = sfgReturn.response.UPDATE_SUCCEEDED == "Y";
                baseResponse.TypedResponse     = updateUserName;
                break;
            }
            baseResponse.TypedResponse.Success       = sfgReturn.success;
            baseResponse.TypedResponse.Info          = Utilities.GetInfo(sfgReturn.response.INFO);
            baseResponse.TypedResponse.MemoryUsed    = sfgReturn.response.MEMORY_USED;
            baseResponse.TypedResponse.Protocol      = sfgReturn.response.PROTOCOL;
            baseResponse.TypedResponse.RoundtripTime = sfgReturn.response.ROUNDTRIP_TIME;
            baseResponse.TypedResponse.Server        = sfgReturn.response.SERVER;
            baseResponse.TypedResponse.TimeElapsed   = sfgReturn.response.TIME_ELAPSED;
            baseResponse.TypedResponse.Version       = sfgReturn.response.VERSION;

            return(baseResponse);
        }
        public static BaseResponse GetResponse(UserMaintenance.Methods methodCalled, returntype sfgReturn)
        {
            string className = "SFGWrapper.UserMaintTranslators";
            BaseResponse baseResponse = new BaseResponse();
            foreach (var item in sfgReturn.error)
            {
                Message ahError = new Message(item.errno, MessageSources.UserMaint);
                foreach (string message in item.errmsg)
                {
                    ahError.SfgMessages.Add(message);
                }
                baseResponse.Messages.Add(ahError);
            }

            switch (methodCalled)
            {
                case UserMaintenance.Methods.CREATELOGIN:
                    CreateLoginResponse createLoginResponse = new CreateLoginResponse();
                    createLoginResponse.UpdateSucceeded = sfgReturn.response.UPDATE_SUCCEEDED == "Y";
                    baseResponse.TypedResponse = createLoginResponse;
                    break;
                case UserMaintenance.Methods.UPDATEPASSWORD:
                    UpdatePasswordResponse updatePasswordResponse = new UpdatePasswordResponse();
                    updatePasswordResponse.UpdateSucceeded = sfgReturn.response.UPDATE_SUCCEEDED == "Y";
                    baseResponse.TypedResponse = updatePasswordResponse;
                    break;
                case UserMaintenance.Methods.UPDATEUSERNAME:
                    UpdateUsernameResponse updateUserName = new UpdateUsernameResponse();
                    updateUserName.UpdateSucceeded = sfgReturn.response.UPDATE_SUCCEEDED == "Y";
                    baseResponse.TypedResponse = updateUserName;
                    break;
            }
            baseResponse.TypedResponse.Success = sfgReturn.success;
            baseResponse.TypedResponse.Info = Utilities.GetInfo(sfgReturn.response.INFO);
            baseResponse.TypedResponse.MemoryUsed = sfgReturn.response.MEMORY_USED;
            baseResponse.TypedResponse.Protocol = sfgReturn.response.PROTOCOL;
            baseResponse.TypedResponse.RoundtripTime = sfgReturn.response.ROUNDTRIP_TIME;
            baseResponse.TypedResponse.Server = sfgReturn.response.SERVER;
            baseResponse.TypedResponse.TimeElapsed = sfgReturn.response.TIME_ELAPSED;
            baseResponse.TypedResponse.Version = sfgReturn.response.VERSION;

            return baseResponse;
        }
Beispiel #4
0
        ///// <summary>
        ///// Create new password for newly created user.
        ///// </summary>
        ///// <param name="request"></param>
        ///// <returns></returns>
        public static LoginUserData UpdatePassword(string userName, string password = null)
        {
            LoginUserData result = null;

            if (userName != null)
            {
                UpdatePasswordRequest  req = new UpdatePasswordRequest();
                UpdatePasswordResponse res = new UpdatePasswordResponse();
                req.username    = userName;
                req.oldPassword = password;
                req.newPassword = password + "_Update";
                res             = target4.UpdatePassword(req);

                if (res != null && res.UpdatePasswordResult != null && res.UpdatePasswordResult.ResponseCode == "VR")
                {
                    result          = new LoginUserData();
                    result.Password = req.newPassword;
                    result.UserName = userName;
                }
            }
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Update Password
        /// </summary>
        /// <param name="obj">Request object</param>
        /// <returns>User object</returns>
        public ActionResponse UpdatePasswordAction(UpdatePasswordRequest obj)
        {
            try
            {
                int     idProduct = obj.idProduct.Value;
                int     idChannel = obj.idChannel.Value;
                decimal idClient  = obj.idClient.Value;

                // STEP 0: Need to verify if product and channel exist or not
                ProductData prodData = new ProductData();
                Product     oProduct = prodData.GetProductById(idProduct);
                if (oProduct == null)
                {
                    return(functions.Response((int)CodeStatusEnum.NO_CONTENT, "El producto no existe en el sistema", null));
                }

                ChannelData channelData = new ChannelData();
                Channel     oChannel    = channelData.GetChannelById(idChannel);
                if (oChannel == null)
                {
                    return(functions.Response((int)CodeStatusEnum.NO_CONTENT, "El canal no existe en el sistema", null));
                }

                // STEP 0.1: Verify if user exists
                ClienteData clientData = new ClienteData();
                Cliente     oClient    = clientData.GetUserById(idClient);
                if (oClient.id_cliente == null)
                {
                    return(functions.Response((int)CodeStatusEnum.NO_CONTENT, "No existe el usuario en el sistema", null));
                }

                // STEP 1: Check if user identify already exists by id_cliente + channel
                UserIdentifyData uiData = new UserIdentifyData();

                UserIdentify ui = uiData.FindByIdUserAndIdChannel(idClient, idChannel);
                if (ui.id_cliente == null)
                {
                    return(functions.Response((int)CodeStatusEnum.NO_CONTENT, "La identidad del usuario no existe en el sistema", null));
                }

                int idUserIdentify = ui.idUserIdentify.Value;

                // STEP 2: Check credential
                string oldPassAsMD5 = "";
                string newPassAsMD5 = "";
                using (MD5 md5Hash = MD5.Create())
                {
                    string oldPass = obj.oldPassword.Trim();
                    string newPass = obj.newPassword.Trim();

                    // Password integrity
                    if (String.IsNullOrEmpty(newPass))
                    {
                        return(functions.Response((int)CodeStatusEnum.BAD_REQUEST, "La contraseña no puede ser una cadena vacía", null));
                    }

                    int minLengthPass = Int32.Parse(functions.ConfigItem("MIN_PASS_LENGTH"));
                    if (newPass.Length < minLengthPass)
                    {
                        return(functions.Response((int)CodeStatusEnum.BAD_REQUEST, "La contraseña debe tener un mínimo de " + minLengthPass + " caracteres", null));
                    }

                    if (oldPass == newPass)
                    {
                        return(functions.Response((int)CodeStatusEnum.BAD_REQUEST, "La nueva contraseña no puede ser igual a la actual", null));
                    }

                    // Passwords as MD5
                    oldPassAsMD5 = functions.GetMd5Hash(md5Hash, oldPass);
                    newPassAsMD5 = functions.GetMd5Hash(md5Hash, newPass);
                }
                CredentialData credData    = new CredentialData();
                Credential     oCredential = credData.FindByProductAndUserIdentifyAndPass(idProduct,
                                                                                          idUserIdentify,
                                                                                          oldPassAsMD5);
                if (oCredential.idCredential == null)
                {
                    return(functions.Response((int)CodeStatusEnum.BAD_REQUEST, "La contraseña no es válida", null));
                }

                int idCredential = oCredential.idCredential.Value;

                // STEP 3: If Credential is OK, need to check if credential is NORMAL or TEMPORAL
                if (oCredential.idState.Value == (int)StateEnum.ACTIVE)
                {
                    // Normal process
                    bool updCredential = credData.UpdatePassword(idCredential, newPassAsMD5, (int)StateEnum.ACTIVE);
                    if (!updCredential)
                    {
                        return(functions.Response((int)CodeStatusEnum.INTERNAL_ERROR, "No se pudo actualizar la contraseña", null));
                    }
                }
                else if (oCredential.idState.Value == (int)StateEnum.TEMPORAL_PASSWORD)
                {
                    // Will set normal credential with new password
                    // Firstly, need to find it
                    List <Credential> lstCredentials = credData.FindByProductAndUserIdentify(idProduct, idUserIdentify);
                    foreach (Credential o in lstCredentials)
                    {
                        // Finding normal credential related to product and useridentify
                        if (o.idState.Value == (int)StateEnum.ACTIVE)
                        {
                            bool updCredential = credData.UpdatePassword(o.idCredential.Value, newPassAsMD5, (int)StateEnum.ACTIVE);
                            if (!updCredential)
                            {
                                return(functions.Response((int)CodeStatusEnum.INTERNAL_ERROR, "No se pudo actualizar la contraseña", null));
                            }
                        }
                    }

                    // Pass temporal credential to TEMPORAL_PASSWORD_USED
                    bool updTmpCredential = credData.UpdatePassword(idCredential, oldPassAsMD5, (int)StateEnum.TEMPORAL_PASSWORD_USED);
                    if (!updTmpCredential)
                    {
                        return(functions.Response((int)CodeStatusEnum.INTERNAL_ERROR, "No se pudo actualizar la credencial temporal", null));
                    }
                }
                else
                {
                    // Desactive, I can´t do anything
                    return(functions.Response((int)CodeStatusEnum.CONFLICT, "La credencial se encuentra inactiva y no se puede actualizar", null));
                }

                // OK, return true/false
                UpdatePasswordResponse response = new UpdatePasswordResponse();
                response.updated = DateTime.Now;
                return(functions.Response((int)CodeStatusEnum.OK, "OK", response));
            }
            catch (Exception e)
            {
                logger.Fatal(e.Message);
                return(functions.Response((int)CodeStatusEnum.INTERNAL_ERROR, e.Message, null));
            }
        }