Rock.Model.UserLoginService.GetByConfirmationCode C# (CSharp) Метод

GetByConfirmationCode() публичный Метод

Returns a Rock.Model.UserLogin by an encrypted confirmation code.
public GetByConfirmationCode ( string code ) : UserLogin
code string A containing the encrypted confirmation code to search for.
Результат UserLogin
        public UserLogin GetByConfirmationCode( string code )
        {
            if ( !string.IsNullOrEmpty( code ) )
            {
                string identifier = string.Empty;
                try { identifier = Rock.Security.Encryption.DecryptString( code ); }
                catch { }

                if ( identifier.StartsWith( "ROCK|" ) )
                {
                    string[] idParts = identifier.Split( '|' );
                    if ( idParts.Length == 4 )
                    {
                        string publicKey = idParts[1];
                        string username = idParts[2];
                        long ticks = 0;
                        if ( !long.TryParse( idParts[3], out ticks ) )
                            ticks = 0;
                        DateTime dateTime = new DateTime( ticks );

                        // Confirmation Code is only valid for an hour
                        if ( RockDateTime.Now.Subtract( dateTime ).Hours > 1 )
                            return null;

                        UserLogin user = this.GetByEncryptedKey( publicKey );
                        if ( user != null && user.UserName == username )
                            return user;
                    }
                }
            }

            return null;
        }

Usage Example

        /// <summary>
        /// Shows the reset success.
        /// </summary>
        private void ShowResetSuccess()
        {
            RockContext rockContext = new RockContext();
            UserLoginService userLoginService = new UserLoginService( rockContext );
            UserLogin user = userLoginService.GetByConfirmationCode( this.ConfirmationCode );

            if ( user != null )
            {
                string caption = GetAttributeValue( "PasswordResetCaption" );
                if ( caption.Contains( "{1}" ) )
                {
                    caption = string.Format( caption, user.Person.FirstName, user.UserName );
                }
                else if ( caption.Contains( "{0}" ) )
                {
                    caption = string.Format( caption, user.Person.FirstName );
                }

                lResetSuccess.Text = caption;

                userLoginService.SetPassword( user, tbPassword.Text );
                user.IsConfirmed = true;
                rockContext.SaveChanges();

                pnlResetSuccess.Visible = true;
            }
            else
            {
                ShowCode();
            }
        }
All Usage Examples Of Rock.Model.UserLoginService::GetByConfirmationCode