Exemple #1
0
        private List <string> GetAllPropertyNameOfViewModel()
        {
            var viewModel = new UserBaseViewModel();
            var type      = viewModel.GetType();

            return(ReflectionUtilities.GetAllPropertyNamesOfType(type));
        }
Exemple #2
0
        /// <summary>
        /// Sends the Confirmation Email
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public ActionResult SendConfirmationEmail(UserBaseViewModel model)
        {
            if (ModelState.IsValid && model.UserId != null)
            {
                JSUser user = JSUserBusinessManager.Current.UserManager.FindById(model.UserId ?? 0);

                string confirmationToken = JSUserBusinessManager.Current.UserManager.GenerateEmailConfirmationToken(model.UserId ?? 0);

                ConfirmationTokenModel emailModel = new ConfirmationTokenModel()
                {
                    User = user,
                    ConfirmationToken = confirmationToken
                };

                EmailHelper.Current.Send(EmailTypes.ConfirmEmail, emailModel, new List <string>()
                {
                    user.Email
                });

                AppMessenger.Current.Send(MessageTypes.ConfirmationEmailSent,
                                          String.Format("{0} has sent a confirmation email to his/her email account ({1})", user.UserName, user.Email),
                                          "A confirmation email has been sent.");

                ViewBag.ConfirmationEmailSent = true;
            }

            return(Manage());
        }
Exemple #3
0
        public async Task <ActionResult> Manage(UserBaseViewModel model)
        {
            if (ModelState.IsValid)
            {
                JSUser updatedUser = new JSUser()
                {
                    JSUserId = Int32.Parse(User.Identity.GetUserId()),
                    UserName = model.UserName
                };

                JSUser storedUser = JSUserBusinessManager.Current.UserManager.FindById(Int32.Parse(User.Identity.GetUserId()));

                if (String.IsNullOrEmpty(storedUser.Email))
                {
                    updatedUser.Email = model.Email;
                }

                JSUserBusinessManager.Current.UserManager.Update(updatedUser);

                ViewBag.NewUserName = model.UserName;

                await SignInAsync(updatedUser, false);
            }

            return(Manage());
        }
Exemple #4
0
        public ActionResult RemoveEmail(UserBaseViewModel model)
        {
            if (ModelState.IsValid && model.UserId != null)
            {
                JSUserBusinessManager.Current.UserManager.SetEmail(model.UserId ?? 0, null);
            }

            return(Manage());
        }
        public ActionResult AcceptWaiver(String Id, String error)
        {
            if (!String.IsNullOrEmpty(error))
            {
                ViewBag.error = error;
            }
            int id = Convert.ToInt32(Id);
            UserBaseViewModel         user             = m.GetUserById(id);
            UserAcceptWaiverViewModel acceptWaiverUser = m.mapper.Map <UserBaseViewModel, UserAcceptWaiverViewModel>(user);

            return(View(acceptWaiverUser));
        }
Exemple #6
0
        public async Task <ActionResult> UserNameAvailable(UserBaseViewModel model)
        {
            JSUser jsUser;

            if (model.UserId != null)
            {
                jsUser = await JSUserBusinessManager.Current.UserManager.FindByIdAsync((int)model.UserId);

                if (jsUser.UserName == model.UserName)
                {
                    return(Json(true));
                }
            }

            jsUser = await JSUserBusinessManager.Current.UserManager.FindByNameAsync(model.UserName);

            return(Json(jsUser == null));
        }
        private static UserBaseViewModel ConvertToBaseViewModel(User dbModel)
        {
            var viewModel = new UserBaseViewModel
            {
                Id           = dbModel.Id,
                FirstName    = dbModel.FirstName,
                LastName     = dbModel.LastName,
                Username     = dbModel.Username,
                Password     = dbModel.Password,
                PasswordHash = dbModel.PasswordHash.ToArray(),
                PasswordSalt = dbModel.PasswordSalt.ToArray(),
                Role         = RoleDto.FromModel(dbModel.Role),
                Enabled      = dbModel.Enabled,
            };


            return(viewModel);
        }
Exemple #8
0
        public async Task <ActionResult> ExternalLoginConfirmation(UserBaseViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(RedirectToAction("Login", new { ReturnUrl = returnUrl, ErrorMessage = ManageAccountMessageId.Error }));
                }
                var user = new JSUser()
                {
                    Name = model.UserName
                };
                var result = await JSUserBusinessManager.Current.UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await JSUserBusinessManager.Current.UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent : false);

                        await SendAppMessage(user, MessageTypes.NewUserAccountRegistered, info.Login.LoginProvider);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }