Custom Logon Module - how to convert IQueryable to IUser?

Topics: Core, Customizing Orchard, Writing modules
Feb 3, 2013 at 9:00 PM
Hi,

I wrote a custom logon module to replace the default logon view, verify user using my web service, it works well. However after the user has been verified (logon-ed), it returns a 'IQueryable' interface, so I can get the user information from my database, i.e.:

user.firstname
user.lastname
user.email
user.phone
...
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var myUser = myUserRepository.Login(model.EmailAddress, model.Password);
                if (myUser != null)
                {
                    string userName = myUser.lastname+ " (" + myUser.firstname +")";
                    FormsAuthentication.SetAuthCookie(userName, model.RememberMe);
                    return RedirectToAction("Index", "Home");                
                }
            }

            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
But the user doesn't seem to 'logon', as I don't see the 'sign out' link after successful verified from my database.

So how to set the user logon status in Orchard? i.e. I want to show the user's full name and email in the Index view. So the user record (IQueryable) needs to be converted to Orchard IUser class, in order to set the Orchard authorization status.

Thanks!
Jim
Feb 4, 2013 at 11:00 AM
var user = membershipService.GetUser(user.email).As<UserPart>();
Although I think I may be missing your problem here, I'm kinda tired ^^
Feb 4, 2013 at 7:25 PM
Thanks Hazza for your response.
but the GetUser() is a function of the Orchard MembershipService class - where it getting user from? Apparently not getting from my custom database!
So does that mean I will have to override the MembershipService?


Thanks!
Feb 4, 2013 at 8:47 PM
Oh I see, so you are not using the Orchard stuff at all... I'm not sure about that, Orchard users are a content type. I guess yeah you will have to overwrite the entire authentication procedure.
Feb 5, 2013 at 8:20 PM
Thanks Hazza,

Anyone can help?