示例#1
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));
        }
示例#2
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));
        }
示例#3
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));
        }