Пример #1
0
        public async Task Handle(OrderConfirmedPublicEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogDebug("START OrderCreatedHandler");

            _sendMail.SendMailAsync(notification.Order.OrderId);

            _logger.LogDebug("END OrderCreatedHandler");
        }
Пример #2
0
        public async Task <IActionResult> Mail([FromServices] ISendMail sendMail, string auth)
        {
            if (Longbow.Security.Cryptography.LgbCryptography.ComputeHash(auth, "l9w+7loytBzNHYkKjGzpWzbhYpU7kWZenT1OeZxkor28wQJQ") != "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=")
            {
                // 授权码不正确拒绝执行
                return(View(new MailModel(this)
                {
                    Result = "授权码不正确"
                }));
            }
            else
            {
                var result = await sendMail.SendMailAsync(MessageFormat.Test, "Email from Bootstrap Admin Master");

                return(View(new MailModel(this)
                {
                    Result = result ? "发送成功" : "发送失败"
                }));
            }
        }
 public async Task <bool> Healths([FromServices] ISendMail sendMail, [FromServices] IWebHostEnvironment env, [FromBody] string message)
 {
     return(await sendMail.SendMailAsync(MessageFormat.Healths, message.FormatHealths(env.WebRootPath)));
 }
Пример #4
0
        public async Task <IActionResult> Signin([FromBody] SigninRequest request)
        {
            if (ModelState.IsValid)
            {
                var issuer   = _appSettings.Value.Tokens.Issuer;
                var audience = _appSettings.Value.Tokens.Audience;
                var key      = _configuration["SecretKey:Key"];

                var user = await _userManager.FindByEmailAsync(request.Username);

                if (user == null)
                {
                    return(StatusCode(403, new ApiResponse {
                        Status = false, Message = "Authorization Error"
                    }));
                }
                var result = await _signInManager.PasswordSignInAsync(request.Username, request.Password, false, true);

                if (result.Succeeded)
                {
                    var claims = new[]
                    {
                        new Claim(JwtRegisteredClaimNames.Email, user.Email),
                        new Claim(JwtRegisteredClaimNames.Jti, user.Id),
                        new Claim(JwtRegisteredClaimNames.FamilyName, user.LastName),
                        new Claim(JwtRegisteredClaimNames.GivenName, user.FirstName)
                    };
                    var credential = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)),
                                                            SecurityAlgorithms.HmacSha256);
                    var token = new JwtSecurityToken(issuer, audience, claims, expires: DateTime.Now.AddMinutes(60),
                                                     signingCredentials: credential);
                    return(Ok(new ApiResponse
                    {
                        Status = true,
                        Message = "Success",
                        Result = new
                        {
                            username = user.UserName,
                            name = $"{user.FirstName} {user.LastName}",
                            token = new JwtSecurityTokenHandler().WriteToken(token)
                        }
                    }));
                }
                if (!result.Succeeded)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false, Message = "Invalid Username or Password"
                    }));
                }
                if (result.IsLockedOut)
                {
                    if (user.UserName == request.Username)
                    {
                        var forgotPasswordLink = Url.ActionLink("ForgotPassword", "Auth", new { }, Request.Scheme);
                        var subject            = "Your account has been locked out due to someone trying to access it, click link below to reset password if you are the one.";
                        await _sendMail.SendMailAsync(_appSettings.Value.FromAddress, request.Username, subject, forgotPasswordLink);
                    }
                }
            }
            return(BadRequest(new ApiResponse {
                Status = false, Message = "Validation Error"
            }));
        }
 public async Task <bool> Log([FromServices] ISendMail sendMail, [FromBody] string message)
 {
     return(await sendMail.SendMailAsync(MessageFormat.Exception, message.Replace("\r\n", "<br>").Replace("\n", "<br>")));
 }