private void mnuLogin_Click(object sender, EventArgs e) { string originalStatus = Status; try { if (string.IsNullOrEmpty(txtUserName.Text)) { txtUserName.Focus(); throw new UserThrownException("Username not entered.", false, true, false); } if (string.IsNullOrEmpty(txtPassword.Text)) { txtPassword.Focus(); throw new UserThrownException("Password not entered.", false, true, false); } using (WaitCursor w = new WaitCursor()) { Status = "Attempting to login ..."; ServiceFunctionResultOfUser result = GlobalDataCache.Instance.Service.Login(txtUserName.Text, txtPassword.Text, UserRoleId.Web); if (ServiceResultHandler.HandleServiceResult(result)) { return; } User u = result.Contents; if (u == null) { throw new UserThrownException("Invalid username/password", false, true, false); } GlobalDataCache.Instance.CurrentUser = u; Status = "Downloading user permissions ..."; if (GlobalDataCache.Instance.CurrentUser.UserPermissionCache.RefreshFromServerForUser(GlobalDataCache.Instance.CurrentUser)) { return; } Status = "Downloading global server variables ..."; if (GlobalDataCache.Instance.GlobalServerVariables.RefreshFromServer()) { return; } } this.DialogResult = DialogResult.OK; Close(); } finally { if (Status != originalStatus) { Status = originalStatus; } } }
private static void Login() { Console.Write("Attempting to login ... "); ServiceFunctionResultOfUser result = GlobalDataCache.Instance.Service.Login( "FiglutSystemUser", "(L!3nT", UserRoleId.System); if (result.Code != ServiceResultCode.Success) { throw new Exception("Invalid user name /password."); } GlobalDataCache.Instance.CurrentUser = result.Contents; Console.WriteLine("done."); }