Run code when user logs in

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
10/8/2009 6:05:26 PM
Gravatar
Total Posts 19

Run code when user logs in

I want to do a database lookup when a user logs in. I added a new field called TeamID to the mp_Users table that I want to read at login. I didn't use the mp_UserProperties table because I want to be able to sort users based on an integer stored in the TeamID field. Also, I'd like to redirect a user to a specific page based on their role when they login, or at least be able to redirect everyone to a "members.aspx" page.

I read the document "User Sign In Event Handlers" but that is way over my head. I don't know how to make a DLL. In other ASP.net websites I've built, I've added code in the Page_Load event of the login page. Is there an easy way to create a function and then call it at login?

I may want to use a session variable to track the TeamID.  If a user logs out, is there a way to clear the session var at logout? 

10/9/2009 12:01:57 PM
Gravatar
Total Posts 18439

Re: Run code when user logs in

I do not recommend modifying any of the mojoportal source code nor modifying any mojoportal tables. By modifying code you are making a fork and making it unlikely that you will be able to get upgrades without losing your changes. 

You must be used to working with ASP.NET Web Site Projects which is not pre-compiled. mojoPortal uses the Web Application Project type where all the C# code is compiled into dlls. If you do not know how to work with that model I have no solution for you other than to learn how.

You simply create a class library project for a UserSignInHandler, you implement it and compile the project it produces a dll. Put that in the /bin folder and register it according to the documentation.

Hope it helps,

Joe

10/22/2009 12:25:18 AM
Gravatar
Total Posts 19

Re: Run code when user logs in

Yes, I am used to web site projects with VB, so I'm really struggling...

I found a key that solved my problem of running code when a user logs in: <add key="PageToRedirectToAfterSignIn" value="~/members.aspx"/> .  A user control on the members.aspx page runs code when the user logs in.  It may not be the cleanest solution, but it seems to work for what I want to do.  I understand that this is a global setting for all sites.

Now I want to redirect a newly registered user to a specific page.  I didn't see a key for "PageToRedirectToAfterREGISTRATION", so I think this would make a nice enhancement to mojoPortal, even if it is a global setting.

I'm trying to create a registered user event handler.  After several hours I'm not even close.  I just want to redirect a new user to somepage.aspx.  I get these errors when I try to build:

The type or namespace name 'Provider' does not exist in the namespace 'System.Configuration'
The type or namespace name 'log4net' could not be found
The type or namespace name 'UserRegisteredHandlerProvider' could not be found
The type or namespace name 'ILog' could not be found
The type or namespace name 'UserRegisteredEventArgs' could not be found

It sounds like I need to add some references, but this where I'm not sure what or where to find them. 

In VS2008 I'm choosing New > Project > Class Library.  I paste the sample from the documentation, rename the class and
namespace mojoPortal.Business.WebHelpers.UserRegisteredHandlers to MyUserRegisteredHandlers.  That's where I have no idea what to do.  I've tried downloading the mojoPortal source and building a solution there, but I get the same errors.  Can anyone point me in the right direction?

I'd love to see a \data\sites\1\site.config file for site settings like this.

Thanks!
Tom

12/21/2009 5:56:28 PM
Gravatar
Total Posts 19

Re: Run code when user logs in

I've spent many hours trying to create the registered event handler and could really use some help. Could someone answer some basic questions?

Should I create a new project using the deployment files, or do I need the source code? I've tried both. Is the Subversion repository version needed?

Does it matter in what folder should I create the project?

How to reference assemblies seems to be the main problem. System.Configuration.Provider always generates the error "The type or namespace name 'Provider' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?).

If I can't get any help, I'll need to hire someone.  I just want to redirect to new users to /members.aspx.  Anyone interested?

12/22/2009 8:59:46 AM
Gravatar
Total Posts 18439

Re: Run code when user logs in

Hi,

If all you want to do is redirect to the /members.aspx page then there is a web.config setting you can use. Put this in your user.config then touch your Web.config so it reloads settings:

<add key="PageToRedirectToAfterSignIn" value="/members.aspx" />

note that the above is correct if running as a root site, if running in a virtual directory you may need the folder in the path like /foldnername/members.aspx

Hope it helps,

Joe

12/22/2009 12:49:46 PM
Gravatar
Total Posts 19

Re: Run code when user logs in

I'm trying to redirect a newly registered user to /members.aspx. New users are confused about where to go once they register.

I followed the instructions at http://www.mojoportal.com/user-registered-event-handlers.aspx but I don't know where to create the project, and if I need to use the source code or just the deployment files. 

Each time I try to build the project I get errors about assembly references missing, and I just need to figure out what I'm missing. Is it possible that additional steps are missing from the user-registered-event-handlers.aspx documentation? It sounds like a 5 minute job, but I have over 6 hours working on this.

Does it matter which folder I use to create the project?

Any help on what I'm missing would really be appreciated!

You must sign in to post in the forums. This thread is closed to new posts.