Skip to content
Mostey edited this page Oct 2, 2014 · 7 revisions

Creating the Session

Creating a session is required for almost every single function in the library. By creating the authenticated session, you provide login information that is used for logging into your elitepvpers account. Cookies get stored for further usage and are valid until you destroy the session.

There are some functions implemented that are also accepting an instance of type GuestSession which operates without user accounts. Using this class, you can do things like updating user profiles or section threads and more if the function accepts the GuestSession type.

Binding your account to the session

For binding your user account to a session, the AuthenticatedSession class can be used. You'll need to provide the type of the user that fits best your situation (currently either User or PremiumUser as template parameter).

User mostey = new User("Mostey", 467410);
var session = new AuthenticatedSession<User>(mostey, "mySecretMd5Hash"); // in case the md5 hash of the password is provided, the session will automatically try to login
// call session.Valid; for checking if the login was successful and if the session is valid for further usage
// ...
session.Destroy();

Note that I've provided the profile ID in the user constructor? While it isn't necessary to provide the ID, you should do it whenever possible. The reason for this is the auto id detection that is triggered straight after the login was successful. If the id couldn't be parsed and you didn't specify the id by yourself, an System.ArgumentException will be thrown on the User.Update function that is executed after the login to update the session user.

Getting started

You should be aware of how we implemented the AuthenticatedSession<TUser> class since other classes and functions expect certain properties that are contained within the AuthenticatedSession<TUser> class:

Basically, we got a property named ConnectedProfile of type AuthenticatedSession<TUser>.Profile which is used for modeling the logged-in user that is bound to the session. The session contains cookies and other information (such as the security token) for this particular user. Nearly all functions expect an Session<TUser> object when interacting with elitepvpers. Since every connected profile got their associated user, you can get that object using the AuthenticatedSession<TUser>.ConnectedProfile.User property. We also provided a shortcut for quick access if you don't need the exclusive Profile functions: AuthenticatedSession<TUser>.User.

If you are looking for functions that require you to be the logged-in user, the ProfileSession<TUser>.Profile class is the first place to look for. Why? Because they wouldn't make any sense when used in a generic way within the User class, as it was implemented before.


Extensions and custom implementations

You may write your own functions and class wrappers by just deriving from the GuestSession or AuthenticatedSession class that provide basic IO HTTP POST/GET functions.

Security tokens

Sometimes, when posting data on elitepvpers pages, you will need to provide a valid security token which is stored in a javascript container. This container is available on each site and is updating on every page refresh. For some reason, you will need to update your session only once after logging in. The security token will keep changing but you can provide the old one which you initially got from logging in.