ContextFactory Class |
Factory to create a new context of execution
A context of execution is almost require to instantiate all objects.
Consider the creation of context the entry point of the AskiaPortalCmn usage.
According to the AuthenticationType of the context, the API will be restricted.
For example, a context created for registration (ForRegistration) will only allow the creation of a new user and send to him email(s) to activate the user account.
Namespace: AskiaPortalCmn
The ContextFactory type exposes the following members.
Name | Description | |
---|---|---|
CreateByLoginOrEmailAndPassword | Creates a new context of execution for the user with the specified login (or email) and password. | |
CreateBySessionKey | Creates a new context of execution for the user behind the session key. | |
CreateByUserEmail | Creates a new context of execution for the user with the specified email address. | |
CreateByUserEncryptedKey | Creates a context using the encryption key of a user. | |
CreateByUserGuid | Creates a new context of execution for the user with the specified GUID. | |
CreateByUserToken | Creates a new context of execution for the user with the specified user token. | |
CreateForRegistration | Creates a special restricted context of execution to register a user account. | |
CreateForSuperAdmin | Creates a new context of execution for the super administrator. |
This example shows how to create a context to register a user.
The created context will restrict the usage of API methods.
It only allow creation of account and send emails to activate it.
using system; using AskiaPortalCmn; namespace MyApp { class Program { static void Main(string[] args) { var context = ContextFactory.CreateForRegistration(); context.User.FirstName = "John"; context.User.LastName = "Doe"; context.User.Email = "johndoe@anonymous.com"; var saveResult = context.User.Save(); if (saveResult.Success) { Console.WriteLine("The account for the user `{0} {1}` was successfully created. An email has been sent to `{2}`", context.User.FirstName, context.User.LastName, context.User.Email); } else { Console.Error.WriteLine("Unable to create the user account"); Console.Error.Write(saveResult.Exception.Message); } } } }