Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> MyProfile(UserProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                user.FirstName              = model.FirstName;
                user.LastName               = model.LastName;
                user.PhoneNumber            = model.PhoneNumber;
                user.PhoneInternationalFlag = model.PhoneInternationalFlag;
                user.JobTitle               = model.JobTitle;
                model.Organization          = user.Organization;
                var result = await UserManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    // Remove and Add the related Security Questions and Answers
                    DataProviderAuth.CreateUserQuestions(user, model.Qs);
                    user = UserManager.FindById(User.Identity.GetUserId());
                    foreach (var q in model.Qs)
                    {
                        q.Question = user.UserQuestions.Where(m => m.Q_ID == q.Q_ID).Select(m => m.SecurityQuestion).First().Questions;
                    }
                    return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeMyProfileSuccess }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult MyOrganization()
        {
            var user  = UserManager.FindById(User.Identity.GetUserId());
            var model = DataProviderAuth.GetOrganizationInfo(user.O_ID);

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult MyOrganization(OrganizationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Users = DataProviderAuth.GetOrganizationInfo(model.ID)?.Users;
                return(View(model));
            }
            var user = UserManager.FindById(User.Identity.GetUserId());

            model.Addresses.Add(model.PhysicalAddress);
            model.Addresses.Add(model.MailingAddress);
            DataProviderAuth.UpdateOrganization(model);
            return(RedirectToAction("Index", new { message = ManageMessageId.ChangeMyOrganizationSuccess }));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    FirstName              = model.FirstName,
                    LastName               = model.LastName,
                    PhoneNumber            = model.PhoneNumber,
                    PhoneInternationalFlag = model.PhoneInternationalFlag,
                    UserName               = model.Email,
                    Email    = model.Email,
                    JobTitle = model.JobTitle,
                    O_ID     = model.O_ID.GetValueOrDefault(-1),
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // Add the related Security Questions and Answers
                    DataProviderAuth.CreateUserQuestions(user, model.Qs);
                    if (!model.IsHpcdsOrganization)
                    {
                        user.O_ID = DataProviderAuth.CreateOrganization(model.NewOrganization);
                        await UserManager.UpdateAsync(user);
                    }

                    await UserManager.AddToRolesAsync(user.Id, UserRoles.PendingAccess);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                    await SendConfrimEmail(user);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();
            var user   = UserManager.FindById(userId);

            ViewBag.IsEmailConfirmed     = user.EmailConfirmed;
            ViewBag.IsOrganizationActive = DataProviderAuth.IsOrganizationActive(user.O_ID);

            // TODO: (HPCDS-70) - find alt method to display
            Session["CurrentUsersName"] = user.FirstName + " " + user.LastName;
            Session["CurrentUsersOrg"]  = user?.Organization.OrganizationName ?? "ERROR, No Organization";

            bool isPendingAccess = User.IsInRole(UserRoles.PendingAccess);

            if (isPendingAccess && !ViewBag.IsEmailConfirmed)
            {                                                    // Registration Submitted but user hasn't confirmed email, hence
              // User is Required to Check Email and Confirm or Request for the email to be resent
                ViewBag.Title = "Account Information Submitted"; // or "Registration Submitted"
#if DEBUG
                ViewBag.DebugMessage     = TempData["DebugMessage"] ?? "Request to resend, with button above";
                TempData["DebugMessage"] = null;
#endif
            }
            else if (isPendingAccess && ViewBag.IsEmailConfirmed)
            {                                              // Requires a site/state admin to approve the registration
                ViewBag.Title = "Email Address Validated"; // or  "Pending Access"
                // TODO: HPCDS-25/HPCDS-35
#if DEBUG
                ViewBag.DebugMessage     = TempData["DebugMessage"] ?? "Request to resend, with button above";
                TempData["DebugMessage"] = null;
#endif
            }
            else
            { // Access Granted
                ViewBag.Title = "Dashboard";
            }

            return(View());
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> ResetPasswordByAdmin(ResetPasswordByAdminViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

                if (result.Succeeded)
                {
                    // Del/Add the related Security Questions and Answers
                    DataProviderAuth.CreateUserQuestions(user, model.Questions);
                    // Auto SignIn
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

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