コード例 #1
0
        public virtual async Task <LoginResult <Usuario> > ResetPassword(int id)
        {
            var user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(new LoginResult <Usuario>(LoginResultType.InvalidUserNameOrEmailAddress));
            }


            var result = await SendRecoverPasswordAsync(user);

            if (result.Result != LoginResultType.SucessPasswordResetCode)
            {
                return(result);
            }

            try
            {
                //3. Enviar Mensaje..
                var modelBodyEmail = new RecoverPasswordDto();
                modelBodyEmail.PasswordRestCode = user.PasswordResetCode;
                modelBodyEmail.Nombres          = user.NombresCompletos;
                modelBodyEmail.Usuario          = user.Cuenta;

                var sistemaURL = ParametroService.GetValor <string>(CodigosParametros.PARAMETRO_SISTEMA_URL);
                modelBodyEmail.Enlace = string.Format("{0}/{1}/?code={2}", sistemaURL, "acceso/Reset", user.PasswordResetCode);

                var body = await TemplateEngine.Process(Constantes.TEMPLATE_SEGURIDAD_ENVIO_CORREO_RESETEO_CLAVE, modelBodyEmail);

                var msg = new IdentityMessage();
                msg.Destination = user.Correo;
                msg.Subject     = "Reseteo de contraseña";
                msg.Body        = body;
                await EmailService.SendAsync(msg);
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.HandleException(ex);
            }

            return(new LoginResult <Usuario>(LoginResultType.Success));
        }
コード例 #2
0
        public async Task <UsuarioDto> Update(MyUsuarioDto input)
        {
            //1. Verificar si el input, corresponde al usuario actual
            var userAutentificado = application.GetCurrentUser();

            if (userAutentificado.Id != input.Id)
            {
                throw new GenericException(string.Format("Intento de actualizar información del usuario autentificado : {0}, con información del usuario : {1}", userAutentificado.Id, input.Id),
                                           "Seguridad: La información del usuario no corresponde al usuario autentificado");
            }

            var user = await UserManager.GetUserByIdAsync(input.Id);

            var existeCambioCorreo = false;

            if (user.Correo != input.Correo)
            {
                existeCambioCorreo = true;
            }

            //Mapper
            user = ObjectMapper.Map(input, user);


            if (existeCambioCorreo)
            {
                user.SetNewPasswordResetCode();
            }

            await UpdateInternal(user);

            //2. Verificar cambio de Correo. (Enviar Correo)
            if (existeCambioCorreo)
            {
                try
                {
                    //3. Enviar Mensaje..
                    var modelBodyEmail = new RecoverPasswordDto();
                    modelBodyEmail.PasswordRestCode = user.PasswordResetCode;
                    modelBodyEmail.Nombres          = user.NombresCompletos;
                    modelBodyEmail.Usuario          = user.Cuenta;

                    var sistemaURL = ParametroService.GetValor <string>(CodigosParametros.PARAMETRO_SISTEMA_URL);
                    modelBodyEmail.Enlace = string.Format("{0}/{1}/?code={2}", sistemaURL, "acceso/Reset", user.PasswordResetCode);

                    var body = await TemplateEngine.Process(Constantes.TEMPLATE_SEGURIDAD_ENVIO_CORREO_CAMBIO_CORREO, modelBodyEmail);

                    var msg = new IdentityMessage();
                    msg.Destination = user.Correo;
                    msg.Subject     = "Cambio de correo electrónico / Reseteo de contraseña";
                    msg.Body        = body;
                    await EmailService.SendAsync(msg);
                }
                catch (Exception ex)
                {
                    ManejadorExcepciones.HandleException(ex);
                }
            }

            //3. Actualizar
            return(await Get(input));
        }