Login Extender

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0.8
  • Enterprise
  • Community
  • Planned

Overview

Sense/Net provides full control over the login procedure of users and hence developers can easily implement custom login validation or logging without modifying the Login portlet or the view.

Details

Login operations are customizable by one or more LoginExtenders. A LoginExtender is inherited from the public abstract LoginExtender class, and overrides some virtual methods. The all five overridable method have a LoginInfo parameter that contains the content of the login control's UserName textbox, and a message. The overridables:


public virtual void LoggingIn(CancellableLoginInfo info)
  • This method will be called when a user is attempting to log in.
  • The possibilities: modifying user name and cancellation. If info.Cancel is set to true, the login will be cancelled.


public virtual void LoggedIn(LoginInfo info)
  • This method will be called when a user is successfully logged in.


public virtual void LoggingOut(CancellableLoginInfo info)
  • Cancellable method that is called after the interactive user pushed the Logout link. If info.Cancle is set to true, the logging out operation will be cancelled.


public virtual void LoggedOut(LoginInfo info)
  • Will be called when the user is logged out.


public virtual void LoginError(LoginInfo info)
  • Will be called when a login error occurs. The message in the login info is editable and it will be written into the login box.

Examples

A sample login extender. Requirement: this class should be placed an assembly that is in the web's bin directory. Our system will find and use it. The sample extender modifies the user name if it is "admin2", bans the "banned" username, rewrites the error message and writes some debug information.

    public class MyLoginExtender : LoginExtender
    {
        public override void LoggingIn(CancellableLoginInfo info)
        {
            Debug.WriteLine(String.Format("|> MyLoginExtender.LoggingIn. UserName: {0}, Message: {1}", info.UserName, info.Message));
            var userName = info.UserName.ToLower();
            if (userName == "admin2" || userName.EndsWith("builtin\\admin2"))
            {
                info.UserName = info.UserName.Substring(0, info.UserName.Length - 1);
            }
            else if (userName == "banned" || userName.EndsWith("builtin\\banned"))
            {
                info.Message = "You are banned.";
                info.Cancel = true;
            }
        }
        public override void LoggedIn(LoginInfo info)
        {
            Debug.WriteLine(String.Format("|> MyLoginExtender.LoggedIn. UserName: {0}, Message: {1}", info.UserName, info.Message));
        }
        public override void LoggingOut(CancellableLoginInfo info)
        {
            Debug.WriteLine(String.Format("|> MyLoginExtender.LoggingOut. UserName: {0}, Message: {1}", info.UserName, info.Message));
            if (DateTime.Now.Minute % 2 == 0)
            {
                info.Message = "You can logout at odd minutes";
                info.Cancel = true;
            }
        }
        public override void LoggedOut(LoginInfo info)
        {
            Debug.WriteLine(String.Format("|> MyLoginExtender.LoggedOut. UserName: {0}, Message: {1}", info.UserName, info.Message));
        }
        public override void LoginError(LoginInfo info)
        {
            Debug.WriteLine(String.Format("|> MyLoginExtender.LoginError. UserName: {0}, Message: {1}", info.UserName, info.Message));
            info.Message += " ####";
        }
    }

Related links

References

  • No references for this article.