Example #1
0
        public ActionResult AccountActivation(Guid userId, Guid token)
        {
            // check for the user
            var user = ValidateUserActivation(userId, token, SystemUserAttributeNames.AccountActivationToken);

            if (user == null)
                return RedirectToRoute(SystemRouteNames.Login);

            // valid user with a valid token, we need him to set the security settings
            var model = new AccountActivationModel
            {
                UserId = user.RowId,
                Token = token
            };

            PrepareAccountActivationModel(model);

            return View(model);
        }
Example #2
0
        public ActionResult AccountActivation(AccountActivationModel model)
        {
            if (ModelState.IsValid)
            {
                var user = ValidateUserActivation(model.UserId, model.Token, SystemUserAttributeNames.AccountActivationToken);

                // set the question and answers and the security verification image for this user in the database
                if (user != null)
                {
                    // set this user unique password
                    ChangePasswordRequest changeRequest = new ChangePasswordRequest(user.Username,
                        false, model.Password);
                    var changeResult = userRegistrationService.ChangePassword(changeRequest);

                    if (changeResult.Success)
                    {
                        // activate this user account now
                        user.CurrentPublishingStatus = PublishingStatus.Active;
                        user.LastActivityDate = DateTime.UtcNow;
                        userService.Update(user);

                        // need to delete the activation token
                        attributeService.SaveAttribute(user, SystemUserAttributeNames.AccountActivationToken, string.Empty);

                        SuccessNotification("Your account has been activated");
                        return RedirectToRoute(SystemRouteNames.Login);
                    }

                    ErrorNotification(changeResult.ErrorMessages);
                }
            }

            // reached here, means error, show the form again
            PrepareAccountActivationModel(model);
            return View(model);
        }
Example #3
0
        private void PrepareAccountActivationModel(AccountActivationModel model)
        {
            Guard.IsNotNull(model, "model");

            // retrieve the user
            var user = userService.GetById(model.UserId);
            if (user != null)
            {
                model.ContactName = user.GetFullName();
                model.UserName = user.Username;
            }
        }