Пример #1
0
        /// <summary>
        /// Activates user account
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="emailConfirmationToken"></param>
        /// <returns></returns>
        public static async Task <AccountActivationOutput> ActivateAccountAsync(Guid?userId, string emailConfirmationToken)
        {
            var output = new AccountActivationOutput();

            if (!userId.HasValue)
            {
                output.UnknownUser = true;
                return(output);
            }

            var userManager = MapHive.Core.Identity.UserManagerUtils.GetUserManager();

            //extract user guid from token

            var idUser = await userManager.FindByIdAsync(userId.ToString());

            if (idUser != null)
            {
                await userManager.ConfirmEmailAsync(idUser, emailConfirmationToken);

                output.Success = true;
            }
            else
            {
                output.UnknownUser = true;
            }

            //Note:
            //TODO perhaps token can expire as in v1???


            return(output);
        }
Пример #2
0
        public static async Task <AccountActivationOutput> ActivateAccountAsync <TAccount>(
            UserAccountService <TAccount> userAccountService, string verificationKey, string initialPassword)
            where TAccount : RelationalUserAccount
        {
            var output = new AccountActivationOutput();

            var user = userAccountService.GetByVerificationKey(verificationKey);

            if (user == null)
            {
                output.UnknownUser = true;
                return(output);
            }

            //see if the verification key is not stale (expired). If so issue a reset pass command, that will fire an account created event with a new key, but without password (that should have been sent out on account create)
            if (userAccountService.IsVerificationKeyStale(user.ID))
            {
                //in a case verification key is stale (outdated pretty much) need to trigger additional pass reset
                //and send some info to a user, so ne verification key can be provided
                AccountCreatedEvent <TAccount> e = null;
                userAccountService.Configuration.AddEventHandler(new MembershipRebootEventHandlers.AccountCreatedEventHandler <TAccount>
                                                                     ((evt) =>
                {
                    e = evt;
                })
                                                                 );
                userAccountService.ResetPassword(user.ID);

                //since got here the reset pass dod not fail and can add som data to output
                output.Email                = user.Email;
                output.VerificationKey      = e.VerificationKey;
                output.VerificationKeyStale = true;
                return(output);
            }
            else
            {
                userAccountService.VerifyEmailFromKey(verificationKey, initialPassword);
                output.Success = true;
                return(output);
            }
        }