Example #1
0
        public IDoxSession CreateAuthenticatedSession(string defaultUserEmail)
        {
            var outlookWindow = new NativeWindow();
            try
            {
                outlookWindow.AssignHandle(FindWindowEx(IntPtr.Zero, IntPtr.Zero, "rctrl_renwnd32", null));
                _loginUi.NativeWindow = outlookWindow;
                _loginUi.LoginFieldEnabled = true;
                _loginUi.RegisterTabVisible = true;

                IAuthenticator authenticator = new Authenticator(_loginUi);
                authenticator.Api = new DoxApi(OptionApi.GetString("SendLinkServiceUrl"));
                string username = OptionApi.GetString("SendLinkCloudStorageLoginName");
                username = string.IsNullOrEmpty(username) ? defaultUserEmail : username;

                string deviceToken = OptionApi.GetEncrypted("SendLinkDeviceToken", _entropy);
                bool cancelled;
                var session = authenticator.Authenticate(username, deviceToken, out cancelled);
                if (cancelled)
                {
                    throw new AbortSendLinkException("User cancelled Sendlink", false);
                }
                return session;
            }
            finally
            {
                if (outlookWindow != null)
                {
                    // TFS 6777: Outlook 2010 + Interwoven EMM: On cancel, Mail Inspector "Send" button inoperable, outlook remains in memory.
                    outlookWindow.ReleaseHandle();
                }
            }
        }
Example #2
0
		public bool CheckCredentials(string cred, bool showUi)
		{
		    string serviceUrl = OptionApi.GetString("SendLinkServiceUrl");
			ILoginUserInteraction loginUi = new LoginUserInteraction()
				{
					LoginFieldEnabled = true,
					RegisterTabVisible = true
				};
			IAuthenticator authenticator = new Authenticator(loginUi)
				{
					Api = new DoxApi(serviceUrl)
				};

			string username = OptionApi.GetString("SendLinkCloudStorageLoginName");
            string deviceToken = OptionApi.GetEncrypted("SendLinkDeviceToken", _entropy);

		    try
			{
			    if (string.IsNullOrEmpty(username))
			    {
                    Logger.LogInfo("CheckCredentials - no login name available");
			        return false;
			    }

                // Account has been created but no device token as they haven't used any platform features.
			    if (string.IsNullOrEmpty(deviceToken) && (!string.IsNullOrEmpty(username)))
			    {
			        return IsProfessionalEnabled(serviceUrl, username);
			    }

			    IDoxSession session = authenticator.CheckCredentials(username, deviceToken);

			    if (session == null)
			    {
			        if (authenticator.Api.Error.IsConnectionError())
			        {
                        return IsSendLinkPlanEnabled();
			        }
			        if (showUi)
			        {
			            return Login(serviceUrl, authenticator, username, deviceToken);
			        }

			    }
                return ValidateSession(serviceUrl, session, username);
			}
			catch (StorageUnavailableException e)
			{
				// Offline
                Logger.LogError(e);
                // The server is not available allow the user to continue using if they have the business/enterprise plans
                // Otherwise when the trial license expires the product will only work when connected to the internet.
			    if (IsSendLinkPlanEnabled())
			    {
			        return true;
			    }
			}
			catch (Exception e)
			{
				// Some other error?
                Logger.LogError(e);
			}
		    return false;
		}