Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class AuthenticationView : Subview
{
private static readonly Vector2 viewSize = new Vector2(290, 290);

private const string CredentialsNeedRefreshMessage = "We've detected that your stored credentials are out of sync with your current user. This can happen if you have signed in to git outside of Unity. Sign in again to refresh your credentials.";
private const string NeedAuthenticationMessage = "We need you to authenticate first";
private const string WindowTitle = "Authenticate";
private const string UsernameLabel = "Username";
private const string PasswordLabel = "Password";
Expand All @@ -24,10 +26,10 @@ class AuthenticationView : Subview
[SerializeField] private string username = string.Empty;
[SerializeField] private string two2fa = string.Empty;
[SerializeField] private string message;
[SerializeField] private string errorMessage;
[SerializeField] private bool need2fa;

[NonSerialized] private bool need2fa;
[NonSerialized] private bool isBusy;
[NonSerialized] private string errorMessage;
[NonSerialized] private bool enterPressed;
[NonSerialized] private string password = string.Empty;
[NonSerialized] private AuthenticationService authenticationService;
Expand All @@ -37,18 +39,30 @@ public override void InitializeView(IView parent)
{
base.InitializeView(parent);
need2fa = isBusy = false;
message = errorMessage = null;
Title = WindowTitle;
Size = viewSize;
}

public override void OnEnable()
public void Initialize(Exception exception)
{
base.OnEnable();
}
var usernameMismatchException = exception as TokenUsernameMismatchException;
if (usernameMismatchException != null)
{
message = CredentialsNeedRefreshMessage;
username = usernameMismatchException.CachedUsername;
}

public override void OnDisable()
{
base.OnDisable();
var keychainEmptyException = exception as KeychainEmptyException;
if (keychainEmptyException != null)
{
message = NeedAuthenticationMessage;
}

if (usernameMismatchException == null && keychainEmptyException == null)
{
message = exception.Message;
}
}

public override void OnGUI()
Expand Down Expand Up @@ -81,27 +95,7 @@ public override void OnGUI()
}
GUILayout.EndScrollView();
}

public void SetMessage(string value)
{
message = value;
}

public void ClearMessage()
{
message = null;
}

public void SetUsername(string value)
{
username = value;
}

public void ClearUsername()
{
username = string.Empty;
}


private void HandleEnterPressed()
{
if (Event.current.type != EventType.KeyDown)
Expand Down Expand Up @@ -174,8 +168,7 @@ private void OnGUI2FA()
if (GUILayout.Button(BackButton))
{
GUI.FocusControl(null);
need2fa = false;
Redraw();
Clear();
}

if (GUILayout.Button(TwofaButton) || (!isBusy && enterPressed))
Expand All @@ -196,27 +189,36 @@ private void OnGUI2FA()

private void DoRequire2fa(string msg)
{
Logger.Trace("Strating 2FA - Message:\"{0}\"", msg);
Logger.Trace("Starting 2FA - Message:\"{0}\"", msg);

need2fa = true;
errorMessage = msg;
isBusy = false;
Redraw();
}

private void Clear()
{
need2fa = false;
errorMessage = null;
isBusy = false;
Redraw();
}

private void DoResult(bool success, string msg)
{
Logger.Trace("DoResult - Success:{0} Message:\"{1}\"", success, msg);

errorMessage = msg;
isBusy = false;

if (success == true)
{
Clear();
Finish(true);
}
else
{
errorMessage = msg;
Redraw();
}
}
Expand Down
37 changes: 1 addition & 36 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ namespace GitHub.Unity
[Serializable]
class PopupWindow : BaseWindow
{
private const string CredentialsNeedRefreshMessage = "We've detected that your stored credentials are out of sync with your current user. This can happen if you have signed in to git outside of Unity. Sign in again to refresh your credentials.";
private const string NeedAuthenticationMessage = "We need you to authenticate first";

public enum PopupViewType
{
None,
Expand Down Expand Up @@ -63,32 +60,8 @@ private void Open(PopupViewType popupViewType, Action<bool> onClose)

}, exception => {
Logger.Trace("User required validation opening AuthenticationView");

string message = null;
string username = null;

var usernameMismatchException = exception as TokenUsernameMismatchException;
if (usernameMismatchException != null)
{
message = CredentialsNeedRefreshMessage;
username = usernameMismatchException.CachedUsername;
}

var keychainEmptyException = exception as KeychainEmptyException;
if (keychainEmptyException != null)
{
message = NeedAuthenticationMessage;
}

if (usernameMismatchException == null && keychainEmptyException == null)
{
message = exception.Message;
}

authenticationView.Initialize(exception);
OpenInternal(PopupViewType.AuthenticationView, completedAuthentication => {
authenticationView.ClearMessage();
authenticationView.ClearUsername();

if (completedAuthentication)
{
Logger.Trace("User completed validation opening view: {0}", popupViewType.ToString());
Expand All @@ -98,11 +71,6 @@ private void Open(PopupViewType popupViewType, Action<bool> onClose)
});

shouldCloseOnFinish = false;
authenticationView.SetMessage(message);
if (username != null)
{
authenticationView.SetUsername(username);
}
});
}
else
Expand All @@ -120,10 +88,7 @@ private void OpenInternal(PopupViewType popupViewType, Action<bool> onClose)
}

ActiveViewType = popupViewType;
titleContent = new GUIContent(ActiveView.Title, Styles.SmallLogo);
OnEnable();
Show();
Refresh();
}

public IApiClient Client
Expand Down