ContextFactoryCreateByLoginOrEmailAndPassword Method |
Creates a new context of execution for the user with the specified login (or email) and password.
Namespace: AskiaPortalCmn
public static IContext CreateByLoginOrEmailAndPassword( string loginOrEmail, string password, string apiKey = null )
The context created will restrict the usage of API methods according to the role of the user.
If the user is not found it return an invalid context with no user
You may check the validity of the context using Validate
This example shows how to create a context to authenticate a user using his login and password.
using system; using AskiaPortalCmn; namespace MyApp { class Program { static void Main(string[] args) { var context = ContextFactory.CreateByLoginOrEmailAndPassword("my-login", "secret"); var validationResult = context.Validate(); if (validationResult.Success) { Console.WriteLine("Context successfully created for the user `{0} {1} ({2})`", context.User.FirstName, context.User.LastName, context.User.Login); } else { Console.Error.WriteLine("Unable to create the context"); Console.Error.Write(validationResult.Exception.Message); } } } }