Exemplo n.º 1
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    return(RedirectToAction(nameof(ForgotPasswordConfirmation)));
                }

                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.ResetPasswordCallbackLink(user.Id, code, Request.Scheme);

                var channel = GrpcChannel.ForAddress("https://localhost:5001");
                var client  = new EmailManager.EmailManagerClient(channel);
                var request = new SendEmailRequest
                {
                    Email   = user.Email,
                    Subject = "Password reset",
                    Message = "Click here to restore your password <a href=\"" + callbackUrl + "\">link</a>"
                };

                await client.SendEmailAsync(request);

                return(RedirectToAction(nameof(ForgotPasswordConfirmation)));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> NotifyAccountStatusChanged(string id, bool isBanned)
        {
            var ret = false;

            if (id == null)
            {
                return(Json(ret));
            }

            var user = _userService.GetUserProfile(id);

            if (user == null)
            {
                return(Json(ret));
            }

            var isAccountLocked = _userService.IsAccountLocked(user);

            ret = true;

            try
            {
                var channel = GrpcChannel.ForAddress("https://localhost:5001");
                var client  = new EmailManager.EmailManagerClient(channel);

                var request = new SendEmailRequest
                {
                    Email = user.Email,
                };

                if (isBanned && isAccountLocked)
                {
                    request.Subject = "Account lock";
                    request.Message = "Your account has been locked due to not completing your tasks in time.";
                }
                else if (!isBanned && !isAccountLocked)
                {
                    request.Subject = "Account unlock";
                    request.Message = "Your account has been unlocked!";
                }
                else
                {
                    return(Json(ret));
                }

                var response = await client.SendEmailAsync(request);

                ret = response.Status == EmailService.Status.Ok;
            }
            catch (Exception)
            {
                ret = false;
            }

            return(Json(ret));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index()
        {
            // Test gRPC connection
            var channel = GrpcChannel.ForAddress("https://*****:*****@gmail.com",
                Subject = "Title",
                Message = "Test email"
            };
            await client.SendEmailAsync(request);

            return(View());
        }