/// <summary> /// Fire user logged in event. /// </summary> /// <param name="userContext">Information about the user that has logged in.</param> private void FireUserLoggedInEvent(IUserContext userContext) { if (UserLoggedInEvent.IsNotNull()) { UserLoggedInEvent(userContext); } }
/// <summary> /// Login user. /// </summary> /// <param name="userName">User name.</param> /// <param name="password">Password.</param> /// <param name="applicationIdentifier"> /// Identifier of the application that the user uses. /// </param> /// <param name="isActivationRequired"> /// Flag that indicates that the user account must /// be activated before login can succeed. /// </param> /// <param name="errorMessage">Possible error message if login failed.</param> /// <returns>True if user was logged in.</returns> public static Boolean Login(String userName, String password, String applicationIdentifier, Boolean isActivationRequired, out String errorMessage) { Boolean isUserLoggedIn = false; // Check arguments. userName.CheckNotEmpty("userName"); password.CheckNotEmpty("password"); // Make sure the user is not already logged in. Logout(); // Loggin. try { errorMessage = null; isUserLoggedIn = WebServiceClient.Login(userName, password, applicationIdentifier, isActivationRequired); } catch (WebException) { // No contact with web service. errorMessage = "Validering av ditt konto misslyckades!\nIngen kontakt mot servern gick att erhålla."; } catch (Exception exception) { errorMessage = "Validering av ditt konto misslyckades!\nServern returnerade ett fel.\n" + exception.Message; } if (isUserLoggedIn) { // Get user information. _user = GetUser(WebServiceClient.GetUser()); // Fire user logged in event. if (UserLoggedInEvent.IsNotNull()) { UserLoggedInEvent(); } } return(isUserLoggedIn); }