public void MakeTransfer()
        {
            // amount to deposit to 1st user account
            decimal amt = 5000;
            // string note = "withdraw money";
            // regsiter 1st user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // Deposit Money into 1st user acount
            account.MakeDeposit(account.AccountNumber, amt, Note, account.AccountType);
            // 1st user account balance
            var balance = account.Balance;

            // 2nd user details.
            string email2    = "*****@*****.**";
            string name2     = "john";
            string password2 = "12345";
            int    acctype2  = 0;
            //Register 2nd user and return 2nd user account
            AccountClass account2 = AuthClass.Register(name2, email2, password2, acctype2);
            // amount to tranfer
            decimal amtTransfer = 1000;

            // Transfer money from 1st to 2nd account
            account.MakeTransfer(account.AccountNumber, amtTransfer, Note, account.AccountType, account2);

            // Assert for transfer
            Assert.That(account.Balance, Is.EqualTo(balance - amtTransfer));
        }
        public List <Accountcycle> query(int lastmonth, int aftermonth)
        {
            AuthClass  authClass  = new AuthClass();
            HttpClient httpClient = AppConfig.GetInstance().crateHttpClient();

            String url = AppConfig.GetInstance().BaseUrl + "/accountcycle?lastmonth=" + lastmonth + "&aftermonth=" + aftermonth;
            HttpResponseMessage response = httpClient.GetAsync(url).Result;
            String result = response.Content.ReadAsStringAsync().Result;

            httpClient.Dispose();

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("查询客户信息错误." + response.RequestMessage.ToString());
            }

            List <Accountcycle> accountcycleList = new List <Accountcycle>();

            JArray ja = JArray.Parse(result);

            foreach (var item in ja)
            {
                Accountcycle accountcycle = new Accountcycle(item.Value <JObject>());
                accountcycleList.Add(accountcycle);
            }

            return(accountcycleList);
        }
        /// <summary>
        /// Обработка события при нажатии на кнопку входа.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_login_system_Click(object sender, EventArgs e)
        {
            bool status;
            Tuple <bool, List <string> > returned;

            try
            {
                if (ValidationField.ValidationFields(fields))
                {
                    TextBoxFiledsBlocked.Add(field_system_login);
                    TextBoxFiledsBlocked.Add(field_system_password);

                    StatusUserUI.StatusFunctionalityPartsOfTheWindow(TextBoxFiledsBlocked);
                    AuthClass userAuth = new AuthClass(field_system_login.Text, field_system_password.Text);
                    returned = userAuth.LogIn();
                    status   = returned.Item1;
                    userData = returned.Item2;
                    if (!status)
                    {
                        StatusUserUI.StatusFunctionalityPartsOfTheWindow(TextBoxFiledsBlocked);
                    }
                    else
                    {
                        this.Hide();
                        StatusUserUI.StatusFunctionalityPartsOfTheWindow(setAllControlsEnabled(controlsInForm));
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, exp.StackTrace);
            }
        }
        public void MakeTransferFail()
        {
            decimal amt = 5000;
            // string note = "withdraw money";
            // regsiter 1st user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // Deposit Money into 1st user acount
            account.MakeDeposit(account.AccountNumber, amt, Note, account.AccountType);
            // 1st user account balance
            var balance = account.Balance;

            // 2nd user details.
            string email2    = "*****@*****.**";
            string name2     = "john";
            string password2 = "12345";
            int    acctype2  = 0;
            //Register 2nd user and return 2nd user account
            AccountClass account2 = AuthClass.Register(name2, email2, password2, acctype2);
            // amount to tranfer
            decimal amtTransfer = 10000;


            // test for transfer

            Assert.That(
                () => account.MakeTransfer(account.AccountNumber, amtTransfer, Note, account.AccountType, account2),
                Throws.TypeOf <System.ArgumentOutOfRangeException>()
                );
        }
        public void Register()
        {
            //user account is null
            AccountClass account = null;

            //Register user and return user account
            account = AuthClass.Register(Name, Email, Password, Acctype);

            // test if account was registered
            Assert.That(account, Is.Not.Null);
        }
        public void RegisterFail()
        {
            //user account is null
            AccountClass account = null;

            // make user empty
            Name = "";

            //Register user and return user account
            account = AuthClass.Register(Name, Email, Password, Acctype);

            Assert.That(account, Is.Null);
        }
        public void LoginFail()
        {
            //assign login variables
            Email    = "*****@*****.**";
            Password = "******";
            AccountClass loginAcct = null;

            //login user
            loginAcct = AuthClass.Login(Email, Password);

            // test if login returns user
            Assert.That(loginAcct, Is.Null);
        }
        public void Login()
        {
            // make login Null
            AccountClass loginAcct = null;

            //register  new user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            //login user
            loginAcct = AuthClass.Login(Email, Password);

            // test if login returns user
            Assert.That(loginAcct, Is.Not.Null);
        }
        public void MakeDepositFail()
        {
            // amount to deposit
            decimal amtDeposit = -5000;
            // register user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // deposit money to user account  Act & Assert

            Assert.That(
                () => account.MakeDeposit(account.AccountNumber, amtDeposit, Note, account.AccountType),
                Throws.TypeOf <System.ArgumentOutOfRangeException>()
                );
        }
Exemple #10
0
        public async Task <Users> Register(Users user, string password)
        {
            byte[]    passwordHash;
            byte[]    passwordSalt;
            AuthClass objAuth = new AuthClass();

            objAuth.CreatePasswordHash(password, out passwordHash, out passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            await _dbContext.Users.AddAsync(user);

            await _dbContext.SaveChangesAsync();

            return(user);
        }
Exemple #11
0
        public IActionResult RequestToken([FromBody] Userinfo userinfo)
        {
            Users Entity = AuthClass.CheckCredentials(userinfo.Login, userinfo.Password);

            if (Entity == null)
            {
                return(BadRequest("Credenciales Invalidas"));
            }

            if (!string.IsNullOrEmpty(Entity.Username))
            {
                return(Ok(AuthClass.GenerateToken(Entity.Username)));
            }

            return(BadRequest("Could not verify username and password"));
        }
        public void TransactionsFail()
        {
            // amount to deposit
            decimal amtDeposit = -5000;

            // number of trasactions
            int count = BankdatasClass.Transactions.Count;
            // register user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // deposit money into account
            Assert.That(
                () => account.MakeDeposit(account.AccountNumber, amtDeposit, Note, account.AccountType),
                Throws.TypeOf <System.ArgumentOutOfRangeException>()
                );
        }
        public void Transactions()
        {
            // amount to deposit
            decimal amtDeposit = 5000;
            // number of trasactions
            int count = BankdatasClass.Transactions.Count;
            // register user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // deposit money into account
            account.MakeDeposit(account.AccountNumber, amtDeposit, Note, account.AccountType);
            // new count
            int newCount = BankdatasClass.Transactions.Count;
            int expected = count + 1;

            Assert.That(newCount, Is.EqualTo(expected));
        }
        public void MakeDeposit()
        {
            // amt to deposit
            decimal amtDeposit = 5000;

            // register user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);
            // user account balance
            var balance = account.Balance;

            // deposit money to user account
            account.MakeDeposit(account.AccountNumber, amtDeposit, Note, account.AccountType);

            // Expected amount
            decimal expectedAmt = balance + amtDeposit;

            // test account for increment by amount deposited
            Assert.That(account.Balance, Is.EqualTo(expectedAmt));
        }
        public void MakeWithdrawalFail()
        {
            // amount to deposit
            decimal amtDeposit = 500;
            // register user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // deposit money into account
            account.MakeDeposit(account.AccountNumber, amtDeposit, Note, account.AccountType);
            // user account balance
            var balance = account.Balance;
            // amount to withdraw from account
            decimal amtWithdraw = 1000;

            // withdraw from user account
            Assert.That(
                () => account.MakeWithdrawal(account.AccountNumber, amtWithdraw, Note, account.AccountType),
                Throws.TypeOf <System.ArgumentOutOfRangeException>()
                );
        }
Exemple #16
0
        public async Task <Users> Login(string username, string password)
        {
            var user = await _dbContext.Users
                       .Include(p => p.Photos)
                       .FirstOrDefaultAsync(x => x.UserName == username);

            if (user == null)
            {
                return(null);
            }

            AuthClass objAuth = new AuthClass();

            if (!objAuth.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                return(null);
            }

            return(user);
        }
Exemple #17
0
        private void login(String userNo, String password)
        {
            if (userNo == null || userNo == "")
            {
                MessageBox.Show("请输入用户编号");
                return;
            }


            AuthClass authClass = new AuthClass();

            if (authClass.checkIn(userNo, password))
            {
                //登录成功
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                //MessageBox.Show("用户名或密码错误。");
            }
        }
        public void MakeWithdrawal()
        {
            // amount to deposit
            decimal amtDeposit = 5000;
            string  note       = "withdraw money";
            // register user
            AccountClass account = AuthClass.Register(Name, Email, Password, Acctype);

            // deposit money into account
            account.MakeDeposit(account.AccountNumber, amtDeposit, note, account.AccountType);
            // user account balance
            var balance = account.Balance;
            // amount to withdraw from account
            decimal amtWithdraw = 1000;

            // withdraw from user account
            account.MakeWithdrawal(account.AccountNumber, amtWithdraw, note, account.AccountType);
            // expected Amount
            decimal expectedAmt = balance - amtWithdraw;

            // test user account for decrement by the amount withdraw
            Assert.That(account.Balance, Is.EqualTo(expectedAmt));
        }
Exemple #19
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     AuthClass.Logoff();
     _eventAggregator.GetEvent <ShowAlertEvent>().Subscribe(ShowAlert);
 }
Exemple #20
0
        static void Main(string[] args)
        {
            AccountClass account = null;
            string       option  = "";

            while (option != "1" || option != "2")
            {
                Console.WriteLine("Welcome TO decagon Bank ");
                Console.WriteLine("To login press 1 ");
                Console.WriteLine("To Register press 2 ");

                option = Console.ReadLine();

                if (option == "1")
                {
                    string email    = "";
                    string password = "";


                    while (string.IsNullOrWhiteSpace(email) ||
                           string.IsNullOrWhiteSpace(password))
                    {
                        try
                        {
                            // collect inputs
                            Console.WriteLine("Enter your email");
                            email = Console.ReadLine();
                            Console.WriteLine("Enter your password");
                            password = Console.ReadLine();
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("\nInvalid operation");
                        }
                    }


                    account = AuthClass.Login(email, password);
                    if (account == null)
                    {
                        Console.WriteLine("Invalid User");
                        Environment.Exit(0);
                    }
                }
                else if (option == "2")
                {
                    string name     = "";
                    string email    = "";
                    string password = "";
                    int    acctype  = 0;


                    while (string.IsNullOrWhiteSpace(name) ||
                           string.IsNullOrWhiteSpace(email) ||
                           string.IsNullOrWhiteSpace(password))
                    {
                        try
                        {
                            // collect inputs
                            System.Console.WriteLine("All fields are required");
                            Console.WriteLine("Enter your name");
                            name = Console.ReadLine();
                            Console.WriteLine("Enter your email");
                            email = Console.ReadLine();
                            Console.WriteLine("Enter your password");
                            password = Console.ReadLine();
                            Console.WriteLine("Choose an account type");
                            Console.WriteLine(@"Savings: Press 0     |     Current: Press 1");
                            acctype = Convert.ToInt32(Console.ReadLine());
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("\nInvalid operation");
                        }
                    }
                    new UtilityClass().ValidateEmailFormat(email);

                    account = AuthClass.Register(name, email, password, acctype);
                    Console.WriteLine("Thanks For Registration  ");
                    if (account == null)
                    {
                        Console.WriteLine("Operation failed. Try again.");
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid operation!");
                    Environment.Exit(0);
                }


                if (account != null)
                {
                    Console.WriteLine("Hello " + FindCus(account) + "!!");
                }

                Console.WriteLine("  Deposit: Press 1  ");
                Console.WriteLine("  Withdrawal: Press 2  ");
                Console.WriteLine(" Transfer: Press 3   ");
                Console.WriteLine(" Account Bal: Press 4   ");
                Console.WriteLine("   Account Transction: 5  ");
                Console.WriteLine("     Logout: Press 6  ");

                string opt2 = "";

                while (opt2 != "6")
                {
                    opt2 = Console.ReadLine();

                    if (opt2 == "1")
                    {
                        try
                        {
                            Console.WriteLine("\nHow much do you wish to deposit?");
                            decimal deposit = Convert.ToDecimal(Console.ReadLine());

                            Console.WriteLine("\nPlease enter a short description note.");
                            string note = Console.ReadLine();
                            note = !string.IsNullOrWhiteSpace(note) ? note : "No note";

                            account.MakeDeposit(account.AccountNumber, deposit, note, account.AccountType);

                            Console.WriteLine($"\nDeposited successfully. Your balance is {account.Balance}");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error: " + e.Message);
                        }
                    }
                    else if (opt2 == "2")
                    {
                        try
                        {
                            Console.WriteLine("How much do you want to withdraw?");
                            decimal withdrawal = Convert.ToDecimal(Console.ReadLine());

                            Console.WriteLine("\nPlease enter a short description note.");
                            string note = Console.ReadLine();
                            note = !string.IsNullOrWhiteSpace(note) ? note : "No note";

                            account.MakeWithdrawal(account.AccountNumber, withdrawal, note, account.AccountType);

                            Console.WriteLine($"\nWithdrawn successfully. Your balance is {account.Balance}");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error: " + e.Message);
                        }
                    }
                    else if (opt2 == "3")
                    {
                        try
                        {
                            Console.WriteLine("\nHow much do you wish to Transfer?");
                            decimal transferAmt = Convert.ToDecimal(Console.ReadLine());

                            Console.WriteLine("\nPlease Enter Account Number?");
                            int accountNum = Convert.ToInt32(Console.ReadLine());

                            Console.WriteLine("\nPlease enter a short description note.");
                            string note = Console.ReadLine();
                            note = !string.IsNullOrWhiteSpace(note) ? note : "No note";

                            AccountClass tranferAcct = AuthClass.CheckAccount(accountNum);

                            if (tranferAcct == null)
                            {
                                throw new ArgumentOutOfRangeException(nameof(accountNum), "Invalid Account Number");
                            }

                            account.MakeTransfer(accountNum, transferAmt, note, account.AccountType, tranferAcct);


                            Console.WriteLine($"\nTransfer is successfully. Your balance is {account.Balance}");
                            Console.WriteLine("Enter 6 to return to menu ");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error: " + e.Message);
                            Console.WriteLine("Enter 6 to return to menu ");
                        }
                    }
                    else if (opt2 == "4")
                    {
                        Console.WriteLine("Total balance in account is  " + account.Balance);
                    }
                    else if (opt2 == "5")
                    {
                        decimal bal = 0;

                        Console.WriteLine("Account Number\tAmount\tBalance\tNote");
                        foreach (var transaction in BankdatasClass.Transactions)
                        {
                            if (transaction.AccountNumber == account.AccountNumber)
                            {
                                bal += transaction.Amount;
                                Console.WriteLine($"{transaction.AccountNumber}\t{transaction.Amount}\t{bal}\t{transaction.Note}");
                            }
                        }
                    }
                }
            }
        }
Exemple #21
0
 public AuthController(ArcDbContext db)
 {
     _db = db;
     AuthClass.Init(db);
 }