Developer forum

Forum » Development » Web handler and extranet user login

Web handler and extranet user login

Vilius Janulis
Reply
Hi,

I am having difficulties trying to login users from web handler.
The web handler by itself works, only the login part does not work for me.
Have searched documentation and forum and found few ways to do that, but after quite some tries still could not make it work.

Html form :
<form action="/Admin/Public/CreateLogins.ashx" method="post" name="loginForm">
	<input type="text" name="username" value="Username.."/>
	<input type="password" name="password" value="Password.."/>
	<input type="submit" value="Login" name="submit">
</form>

Web handler : 

namespace CustomModules.CustomModules
{
    /// <summary>
    /// Summary description for CreateLogins 
    /// </summary>
    public class CreateLogins : IHttpHandler
    {
        public string username;
        public string password;

        public void ProcessRequest(HttpContext context)
        {
		context.Response.ContentType = "text/html";
	    if (context.Request["username"] != null && context.Request["password"] != null)
            {
		username = context.Request["username"].ToString();
                password = context.Request["password"].ToString();

		/* first try */
                 Dynamicweb.Security sec = new Dynamicweb.Security();

		 Dynamicweb.Backend.User usr = new Dynamicweb.Backend.User();
                 usr.UserName = username;
                 usr.Name = username;
                 usr.Password = password;

		 sec.ExtranetLogin("test", "test", true);

		/* second try */
                 Dynamicweb.Security sec = new Dynamicweb.Security();

                 Dynamicweb.Modules.UserManagement.User user = new Dynamicweb.Modules.UserManagement.User();
                 user.UserName = username;
                 user.Password = password;

                 sec.ExtranetLogin("test", "test", true);

		/* third try */

		Dynamicweb.Modules.UserManagement.User.set_Current(Dynamicweb.Modules.UserManagement.PagePermissionLevels.Frontend, Dynamicweb.Modules.UserManagement.User.GetUserByUserName(username));
	    }
	}
	public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

And when i enter in the fields existing login information (test test), i get :

Object reference not set to an instance of an object. at 
Dynamicweb.Modules.UserManagement.User.set_Current(PagePermissionLevels level, User value) at 
Dynamicweb.Security.ExtranetLogin(String username, String password, Boolean onlyActive) at 
CustomModules.CustomModules.CreateLogins.ProcessRequest(HttpContext context) 
in ........\Admin\Public\CreateLogins.ashx.cs:line 72Dynamicweb


Not one of them worked.
test users with test password exists in extranet group in solution.
Using dw 8.0.1.5 version.
The error line number is the methods externalLogin or set_Current.

Is there other ways, or is there some not logic places in my code (of course every try was tested separately and not all of them at once) ?
Does there are other requirements for this use, except that extranet module has to be installed ? (it is installed)

Thank you for all the help.

Replies

 
Vilius Janulis
Reply
 Ok found oter solution or overcome , by redirecting to the url, so can be closed.

 

You must be logged in to post in the forum