Get extra User infomation when logging in - (Completely new to CSLA)

Get extra User infomation when logging in - (Completely new to CSLA)

Old forum URL: forums.lhotka.net/forums/t/8030.aspx


strangerd posted on Monday, November 23, 2009

Hi

I have been searching everywhere for a good solution for my problem, but have only found half created pieces of code.

I know that you only get the username currently it seems from the Identity. I would like to get the full name of the user and whether the user is admin, etc. (all is stored in DB).

I read that you need to create custom Identity. I read the book and don't really get what I have to do to make it work (where I have to place what and what to import and what to call, etc.)

I am really in need of help.

UPDATE:
The other thing I can also do is get the information by just reading info from the User object by giving it the Username I use when logging in). This might be easier but I am also at a loss on what to do.

Thank you

dlambert replied on Monday, November 23, 2009

Look in the ProjectTracker sample at the ProjectTracker.Library.Security.PTIdentity object and see if this is what you're trying to do. You'd add something like a FullName property and fill it in the DP_Fetch method.

Is this about right?

strangerd replied on Monday, November 23, 2009

Everything is returned in the DP_Fetch method.

I created properties for all the required fields. So I can call all the fields:

(TxtName is the textbox in which I type the user name. ID is a class level variable I require. I have not tried the other new ones yet)

CODE:
-------------
    Dim n As Object = txtName.Text     'I tried this (It does not give any errors)

    ID = CType(n, UserInfo).Id

And it gives this error:
Unable to cast object of type 'System.String' to type 'ITIMS.Library.UserInfo'.


But if you use a list's selecteditem, it works fine with bringing back the data.

So is there any way this can be dealt with?

Thank you


dlambert replied on Monday, November 23, 2009

If you're trying to access the contents of the text box directly in the Principal or Identity object's DP_Fetch, you're going to run into problems.

See how the PTracker app grabs these values in the UI and sends them to the business library - ex:

ProjectTracker.Library.Security.PTPrincipal.Login(this.UsernameTextBox.Text, this.PasswordTextBox.Text)

Sorry if I'm not following you on this, but I think you're going to want to make sure you can get login working (in the easy case), and then add your extra attributes.

strangerd replied on Tuesday, November 24, 2009

The usual login code works fine with the two parameters, yes. So I would have to see what I can do to bring back things like the ID and full name of person, to the UI and UI code.

If you have any other suggestions please let me know.

Thanks for your help.

Copyright (c) Marimer LLC