예제 #1
0
        public void Recovery(ModelViewRecovery model)
        {
            var objRepo     = new RepositoryUser();
            var dataUsuario = objRepo.GetEmail(model.Email);

            if (dataUsuario == null)
            {
                throw new Exception("EmailInvalid");
            }

            var NewPassword = GeneratePassword(8);

            dataUsuario.Password       = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(NewPassword);
            dataUsuario.ChangePassword = true;

            objRepo.Update(dataUsuario);

            List <string> arr = new List <string>();

            arr.Add(model.Email);
            //arr.Add("*****@*****.**");

            var objAlerta = new BusinessNotification();

            //byte[] outMessage = new byte[ResourceMessage.GetStream("NotificationRecoveryBodyContent", culture).Length];
            //ResourceMessage.GetStream("NotificationRecoveryBodyContent", culture).Read(outMessage, 0, (int) ResourceMessage.GetStream("NotificationRecoveryBodyContent", culture).Length);

            //StringBuilder sb = new StringBuilder(UnicodeEncoding.Unicode.GetString(outMessage));
            string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationRecoveryBodyContent.txt");

            sb = sb.Replace("#%Nombre%#", dataUsuario.Name);
            sb = sb.Replace("#%ClaveTemporal%#", NewPassword);
            var Manager = new ResourceManager("net.paxialabs.mabe.serviplus.resource.Common.ResourceMessage", typeof(ResourceMessage).Assembly);

            //objAlerta.SendMails(arr, Manager.GetString("NotificationRecoveryPassword"), sb.ToString());
            objAlerta.SendMailExchange(GlobalConfiguration.exchangeUser, GlobalConfiguration.exchangePwd, arr, Manager.GetString("NotificationRecoveryPassword"), sb.ToString());
        }
예제 #2
0
        public ModelViewUser Insert(ModelViewUser model)
        {
            var objRepository = new RepositoryUser();
            var objSecurity   = new BusinessSecurity();

            bool   salir = false;
            string token = "";

            while (!salir)
            {
                token = objSecurity.GenerateToken();
                if (objRepository.GetToken(token) == null)
                {
                    salir = true;
                }
            }
            string clave = objSecurity.GeneratePassword(8);

            if (objRepository.GetEmail(model.Email) != null)
            {
                throw new Exception("DuplicateEmail");
            }

            if (objRepository.GetUserName(model.UserName) != null)
            {
                throw new Exception("DuplicateUser");
            }


            EntityUser data = new EntityUser()
            {
                UserID           = model.UserID,
                ProfileID        = model.ProfileID,
                UserName         = model.UserName,
                Name             = model.Name,
                Password         = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(clave),
                Token            = token,
                ChangePassword   = true,
                Email            = model.Email,
                Status           = true,
                DateLastAccess   = DateTime.UtcNow,
                DateCreate       = DateTime.UtcNow,
                DateModification = DateTime.UtcNow
            };

            data = objRepository.Insert(data);

            model.UserID = data.UserID;

            List <string> arr = new List <string>();

            arr.Add(model.Email);

            string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationUserBodyContent.txt");

            sb = sb.Replace("#%NombreUsuario%#", data.UserName);
            sb = sb.Replace("#%ClaveTemporal%#", clave);
            sb = sb.Replace("#%Nombre%#", data.Name);
            //Nombre de usuario, usuario, pass,
            //new BusinessNotification().SendMails(arr, "Mabe - Registro de usuario ServiPlus", sb);
            new BusinessNotification().SendMailExchange(GlobalConfiguration.exchangeUser, GlobalConfiguration.exchangePwd, arr, "Mabe - Registro de usuario ServiPlus", sb);
            return(model);
        }