internal static CRegistationResult RegisterPerson(String name, String username, String email, SecureString securePassword, SecureString securePasswordConfirmation)
        {
            CRegistationResult result               = new CRegistationResult();
            String             password             = securePassword.ConvertToUnsecureString();
            String             passwordConfirmation = securePasswordConfirmation.ConvertToUnsecureString();

            result.IsEmailValidated    = IsMailValid(email);
            result.IsPasswordValidated = IsPasswordValid(password);
            result.IsPasswordConfirmed = password.Equals(passwordConfirmation);
            if (!result.IsEmailValidated || !result.IsPasswordValidated || !result.IsPasswordConfirmed)
            {
                result.IsRegistered = false;
                return(result);
            }

            CDataSupplierProxy dataSupplier = new CDataSupplierProxy();

            result.IsUsernameFree = !dataSupplier.IsUsernameExisted(username);
            result.IsEmailFree    = !dataSupplier.IsEmailExisted(email);
            if (!result.IsUsernameFree || !result.IsEmailFree)
            {
                result.IsRegistered = false;
                return(result);
            }

            CDataRecorderProxy dataRecorder = new CDataRecorderProxy();
            String             salt         = GenerateRandomString(10);
            String             passwordHash = CalculateHash(SaltPassword(password, salt));

            try
            {
                dataRecorder.RegisterPerson(name, username, email, salt, passwordHash);
            }
            //TODO: Find what exception throw when added new entity with existed primary Key or unique field dublicate
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to register person in CSLoginServis. Message: {0}", ex.Message);
                result.IsRegistered = false;
                return(result);
            }

            CLoginVerificationResult verRes = VerifyPassword(username, securePassword);

            if (verRes.IsVerified)
            {
                result.Token        = verRes.Token;
                result.IsRegistered = true;
            }
            else
            {
                result.IsRegistered = false;
            }

            return(result);
        }
Exemple #2
0
        public Boolean CreateFamily(String token, String familyName, Int32 budget)
        {
            try
            {
                log.Trace("Entered CreateFamily");

                Int32 personId;
                if (IsTokenBad(token, out personId))
                {
                    log.Info("Token is invalid. Can't create family. Token: {0}", token);
                    return(false);
                }

                IDataRecorder recorder = new CDataRecorderProxy();
                return(recorder.CreateFamily(personId, familyName, budget));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure in CBllFacadeForUI.CreateFamily. Message: {0}", ex.Message);
                return(false);
            }
        }
Exemple #3
0
        public Boolean DeleteSubCategory(String token, Int32 subCategoryId)
        {
            try
            {
                log.Trace("Entered DeleteSubCategory");

                Int32 personId;
                if (IsTokenBad(token, out personId))
                {
                    log.Info("Token is invalid. Can't delete subCategory (id = {1}). Token: {0}", token, subCategoryId);
                    return(false);
                }

                IDataRecorder recorder = new CDataRecorderProxy();
                return(recorder.DeleteSubCategory(personId, subCategoryId));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure in CBllFacadeForUI.DeleteSubCategory (subCategoryId = {1}). Message: {0}", ex.Message, subCategoryId);
                return(false);
            }
        }
Exemple #4
0
        public Int32 AddSubCategory(String token, String categoryTitle, String subCategoryTitle, String subCategoryDescription)
        {
            try
            {
                log.Trace("Entered AddSubCategory");

                Int32 personId;
                if (IsTokenBad(token, out personId))
                {
                    log.Info("Token is invalid. Can't add Payment. Token: {0}", token);
                    return(0);
                }

                IDataRecorder recorder = new CDataRecorderProxy();
                return(recorder.AddSubCategory(personId, categoryTitle, subCategoryTitle, subCategoryDescription));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure in CBllFacadeForUI.AddSubCategory (categoryTitle = {1}, subCategoryTitle = {2}, subCategoryDescription = {3}). Message: {0}",
                          ex.Message, categoryTitle, subCategoryTitle, subCategoryDescription);
                return(0);
            }
        }
Exemple #5
0
        public Int32 AddPayment(String token, DateTime date, String category, String subCategory, Decimal spended)
        {
            try
            {
                log.Trace("Entered AddPayment");

                Int32 personId;
                if (IsTokenBad(token, out personId))
                {
                    log.Info("Token is invalid. Can't add Payment. Token: {0}", token);
                    return(0);
                }

                IDataRecorder recorder = new CDataRecorderProxy();
                return(recorder.AddPayment(personId, date, category, subCategory, spended));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure in CBllFacadeForUI.AddPayment (date = {1}, category = {2}, subCategory = {3}, sum = {4}). Message: {0}",
                          ex.Message, date, category, subCategory, spended);
                return(0);
            }
        }
Exemple #6
0
        public Boolean EditSubCategory(String token, Int32 subCategoryId, String newCategoryTitle, String newSubCategoryTitle, String newSubCategoryDescription)
        {
            try
            {
                log.Trace("Entered EditSubCategory");

                Int32 personId;
                if (IsTokenBad(token, out personId))
                {
                    log.Info("Token is invalid. Can't edit subCategory (id = {1}). Token: {0}", token, subCategoryId);
                    return(false);
                }

                IDataRecorder recorder = new CDataRecorderProxy();
                return(recorder.EditSubCategory(personId, subCategoryId, newCategoryTitle, newSubCategoryTitle, newSubCategoryDescription));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure in CBllFacadeForUI.EditSubCategory " +
                          "(subCategoryId = {1}, newCategoryTitle = {2}, newSubCategoryTitle = {3}, newSubCategoryDescription = {4}). Message: {0}",
                          ex.Message, subCategoryId, newCategoryTitle, newSubCategoryTitle, newSubCategoryDescription);
                return(false);
            }
        }
Exemple #7
0
        public Boolean EditPayment(String token, Int32 paymentId, DateTime newDate, String newCategoryTitle, String newSubCategoryTitle, Decimal newSum)
        {
            try
            {
                log.Trace("Entered EditPayment");

                Int32 personId;
                if (IsTokenBad(token, out personId))
                {
                    log.Info("Token is invalid. Can't edit Payment (id = {1}). Token: {0}", token, paymentId);
                    return(false);
                }

                IDataRecorder recorder = new CDataRecorderProxy();
                return(recorder.EditPayment(personId, paymentId, newDate, newCategoryTitle, newSubCategoryTitle, newSum));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure in CBllFacadeForUI.EditPayment " +
                          "(paymentId = {1}, newDate = {2}, newCategory = {3}, newSubCategory = {4} newSum = {5}). Message: {0}",
                          ex.Message, paymentId, newDate, newCategoryTitle, newSubCategoryTitle, newSum);
                return(false);
            }
        }