Пример #1
0
        /// <summary>
        /// Method that creates a new user in the system via the api by using the properties
        /// </summary>
        public async void CreateUser()
        {
            if (CheckTextFields())
            {
                if (!string.IsNullOrEmpty(UserName) && Password != "********")
                {
                    _tempUser = new User(Name, Email, Telephone, Address, SelectedRole.Id, TajNumber, TaxNumber, WorkingHours, SelectedUserLevel.Id, SelectedStore.ID);
                    User postedUser = await APIHandler <User> .PostOne("Users", _tempUser);

                    if (postedUser.Id != -1)
                    {
                        Salary salary       = new Salary(postedUser.Id, Salary, (SalaryWTax / Salary) * 100);
                        Salary postedSalary = await APIHandler <Salary> .PostOne("Salaries", salary);

                        string encryptedPassword = AuthHandler.EncryptPassword(Password, Salt);
                        Auth   posteAuth         = await APIHandler <Auth> .PostOne("Auth/PostAuth", new Auth(UserName, encryptedPassword, Salt, postedUser.Id));

                        NavigationHandler.NavigateToPage(typeof(EmployeesPage));
                        VMHandler.EmployeesPageVm.FeedBackText = $"The user {postedUser.Name} \nwas created successfully";
                    }
                    else
                    {
                        ErrorText = "The provided email is in use,\nplease specify a different one.";
                    }
                }
                else
                {
                    ErrorText = "A password and username\nmust be generated before\nconfirming.";
                }
            }
            else
            {
                ErrorText = "All text fields must be filled\nand all selections must be\nmade.";
            }
        }
Пример #2
0
        /// <summary>
        /// Attempts to login using information from properties.
        /// </summary>
        public async void AttemptLogin()
        {
            DisplayLoginWindow = false;
            DisplayLoading     = true;
            OnPropertyChanged(nameof(DisplayLoginWindow));
            OnPropertyChanged(nameof(DisplayLoading));
            string passwordSalt = await APIHandler <string> .GetOne($"Auth/GetSalt/{Username}");

            if (passwordSalt != null)
            {
                (int UserID, string SessionKey)sessionTuple =
                    await APIHandler <(int UserID, string SessionKey)> .GetOne($"Auth/Login/{Username}/{AuthHandler.EncryptPassword(Password, passwordSalt)}");

                if (sessionTuple != default)
                {
                    AuthHandler.UserID     = sessionTuple.UserID;
                    AuthHandler.SessionKey = sessionTuple.SessionKey;
                    await AuthHandler.InitializeAuth();

                    Frame mainFrame = Window.Current.Content as Frame;
                    mainFrame?.Navigate(Type.GetType($"{Application.Current.GetType().Namespace}.MainPage"));
                }
                else
                {
                    DisplayLoginError(Constants.LOGIN_ERROR);
                }
            }
            else
            {
                DisplayLoginError(Constants.LOGIN_ERROR);
            }
        }