SignInWithEmailPanel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System.Collections.Generic;
  2. using Unity.PlasticSCM.Editor.UI.UIElements;
  3. using UnityEngine.UIElements;
  4. using PlasticGui;
  5. using PlasticGui.Configuration.CloudEdition.Welcome;
  6. using PlasticGui.Configuration.CloudEdition;
  7. using PlasticGui.WebApi;
  8. namespace Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome
  9. {
  10. internal class SignInWithEmailPanel :
  11. VisualElement,
  12. Login.INotify
  13. {
  14. internal SignInWithEmailPanel(
  15. CloudEditionWelcomeWindow parentWindow,
  16. IWelcomeWindowNotify notify,
  17. IPlasticWebRestApi restApi)
  18. {
  19. mParentWindow = parentWindow;
  20. mNotify = notify;
  21. mRestApi = restApi;
  22. InitializeLayoutAndStyles();
  23. BuildComponents();
  24. }
  25. internal void Dispose()
  26. {
  27. mSignInButton.clicked -= SignInButton_Clicked;
  28. mBackButton.clicked -= BackButton_Clicked;
  29. }
  30. void SignInButton_Clicked()
  31. {
  32. CleanNotificationLabels();
  33. Login.Run(
  34. mRestApi,
  35. new SaveCloudEditionCreds(),
  36. mEmailField.text,
  37. mPasswordField.text,
  38. string.Empty,
  39. Login.Mode.Configure,
  40. mProgressControls,
  41. this);
  42. }
  43. void BackButton_Clicked()
  44. {
  45. mNotify.Back();
  46. }
  47. void Login.INotify.SuccessForConfigure(
  48. List<string> organizations,
  49. bool canCreateAnOrganization)
  50. {
  51. mNotify.SuccessForConfigure(
  52. organizations,
  53. canCreateAnOrganization);
  54. }
  55. void Login.INotify.SuccessForSSO(
  56. string organization)
  57. {
  58. mNotify.SuccessForSSO(organization);
  59. }
  60. void Login.INotify.SuccessForProfile(
  61. string userName)
  62. {
  63. mNotify.SuccessForProfile(userName);
  64. }
  65. void Login.INotify.SuccessForCredentials(string userName, string password)
  66. {
  67. mNotify.SuccessForCredentials(userName, password);
  68. }
  69. void Login.INotify.ValidationFailed(
  70. Login.ValidationResult validationResult)
  71. {
  72. if (validationResult.UserError != null)
  73. {
  74. mEmailNotificationLabel.text = validationResult.UserError;
  75. }
  76. if (validationResult.PasswordError != null)
  77. {
  78. mPasswordNotificationLabel.text = validationResult.PasswordError;
  79. }
  80. }
  81. void Login.INotify.SignUpNeeded(
  82. Login.Data loginData)
  83. {
  84. mNotify.SignUpNeeded(loginData.User, loginData.ClearPassword);
  85. }
  86. void Login.INotify.Error(
  87. string message)
  88. {
  89. mProgressControls.ShowError(message);
  90. }
  91. void CleanNotificationLabels()
  92. {
  93. mEmailNotificationLabel.text = string.Empty;
  94. mPasswordNotificationLabel.text = string.Empty;
  95. }
  96. void BuildComponents()
  97. {
  98. mEmailField = this.Q<TextField>("email");
  99. mPasswordField = this.Q<TextField>("password");
  100. mEmailNotificationLabel = this.Q<Label>("emailNotification");
  101. mPasswordNotificationLabel = this.Q<Label>("passwordNotification");
  102. mSignInButton = this.Q<Button>("signIn");
  103. mBackButton = this.Q<Button>("back");
  104. mProgressContainer = this.Q<VisualElement>("progressContainer");
  105. mSignInButton.clicked += SignInButton_Clicked;
  106. mBackButton.clicked += BackButton_Clicked;
  107. mEmailField.FocusOnceLoaded();
  108. mProgressControls = new ProgressControlsForDialogs(new VisualElement[] { mSignInButton });
  109. mProgressContainer.Add((VisualElement)mProgressControls);
  110. this.SetControlText<Label>("signInLabel",
  111. PlasticLocalization.Name.SignInWithEmail);
  112. this.SetControlLabel<TextField>("email",
  113. PlasticLocalization.Name.Email);
  114. this.SetControlLabel<TextField>("password",
  115. PlasticLocalization.Name.Password);
  116. this.SetControlText<Button>("signIn",
  117. PlasticLocalization.Name.SignIn);
  118. this.SetControlText<Button>("back",
  119. PlasticLocalization.Name.BackButton);
  120. }
  121. void InitializeLayoutAndStyles()
  122. {
  123. this.LoadLayout(typeof(SignInWithEmailPanel).Name);
  124. this.LoadStyle("SignInSignUp");
  125. this.LoadStyle(typeof(SignInWithEmailPanel).Name);
  126. }
  127. TextField mEmailField;
  128. TextField mPasswordField;
  129. Label mEmailNotificationLabel;
  130. Label mPasswordNotificationLabel;
  131. Button mSignInButton;
  132. Button mBackButton;
  133. VisualElement mProgressContainer;
  134. IProgressControls mProgressControls;
  135. readonly CloudEditionWelcomeWindow mParentWindow;
  136. readonly IWelcomeWindowNotify mNotify;
  137. readonly IPlasticWebRestApi mRestApi;
  138. }
  139. }