コード例 #1
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordRequestModel request)
        {
            var user = await this.userManager.FindByNameAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(localizer.GetString("errors.user_not_found")));
            }

            var recover = new IPCS.Entities.RecoverPassword
            {
                RecoverDate = DateTime.Now.Add(TimeSpan.FromDays(1)),
                Hash        = Guid.NewGuid().ToString(),
                Used        = false,
                UserId      = user.Id
            };

            this.recoverPasswordService.Insert(recover);
            string callBack  = $"{this.generalOptions.BaseWebAppUrl}resetPassword/{recover.Hash}";
            string emailFile = localizer.GetString("emails.forgotpassword_src");
            string path      = $"{Directory.GetCurrentDirectory()}{emailFile}";

            this.emailSender.SendEmail(user.Email, "Reset Password", path, new Dictionary <string, string> {
                { "callback", callBack }, { "username", $"{user.FirstName}" }, { "host", this.generalOptions.BaseEmailsImage }
            });
            return(Ok());
        }
コード例 #2
0
        private void SendEmailActivateAccount(User user)
        {
            string token    = Guid.NewGuid().ToString();
            string callBack = $"{this.generalOptions.BaseWebAppUrl}account-activate/{token}";

            string emailFile = localizer.GetString("emails.welcome_src");
            string path      = $"{Directory.GetCurrentDirectory()}{emailFile}";

            this.emailSender.SendEmail(user.Email, "Activate Account", path, new Dictionary <string, string> {
                { "callback", callBack },
                { "username", $"{user.FirstName}" }, { "host", this.generalOptions.BaseEmailsImage }
            });
            //this.emailSender.SendEmailAsync(user.Email, "Activate Account", $"{callBack}", true);
            var recover = new IPCS.Entities.RecoverPassword
            {
                RecoverDate = DateTime.Now.Add(TimeSpan.FromDays(1)),
                Hash        = token,
                Used        = false,
                UserId      = user.Id
            };

            this.recoverPasswordService.Insert(recover);
        }