/// <summary> /// Sends a user's master server login credentials to the master server. /// If successful, the user's profile information will be sent back /// excluding the password. /// </summary> /// <param name="loginCredentials"></param> /// <returns></returns> public UserProfile AttemptUserLogin(LoginCredentials loginCredentials) { try { // Ensure that we don't send any invalid data to the server. if (Object.ReferenceEquals(loginCredentials, null) || String.IsNullOrWhiteSpace(loginCredentials.Password) || String.IsNullOrWhiteSpace(loginCredentials.UserName)) { return null; } string jsonObject = JsonConvert.SerializeObject(loginCredentials, SerializerSettings); string result = SendJsonRequest("ValidateLoginCredentials", WebServiceMethodTypeEnum.User, jsonObject); return JsonConvert.DeserializeObject<UserProfile>(result, SerializerSettings); } catch(Exception ex) { throw new Exception("Error sending login credentials.", ex); } }
/// <summary> /// Sends login credentials to master server and attempts to log in. /// Returns true if log in is successful. /// Returns false if log in is unsuccessful. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void LoginButtonClickAsync(object sender, JavascriptMethodEventArgs args) { string username = args.Arguments[0]; string password = args.Arguments[1]; LoginCredentials loginCredentials = new LoginCredentials(username, password); UserProfileResponseTypeEnum responseType = UserProfileResponseTypeEnum.Failure; await TaskEx.Run(() => { WinterEngineService.InitializeUserProfile(WebUtility.AttemptUserLogin(loginCredentials)); if (WinterEngineService.ActiveUserProfile.UserID > 0 && WinterEngineService.ActiveUserProfile.IsEmailVerified) { WinterEngineService.ActiveUserProfile.IsLoggedIn = true; responseType = UserProfileResponseTypeEnum.Successful; } else if (WinterEngineService.ActiveUserProfile.UserID > 0 && !WinterEngineService.ActiveUserProfile.IsEmailVerified) { responseType = UserProfileResponseTypeEnum.AccountNotActivated; } else { responseType = UserProfileResponseTypeEnum.InvalidPassword; } loginCredentials.UserName = ""; loginCredentials.Password = ""; }); AsyncJavascriptCallback("DoLogin_Callback", (int)responseType); }