/// <summary> /// <see cref="IChatService.LogIn"/> /// </summary> public string LogIn(string accountName, int port) { // Lookup the account who is trying to log in. var account = DatabaseProcedures.GetAccountByName(accountName); if (account == null) { var response = new LoginResponse { Result = LoginResult.AccountNotRegistered, Account = null }; return JsonConvert.SerializeObject(response); } // Set the account's new IP/port. account.IpAddress = this.GetClientIpAddress(); account.Port = port; DatabaseProcedures.SetIpAndPort(account); // Get the account's friends. We don't want to expose the friends' IP addresses or ports so we strip those out in // the friend model. var friendAccounts = DatabaseProcedures.GetFriends(account.Id).ToList(); account.Friends = friendAccounts.Select(friend => new Friend { Id = friend.Id, UserName = friend.UserName, Presence = ServiceHelpers.GetPresence(friend) }); // Send a presence event to each of the user's friends to notify them that this // user has come online. this.NotifyFriendsOfPresenceChange(account, friendAccounts); var successResponse = new LoginResponse { Result = LoginResult.Success, Account = account }; return JsonConvert.SerializeObject(successResponse); }
private void HandleSuccessfulLogin(LoginResponse response) { // Log the success. this.Logger.Info($"LoginViewModel.LogIn - The account {response.Account.UserName} successfully logged in at " + $"{DateTime.Now}."); this._parent.DisplayName += $" ({response.Account.UserName})"; this._parent.ShowMainPage(response.Account); }