Esempio n. 1
0
        public async Task <User> Authenticate(AuthUser authUser)
        {
            return(await Task.Run(async() =>
            {
                // Thread.Sleep(1000);

                if (string.IsNullOrWhiteSpace(authUser.Login) || string.IsNullOrWhiteSpace(authUser.Password))
                {
                    throw new ArgumentException("Login or Password is empty");
                }

                byte[] encryptedPassword = System.Text.Encoding.ASCII.GetBytes(authUser.Password);
                encryptedPassword = new System.Security.Cryptography.SHA256Managed().ComputeHash(encryptedPassword);
                string hashPassword = System.Text.Encoding.ASCII.GetString(encryptedPassword);

                List <DBUser> users = await _storage.GetAllAsync();
                DBUser dbUser =
                    users.FirstOrDefault(user => user.Login == authUser.Login && user.Password == hashPassword);
                if (dbUser == null)
                {
                    throw new Exception("Wrong Login or Password");
                }

                return new User(dbUser.Guid, dbUser.Login, dbUser.FirstName, dbUser.LastName, dbUser.Email);
            }));
        }
Esempio n. 2
0
        public async Task <User> AuthenticateAsync(AuthenticationUser authUser)
        {
            if (String.IsNullOrWhiteSpace(authUser.Login) || String.IsNullOrWhiteSpace(authUser.Password))
            {
                throw new ArgumentException("Login or Password is Empty");
            }
            var users = await _storage.GetAllAsync(DBUser.FOLDER);

            var dbUser = users.FirstOrDefault(user => user.Login == authUser.Login && user.Password == Encrypt(authUser.Password, encryptingIndex));

            if (dbUser == null)
            {
                throw new Exception("Wrong Login or Password");
            }
            if ((dbUser.Login.Length < 2))
            {
                throw new ArgumentException("Login must consist at least of 2 symbols");
            }
            if ((dbUser.Password.Length < 3))
            {
                throw new ArgumentException("Password must consist at least of 3 symbols");
            }

            return(new User(dbUser.Guid, dbUser.FirstName, dbUser.LastName, dbUser.Login));
        }
        public async Task <User> AuthenticateAsync(UserAuth authUser)
        {
            if (String.IsNullOrWhiteSpace(authUser.Login) || String.IsNullOrWhiteSpace(authUser.Password))
            {
                throw new ArgumentException("Login or Password is Empty");
            }
            var users = await _storage.GetAllAsync();

            UserDb dbUser = null;

            try
            {
                dbUser = users.FirstOrDefault(user =>
                                              user.Login == authUser.Login &&
                                              Encryption.Decrypt(user.Password, authUser.Password) == authUser.Password);
                if (dbUser == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new UserException("Wrong Login or Password");
            }

            dbUser.Categories ??= new List <Category>();

            CurrentUser = new User(dbUser.Name, dbUser.Surname, dbUser.Email, dbUser.Guid, dbUser.Categories);
            return(CurrentUser);
        }
Esempio n. 4
0
        public async Task <User> AuthenticateAsync(AuthenticationUser authUser)
        {
            if (String.IsNullOrWhiteSpace(authUser.Login) || String.IsNullOrWhiteSpace(authUser.Password))
            {
                throw new ArgumentException("Login or Password is Empty");
            }
            var users = await _storage.GetAllAsync();

            var dbUser = users.FirstOrDefault(user => user.Login == authUser.Login && user.Password == authUser.Password);

            if (dbUser == null)
            {
                throw new Exception("Wrong Login or Password");
            }
            return(new User(dbUser.Guid, dbUser.FirstName, dbUser.LastName, dbUser.Email, dbUser.Login));
        }
Esempio n. 5
0
        public async Task <List <Wallet> > GetWallets()
        {
            return(await Task.Run(async() =>
            {
                // Thread.Sleep(1000);

                List <DBWallet> dbWallets = await _storage.GetAllAsync();
                List <Wallet> res = new List <Wallet>();

                foreach (var dbWallet in dbWallets)
                {
                    res.Add(new Wallet
                            (
                                dbWallet.Guid,
                                dbWallet.Name,
                                dbWallet.Description,
                                dbWallet.Currency,
                                dbWallet.InitialBalance,
                                dbWallet.OwnerGuid
                            ));
                }

                return res;
            }));
        }
Esempio n. 6
0
        public async Task <List <Transaction> > GetTransactions()
        {
            return(await Task.Run(async() =>
            {
                // Thread.Sleep(1000);

                List <DBTransaction> dbTransactions = (await _storage.GetAllAsync()).OrderBy(transaction => transaction.Date).ToList();
                List <Transaction> res = new List <Transaction>();

                foreach (var dbTransaction in dbTransactions)
                {
                    res.Add(new Transaction
                            (
                                dbTransaction.Guid,
                                dbTransaction.Sum,
                                dbTransaction.Currency,
                                dbTransaction.Category,
                                dbTransaction.Description,
                                dbTransaction.Date
                            ));
                }

                return res;
            }));
        }
Esempio n. 7
0
        public async Task GetWalletsAsync()
        {
            if (!_allServices.CategoryService.CategoriesLoaded)
            {
                await _allServices.CategoryService.GetCategoriesAsync();

                _allServices.CategoryService.CategoriesLoaded = true;
            }
            var dbWallets = await _storage.GetAllAsync(User.Id.ToString("N"));

            foreach (var dbWallet in dbWallets)
            {
                var wallet = new Wallet(User, dbWallet.Guid, dbWallet.Name, dbWallet.InitialBalance, dbWallet.CurrentBalance,
                                        dbWallet.MainCurrency, dbWallet.AvailabilityOfCategories);
                for (var i = 0; i < User.CategoriesAmount(); i++)
                {
                    if (dbWallet.AvailabilityOfCategories[i])
                    {
                        wallet.AmountOfAvailableCategories += 1;
                    }
                }
                _wallets.Add(wallet);
                User.MyWallets.Add(wallet);
            }
        }
Esempio n. 8
0
        public async Task GetCategoriesAsync()
        {
            var dbCategories = await _storage.GetAllAsync(User.Id.ToString("N"));

            foreach (var dbCategory in dbCategories)
            {
                var category = new Category(User, dbCategory.Name, dbCategory.Color, dbCategory.Icon, dbCategory.Guid);
                _categories.Add(category);
                User.AddCategory(category);
            }
        }
Esempio n. 9
0
        public async Task GetTransactionsAsync()
        {
            var dbTransactions = await _storage.GetAllAsync(Wallet.Id.ToString("N"));

            foreach (var dbTransaction in dbTransactions)
            {
                var transaction = new Transaction(Wallet, dbTransaction.Guid, dbTransaction.Sum, dbTransaction.Currency, dbTransaction.Date, Wallet.Owner.GetCategory(dbTransaction.Category));
                transaction.Description = dbTransaction.Description;
                _transactions.Add(transaction);
                Wallet.AddTransaction(transaction, Wallet.Owner.Id, true);
            }
        }
Esempio n. 10
0
        public async Task <User> Authenticate(AuthenticationUser authUser)
        {
            Thread.Sleep(2000);
            if (string.IsNullOrWhiteSpace(authUser.Login) || string.IsNullOrWhiteSpace(authUser.Password))
            {
                throw new ArgumentException("Blank login/password");
            }

            System.Collections.Generic.List <DBUser> dbUsers = await _storage.GetAllAsync();

            DBUser dbUser = dbUsers.FirstOrDefault(user => user.Login == authUser.Login && user.Password == Encrypt(authUser.Password));

            if (dbUser == null)
            {
                throw new Exception("Invalid login/password");
            }

            User curUser = new(dbUser);

            CurrentSession.User = curUser;
            return(curUser);
        }
Esempio n. 11
0
        public async Task <User> Authenticate(AuthenticationUser authUser)
        {
            Thread.Sleep(2000);
            if (string.IsNullOrWhiteSpace(authUser.Login) || string.IsNullOrWhiteSpace(authUser.Password))
            {
                throw new ArgumentException("Login or Password is empty");
            }

            var users = await Task.Run(() => _storage.GetAllAsync());

            var dbUser = users.FirstOrDefault(user =>
                                              user.Login == authUser.Login && user.Password == Encrypt(authUser.Password));

            if (dbUser == null)
            {
                throw new Exception("wrong login or password");
            }
            //Todo Call Method for user login or password validation and retrieve password from storage
            User curUser = new User(dbUser.Guid, dbUser.LastName, dbUser.FirstName, dbUser.Email, dbUser.Login);

            CurrentInformation.User = curUser;
            return(curUser);
        }
Esempio n. 12
0
        public List <Transaction> GetTransactions()
        {
            Task <List <Transaction> > transactions = Task.Run <List <Transaction> >(async() => await _storage.GetAllAsync());

            return(transactions.Result);
        }
        public async Task <List <DBTransaction> > GetAllTransactionsAsync()
        {
            var tr = await _storage.GetAllAsync();

            return(tr);
        }
Esempio n. 14
0
        public async Task <List <DBWallet> > GetAllWalletsAsync()
        {
            var wallets = await _storage.GetAllAsync();

            return(wallets);
        }
Esempio n. 15
0
        public List <Wallet> GetWallets()
        {
            Task <List <Wallet> > wallets = Task.Run <List <Wallet> >(async() => await _storage.GetAllAsync());

            return(wallets.Result);
        }
Esempio n. 16
0
        public List <Category> GetCategories()
        {
            Task <List <Category> > categories = Task.Run <List <Category> >(async() => await _storage.GetAllAsync());

            return(categories.Result);
        }