public IActionResult New(Attorney attorney)
 {
     if (!_usersRepo.VerifyUsername(attorney.User.Username))
     {
         ModelState.AddModelError("uqUsername", "El usuario ingresado ya existe");
     }
     if (!_attorneysRepo.VerifyEmail(attorney.Email))
     {
         ModelState.AddModelError("uqEmail", "El correo ingresado ya existe");
     }
     if (!_attorneysRepo.VerifyNotaryCode(attorney.NotaryCode))
     {
         ModelState.AddModelError("uqNotaryCode", "El código de notario ingresado ya existe");
     }
     //if(attorney.User.Username.Contains(" "))
     //{
     //    ModelState.AddModelError("whiteSpacesUsername", "El nombre de usuario contiene espacios en blanco, favor no incluir espacios en blanco");
     //}
     if (!ModelState.IsValid)
     {
         NewAttorneyViewModel viewModel = new NewAttorneyViewModel
         {
             Departments = _departmentsRepo.Departments.ToList()
         };
         viewModel.Attorney = attorney;
         return(View(viewModel));
     }
     else
     {
         //string guidGenerated = _guidManager.GenerateGuid();
         //string passwordDefault = guidGenerated.Substring(guidGenerated.Length - 12, 12);
         string passwordOriginal = attorney.User.Password;
         string passwordHashed   = _cryptoManager.HashString(attorney.User.Password);
         attorney.User.Password = passwordHashed;
         _attorneysRepo.Save(attorney);
         //Envío de password sin hash al usuario
         string emailBody = $"Se le ha creado un acceso a la aplicación Lexincorp Nicaragua Web, su usuario es {attorney.User.Username} " +
                            $"y su clave de acceso es {passwordOriginal}. \n**Este es un mensaje autogenerado por el sistema, favor no responder**";
         _mailSender.SendMail(attorney.Email, "Usuario web creado para aplicación Lexincorp Nicaragua Web", emailBody);
         TempData["added"] = true;
         return(RedirectToAction("New"));
     }
 }
Esempio n. 2
0
        public IActionResult ChangePassword(NewPasswordUser PasswordUser)
        {
            return(NotFound());

            if (!ModelState.IsValid)
            {
                ChangePasswordViewModel vm = new ChangePasswordViewModel();
                vm.PasswordUser = PasswordUser;
                return(View(vm));
            }
            else
            {
                var user = HttpContext.User;
                var id   = user.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
                var u    = _usersRepo.Users.Where(x => x.Id == Convert.ToInt32(id)).FirstOrDefault();
                if (_cryptoManager.VerifyHash(PasswordUser.oldPassword, u.Password))
                {
                    if (PasswordUser.newPassword == PasswordUser.confirmNewPassword)
                    {
                        u.Password = _cryptoManager.HashString(PasswordUser.newPassword);
                        _usersRepo.UpdateUserPassword(u);
                        TempData["Updated"] = true;
                        return(RedirectToAction("ChangePassword"));
                    }
                    else
                    {
                        TempData["PasswordsDontMatch"] = true;
                        ChangePasswordViewModel vm = new ChangePasswordViewModel();
                        vm.PasswordUser = PasswordUser;
                        return(View(vm));
                    }
                }
                else
                {
                    TempData["OldPasswordDontMatch"] = true;
                    ChangePasswordViewModel vm = new ChangePasswordViewModel();
                    vm.PasswordUser = PasswordUser;
                    return(View(vm));
                }
            }
        }
 public void CreateAccount(Administrator administrator)
 {
     administrator.Password = _crypto.HashString(administrator.Password);
     context.Administrators.Add(administrator);
     context.SaveChanges();
 }