예제 #1
0
        /// <summary>
        /// Email sent to oganization users (or site admins) for access (HPCDS-22)
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private async Task <bool> SendApprovedEmail(ApplicationUser user)
        {
            bool   isSentToAdmins    = false;
            var    roleIds           = DataProviderAuth.GetAppRolesFor(new List <string>(new string[] { UserRoles.PendingAccess }), false).Select(s => s.Id);
            string DestinationEmails = string.Join("; ", user.Organization
                                                   .Users
                                                   .Where(w => w.LockoutEndDateUtc == null && w.EmailConfirmed &&
                                                          w.Roles.Any(a => roleIds.Contains(a.RoleId)))                        // HPCDS-22 TODO: specify a better way of IDentify'n active users
                                                   .Select(s => s.Email).ToList());

            if (String.IsNullOrWhiteSpace(DestinationEmails))
            {
                var adminUsers = DataProviderAuth.GetAdminUsers();
                DestinationEmails = string.Join("; ", adminUsers.Select(s => s.Email).ToList());
                isSentToAdmins    = true;
            }

            var emailMsg = new PgrmIdentityMessage()
            {
                Destination = DestinationEmails,
                Subject     = isSentToAdmins ? EmailRes.RegistrationApprovalReqForAdminSubjectFormat : EmailRes.RegistrationApprovalReqForOrgUsersSubjectFormat,
                Body        = String.Format(isSentToAdmins ? EmailRes.RegistrationApprovalReqForAdminBodyFormat : EmailRes.RegistrationApprovalReqForOrgUsersBodyFormat
                                            //"email: {0} organization name: {1} urlControllerAction: {2} token: {3}"
                                            , user.Email, user?.Organization.OrganizationName ?? "ERROR-NO Organization Name", "URL-TODO: (HPCDS-25)", "TOKEN-APPROVE-USER"),
            };
            await EService.SendAsync(emailMsg);

#if DEBUG
            TempData["DebugMessage"] = emailMsg.ToStringEmail();
#endif
            return(true);
        }
예제 #2
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                var emailMsg = new PgrmIdentityMessage
                {
                    Destination = user?.Email ?? model.Email
                };

                if (user == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    EmailSetupForNotRegisterdUser(emailMsg);
                    await EService.SendAsync(emailMsg);
                }
                else if (!(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    EmailSetupForNotVerifiedUser(emailMsg, user.Id, code);
                    await UserManager.SendEmailAsync(user.Id, emailMsg.Subject, emailMsg.Body);
                }
                else
                {
                    //For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateUserTokenAsync("CanAnswerSecQuestions", user.Id);

                    EmailSetupForRegisterdUser(emailMsg, code, "VerifyUser");
                    await UserManager.SendEmailAsync(user.Id, emailMsg.Subject, emailMsg.Body);
                }
#if DEBUG
                TempData["DebugMessage"] = emailMsg.ToStringEmail();
#endif
                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }