async Task <bool> ActivateAccount()
        {
            ErrorMessage        = "";
            ShowActivationError = false;

            try
            {
                ShowBusy = true;
                var response = await AltiumDbApi.ActivateAccount(new AccountActivation { Username = this.Username, Password = this.Password, Code = this.ActivationCode });

                ShowBusy = false;

                if (response.Success)
                {
                    ShowActivationBox = false;
                    RegisterUser      = false;
                }
                else
                {
                    ErrorMessage        = response.Message;
                    ShowActivationError = true;
                    return(false);
                }
            }
            catch (Exception err)
            {
                ShowBusy            = false;
                ErrorMessage        = err.InnerException.Message;
                ShowActivationError = true;
                return(false);
            }

            return(await DoLogin());
        }
        async Task <bool> DoLogin()
        {
            ErrorMessage   = "";
            ShowLoginError = false;

            if (String.IsNullOrEmpty(Username) ||
                String.IsNullOrEmpty(Password))
            {
                ErrorMessage   = "You need to enter a username and password.";
                ShowLoginError = true;
                return(false);
            }

            ShowBusy = true;
            try
            {
                var response = await AltiumDbApi.Login(Username, Password);

                ShowBusy = false;

                if (!string.IsNullOrEmpty(response.error))
                {
                    ErrorMessage   = response.error_description;
                    ShowLoginError = true;
                    return(false);
                }
            }
            catch (Exception err)
            {
                ShowBusy       = false;
                ErrorMessage   = err.InnerException.Message;
                ShowLoginError = true;
            }

            ShowBusy = true;
            try
            {
                var active = await AltiumDbApi.CheckAccountActivated();

                ShowBusy = false;

                if (!active.Success)
                {
                    ErrorMessage   = active.Message;
                    ShowLoginError = true;
                }
            }
            catch (Exception err)
            {
                ShowBusy       = false;
                ErrorMessage   = err.InnerException.Message;
                ShowLoginError = true;
            }

            UserIsLoggedIn = true;

            return(true);
        }
Esempio n. 3
0
        public async Task CheckFirewallStatusAsync(Object stateInfo)
        {
            if (!UserIsLoggedIn)
            {
                return;
            }

            FirewallRuleOk = (await AltiumDbApi.CheckFirewallRule()).Success;
        }
Esempio n. 4
0
        public async Task UpdateFirewall()
        {
            UpdatingFirewallRule = true;

            await AltiumDbApi.UpdateFirewallRule();

            await CheckFirewallStatusAsync(null);

            UpdatingFirewallRule = false;
        }
        async Task <bool> ResendToken()
        {
            ErrorMessage    = "";
            ShowResendError = false;

            ShowBusy = true;
            try
            {
                var response = await AltiumDbApi.ResendActivationEmail(EmailAddress);

                ShowBusy = false;

                if (!response.Success)
                {
                    ErrorMessage    = response.Message;
                    ShowResendError = true;
                }
                else
                {
                    ShowResendToken = false;

                    ActivationCode        = "";
                    ActivationMessage     = "Please activate with the code you were emailed - it may take a few minutes to arrive.";
                    ShowActivationMessage = true;
                    ShowActivationBox     = true;
                }

                return(response.Success);
            }
            catch (Exception err)
            {
                ShowBusy        = false;
                ErrorMessage    = err.InnerException.Message;
                ShowResendError = true;
            }

            return(false);
        }
        //todo: this view model is getting pretty big and ugly now. Split out to register, login, auth, resend.

        public LoginRegisterViewModel()
        {
            username                = "";
            password                = "";
            passwordConfirm         = "";
            emailAddress            = "";
            verificationCode        = "";
            registerUser            = true;
            showActivationCodeEntry = false;
            errorMessage            = "";
            boxTitleText            = "Registration is FREE";
            displayText             = "Register";
            ShowAltiumPathError     = false;
            AltiumPath              = "";
            AltiumPathError         = "";
            databaseUse             = UserType.Professional;
            firstName               = "";
            LastName                = "";
            showCompanyField        = true;
            Company               = "";
            allowEmail            = true;
            ShowActivationBox     = false;
            ActivationCode        = "";
            ShowActivationMessage = false;
            ShowBusy              = false;
            ShowResendToken       = false;
            UserIsLoggedIn        = false; //= false;

            try
            {
                var stats = AltiumDbApi.GetDatabaseStats();
                componentCount = stats.ComponentCount;
                footprintCount = stats.FootprintCount;
            }
            catch // (Exception err)
            {
                // todo: network issue?
            }

            ActivateAccountCommand = new AwaitableDelegateCommand(ActivateAccount, ActivateAccountButtonEnabled);
            RegisterLoginCommand   = new AwaitableDelegateCommand(RegisterLogin, RegisterLoginButtonEnabled);
            ResendTokenCommand     = new AwaitableDelegateCommand(ResendToken, ResendButtonEnabled);

            SwitchBetweenRegisterLoginCommand = new DelegateCommand(() => { RegisterUser = !RegisterUser; ShowLoginError = false; });

            ShowResendTokenCommand = new DelegateCommand(() => { ShowResendToken = !ShowResendToken; ShowActivationError = false; ShowActivationMessage = false; ShowActivationBox = !ShowActivationBox; });

            ShowVerificationCommand = new DelegateCommand(() => { ShowActivationBox = !ShowActivationBox; ShowActivationError = false; });

            ViewGithubCommand = new DelegateCommand(() => System.Diagnostics.Process.Start("https://github.com/issus/altium-library"));

            AltiumBrowseCommand = new DelegateCommand(BrowseForAltiumDirectory);


            if (!String.IsNullOrEmpty(Properties.Settings.Default.Username))
            {
                Username     = Properties.Settings.Default.Username;
                RegisterUser = false;
            }

            if (!String.IsNullOrEmpty(Properties.Settings.Default.AccessToken))
            {
                try
                {
                    UserIsLoggedIn = AltiumDbApi.CheckTokenValid();
                }
                catch { } // will throw an exception if the token is invalid
            }
        }
        async Task <bool> DoRegistration()
        {
            ActivationMessage = "";
            ErrorMessage      = "";
            ShowLoginError    = false;

            if (!CheckEmailAddressValid(EmailAddress))
            {
                ShowLoginError = true;
                ErrorMessage   = "You need to enter a valid email address.";
                return(false);
            }

            if (Password.Length < 10)
            {
                ShowLoginError = true;
                ErrorMessage   = "Password must be at least 10 characters.";
                return(false);
            }

            if (Password.Contains("\""))
            {
                ShowLoginError = true;
                ErrorMessage   = "Password cannot contain a \".";
                return(false);
            }

            UserRegistrationRequest user = new UserRegistrationRequest();

            user.AllowEmail      = AllowEmail;
            user.Username        = Username;
            user.Password        = Password;
            user.ConfirmPassword = PasswordConfirm;
            user.FirstName       = FirstName;
            user.LastName        = LastName;
            user.Company         = Company;
            user.Email           = EmailAddress;
            user.Password        = Password;
            user.UserType        = databaseUse;

            ShowBusy = true;
            try
            {
                var resp = await AltiumDbApi.AccountRegister(user);

                ShowBusy = false;

                if (resp.Success)
                {
                    ActivationCode        = "";
                    ActivationMessage     = "Registration complete. Please activate with the code you were emailed - it may take a few minutes to arrive.";
                    ShowActivationMessage = true;
                    ShowActivationBox     = true;
                }
                else
                {
                    ShowLoginError = true;
                    ErrorMessage   = resp.Message;
                    return(false);
                }
            }
            catch (Exception err)
            {
                ShowBusy = false;

                ShowLoginError = true;
                ErrorMessage   = err.InnerException.Message;
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        void UserHasLoggedIn()
        {
            CheckFirewallStatus(null);

            UsersName = AltiumDbApi.GetUsersName();
        }