示例#1
0
        public async Task <IActionResult> ForgetPassword(ForgetPasswordDTO dto)
        {
            try
            {
                var user = await _userRepository.Find(x => x.Email == dto.Email).FirstOrDefaultAsync();

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

                var otp = await _otpRepository.CreateOTP(user, DateTime.UtcNow.AddHours(24));

                var resetUrl = $"http://localhost:8080/#/resetPassword?otp={otp.Hash}";

                await _mailService.SendMail("Reset Password Notification",
                                            $"<p>Your reset URL is <a href=\"{resetUrl}\">{resetUrl}</a></p>",
                                            MailType.ResetPassword,
                                            new string[] { user.Email }
                                            );

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(Problem(ex.Message));
            }
        }
示例#2
0
        //[Route("ForgetPassword/ForgetPassword")]
        public IActionResult SaveForgetPasswordDetails(ForgetPasswordDTO forgetPasswordDTO)
        {
            ForgetPasswordModel forgetPasswordObj = new ForgetPasswordModel(_forgetPassword, true, _config);

            forgetPasswordObj.SaveForgetPasswordDetails(forgetPasswordDTO);
            return(View());
        }
示例#3
0
        public IActionResult ForgetPassword()
        {
            ForgetPasswordDTO forgetPasswordDTO = new ForgetPasswordDTO
            {
                UserName = (string)this.RouteData.Values["UserName"]
            };

            return(View("ForgetPassword", forgetPasswordDTO));
        }
示例#4
0
        public JsonResult VerifyUser(ForgetPasswordDTO forgetPasswordDTO)
        {
            ForgetPasswordModel forgetPasswordObj = new ForgetPasswordModel(_forgetPassword, true, _config);
            string userName = forgetPasswordDTO.UserName;
            bool   isExists = forgetPasswordObj.VerifyUser(userName);

            if (isExists == true)
            {
                string Token = forgetPasswordObj.CreateToken();
                return(Json(Token));
            }
            else
            {
                return(Json(false));
            }
        }
示例#5
0
 public HttpResponseMessage ForgetPassword(ForgetPasswordDTO dto)
 {
     try
     {
         using (AspodesDB _context = new AspodesDB())
         {
             User user = _context.Users.FirstOrDefault(u => u.IDCard == dto.IDCard && u.Name == dto.Name && u.Person.Status != "D");
             if (null == user)
             {
                 return(ResponseWrapper.ExceptionResponse(new OtherException("填入信息有误")));
             }
             string IdentifyCode = StringExtensions.GetRandomString(6, true, true);
             Email  email        = new Email();
             email.SenderId      = SystemConfig.SenderAddress;
             email.ReceiverId    = user.UserId;
             email.Content       = "[农科院]验证码:" + IdentifyCode + ",农科院用户,您正在通过邮箱重置您的密码[验证码告知他人将导致账号被盗,请勿泄露]";
             email.ReciveAddress = user.Person.Email;
             email.Subject       = "农科院";
             email.IdentifyCode  = IdentifyCode;
             EmailRepository mailRepository = new EmailRepository();
             mailRepository.AddEmail(email);
             return(ResponseWrapper.SuccessResponse("邮件已发送成果,请注意查收,部分邮件会被自动删除,请在回收箱中仔细查找"));
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(ResponseWrapper.ExceptionResponse(new OtherException("数据库连接错误")));
     }
     catch (Exception e)
     {
         var a = e.Message;
         return(ResponseWrapper.ExceptionResponse(e));
     }
 }
示例#6
0
 public void SaveForgetPasswordPage(ForgetPasswordDTO forgetPasswordDTO)
 {
     _employeeContext.Login.Where(s => s.UserName == forgetPasswordDTO.UserName).ToList();
     _employeeContext.SaveChanges();
 }
示例#7
0
 public void SaveForgetPasswordDetails(ForgetPasswordDTO passwordDTO)
 {
     _forgetPassword.SaveForgetPasswordPage(passwordDTO);
 }