Agamemnon
Agamemnon

Reputation: 607

Log into DotNetNuke site remotely

I am creating a simple web service, for DotNetNuke 7, that will allow an iOS or Android app to authenticate a user with our website to make sure they are a member and so allowed to view restricted content on the app.

I have a test webservice running that responds to annonymous connections. How do I actually get it to login into the website and retrieve data back (like roles and contact information)?

public class SiteLoginController : DnnApiController  
{
    [DnnAuthorize]
    [HttpGet]
    public HttpResponseMessage LoginToSite(string username, string password)
    {
        // go log into website
        // if they have an account
        // retrieve role and contact info
        // else
        // return invalid credentials message
    }
}

I have looked online for a while now and most answers seem to relate to allowing annonymous access and not actually authenticating the user.

Upvotes: 0

Views: 171

Answers (2)

Mitchel Sellers
Mitchel Sellers

Reputation: 63136

Honestly, the easier solution would be to simply pass the username & password as basic authentication, using the [DnnAuthorize] attribute you can validate that the user is the one you want and you can then use UserController.GetCurrentUser() to get the logged in user.

Upvotes: 1

VDWWD
VDWWD

Reputation: 35564

You don't need to log in to get the user info. Although I'm not sure the logging in part works from a web service.

UserInfo user = UserController.GetUserByName(username);

if (user != null)
{
    string email = user.Email;
}
else
{
    //user not found
}

Or if you do want to log in for added security, you can do this:

string resultText = string.Empty;

UserLoginStatus loginStatus = new UserLoginStatus();
UserController.UserLogin(PortalId, username, password, null, PortalSettings.PortalName, DotNetNuke.Services.Authentication.AuthenticationLoginBase.GetIPAddress(), ref loginStatus, false);

switch (loginStatus)
{
    case UserLoginStatus.LOGIN_SUCCESS:
        resultText = "OK";
        break;
    case UserLoginStatus.LOGIN_FAILURE:
        resultText = "Failure";
        break;
    case UserLoginStatus.LOGIN_USERLOCKEDOUT:
        resultText = "Locked out";
        break;
    case UserLoginStatus.LOGIN_USERNOTAPPROVED:
        resultText = "Not approved";
        break;
    default:
        resultText = "Unknown error";
        break;
}

Upvotes: 1

Related Questions