Esempio n. 1
0
        public ActionResult PartialAccountUpdate(int id, JsonPatchDocument <AccountsUpdateDto> patchDoc)
        {
            var accountModelFromRepo = _repository.GetAccountsById(id);

            if (accountModelFromRepo == null)
            {
                return(NotFound());
            }

            var accountToPatch = _mapper.Map <AccountsUpdateDto>(accountModelFromRepo);


            if (!TryValidateModel(accountToPatch))
            {
                return(ValidationProblem());
            }
            _mapper.Map(accountToPatch, accountModelFromRepo);
            _repository.UpdateAccount(accountModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
Esempio n. 2
0
        public IActionResult ForgotPassword(ForgotPassDto model)
        {
            var user = _accRepo.GetAccountByEmail(model.Email);
            //EmailConfig
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

            client.EnableSsl             = true;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential("*****@*****.**", "abcdEcosystem123");
            MailMessage msg = new MailMessage();

            //Token config
            var Token        = Guid.NewGuid().ToString();
            var encodedToken = _authRepo.TokenConfig(Token);

            if (user != null)
            {
                //Adding table data to db
                var modifiedData = _authRepo.AddToken(Token, user);
                if (user == null)
                {
                    return(NotFound());
                }
                _mapper.Map(modifiedData, user);
                _accRepo.UpdateAccount(user);
                _accRepo.SaveChanges();

                //Sending Email with query parameters
                string url = $"{_configuration["ClientAppUrl"]}/resetpassword?email={model.Email}&token={encodedToken}";
                msg.To.Add(model.Email);
                msg.From    = new MailAddress("UST Eco-Tigers <*****@*****.**>");
                msg.Subject = "Password Reset Url";
                msg.Body    = url;
                client.Send(msg);
                return(Ok());
            }
            return(BadRequest());
        }