A game about forced loneliness, made by TACStudios
at master 184 lines 6.1 kB view raw
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEngine.UIElements; 4 5using Codice.Client.Common; 6using Codice.Client.Common.Authentication; 7using Codice.Client.Common.WebApi; 8using Codice.Client.Common.WebApi.Responses; 9using Codice.CM.Common; 10using PlasticGui; 11using PlasticGui.Configuration.CloudEdition.Welcome; 12using PlasticGui.Configuration.CloudEdition; 13using Unity.PlasticSCM.Editor.UI.UIElements; 14 15namespace Unity.PlasticSCM.Editor.Configuration.CloudEdition.Welcome 16{ 17 internal class SignInWithEmailPanel : VisualElement, GetCloudOrganizations.INotify 18 { 19 internal SignInWithEmailPanel( 20 IWelcomeWindowNotify notify, 21 IPlasticWebRestApi restApi) 22 { 23 mNotify = notify; 24 mRestApi = restApi; 25 26 InitializeLayoutAndStyles(); 27 28 BuildComponents(); 29 } 30 31 internal void Dispose() 32 { 33 mSignInButton.clicked -= SignInButton_Clicked; 34 mBackButton.clicked -= BackButton_Clicked; 35 mSignUpButton.clicked -= SignUpButton_Clicked; 36 } 37 38 void ShowSignUpNeeded() 39 { 40 mSignUpNeededNotificationContainer.Show(); 41 } 42 43 void HideSignUpNeeded() 44 { 45 mSignUpNeededNotificationContainer.Collapse(); 46 } 47 48 void GetCloudOrganizations.INotify.CloudOrganizationsRetrieved( 49 List<string> cloudServers) 50 { 51 mNotify.ProcessLoginResponseWithOrganizations(mCredentials, cloudServers); 52 } 53 54 void GetCloudOrganizations.INotify.Error( 55 ErrorResponse.ErrorFields error) 56 { 57 if (error.ErrorCode == ErrorCodes.UserNotFound) 58 { 59 ShowSignUpNeeded(); 60 return; 61 } 62 63 HideSignUpNeeded(); 64 ((IProgressControls)mProgressControls).ShowError(error.Message); 65 } 66 67 void CleanNotificationLabels() 68 { 69 mEmailNotificationLabel.text = string.Empty; 70 mPasswordNotificationLabel.text = string.Empty; 71 72 HideSignUpNeeded(); 73 } 74 75 void SignInButton_Clicked() 76 { 77 CleanNotificationLabels(); 78 79 ValidateEmailAndPassword.ValidationResult validationResult; 80 if (!ValidateEmailAndPassword.IsValid(mEmailField.text, mPasswordField.text, out validationResult)) 81 { 82 ShowValidationResult(validationResult); 83 return; 84 } 85 86 mCredentials = new Credentials( 87 new SEID(mEmailField.text, false, mPasswordField.text), 88 SEIDWorkingMode.LDAPWorkingMode); 89 90 GetCloudOrganizations.GetOrganizationsInThreadWaiter( 91 mCredentials.User.Data, 92 mCredentials.User.Password, 93 mProgressControls, 94 this, 95 mRestApi, 96 CmConnection.Get()); 97 } 98 99 void ShowValidationResult( 100 ValidateEmailAndPassword.ValidationResult validationResult) 101 { 102 if (validationResult.UserError != null) 103 { 104 mEmailNotificationLabel.text = validationResult.UserError; 105 } 106 107 if (validationResult.PasswordError != null) 108 { 109 mPasswordNotificationLabel.text = validationResult.PasswordError; 110 } 111 } 112 113 void BackButton_Clicked() 114 { 115 mNotify.Back(); 116 } 117 118 void InitializeLayoutAndStyles() 119 { 120 this.LoadLayout(typeof(SignInWithEmailPanel).Name); 121 this.LoadStyle(typeof(SignInWithEmailPanel).Name); 122 } 123 124 void SignUpButton_Clicked() 125 { 126 Application.OpenURL(UnityUrl.DevOps.GetSignUp()); 127 } 128 129 void BuildComponents() 130 { 131 mEmailField = this.Q<TextField>("email"); 132 mPasswordField = this.Q<TextField>("password"); 133 mEmailNotificationLabel = this.Q<Label>("emailNotification"); 134 mPasswordNotificationLabel = this.Q<Label>("passwordNotification"); 135 mSignInButton = this.Q<Button>("signIn"); 136 mBackButton = this.Q<Button>("back"); 137 mSignUpButton = this.Q<Button>("signUpButton"); 138 mProgressContainer = this.Q<VisualElement>("progressContainer"); 139 mSignUpNeededNotificationContainer = this.Q<VisualElement>("signUpNeededNotificationContainer"); 140 141 mSignInButton.clicked += SignInButton_Clicked; 142 mBackButton.clicked += BackButton_Clicked; 143 mSignUpButton.clicked += SignUpButton_Clicked; 144 mEmailField.FocusOnceLoaded(); 145 146 mProgressControls = new ProgressControlsForDialogs(new VisualElement[] { mSignInButton }); 147 mProgressContainer.Add((VisualElement)mProgressControls); 148 149 this.SetControlText<Label>("signInLabel", 150 PlasticLocalization.Name.SignInWithEmail); 151 this.SetControlLabel<TextField>("email", 152 PlasticLocalization.Name.Email); 153 this.SetControlLabel<TextField>("password", 154 PlasticLocalization.Name.Password); 155 this.SetControlText<Button>("signIn", 156 PlasticLocalization.Name.SignIn); 157 this.SetControlText<Button>("back", 158 PlasticLocalization.Name.BackButton); 159 this.SetControlText<Label>("signUpNeededNotificationLabel", 160 PlasticLocalization.Name.SignUpNeededNoArgs); 161 this.SetControlText<Button>("signUpButton", 162 PlasticLocalization.Name.SignUp); 163 } 164 165 TextField mEmailField; 166 TextField mPasswordField; 167 168 Label mEmailNotificationLabel; 169 Label mPasswordNotificationLabel; 170 171 Button mSignInButton; 172 Button mBackButton; 173 Button mSignUpButton; 174 175 VisualElement mProgressContainer; 176 VisualElement mSignUpNeededNotificationContainer; 177 178 Credentials mCredentials; 179 ProgressControlsForDialogs mProgressControls; 180 181 readonly IWelcomeWindowNotify mNotify; 182 readonly IPlasticWebRestApi mRestApi; 183 } 184}