예제 #1
0
        public Account Deposit(Transaction transaction)
        {
            TransactionValidated(transaction);
            var account = _context.Accounts.Where(x => x.Number == transaction.AccountNumber).FirstOrDefault();

            account.Value += transaction.Value;
            var transactionHistory = new TransactionHistory {
                AccountNumber = account.Number, TransactionType = TransactionType.Deposit, TransactionTime = DateTime.Now, TransactionValue = transaction.Value
            };

            _context.Add(transactionHistory);
            _context.SaveChanges();
            return(account);
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Guid,UserName,Password,Role,Email,CreateTime,UpdateTime")]
                                                 Account account)
        {
            if (ModelState.IsValid)
            {
                account.Guid       = Guid.NewGuid();
                account.CreateTime = DateTime.Now;
                account.UpdateTime = DateTime.Now;
                account.Role       = UserRole.Ordinary;
                context.Add(account);
                await context.SaveChangesAsync();

                var partyMember =
                    new PartyMember(new SeriaNumber().Seria(pMContext.PartyMembers.Count() + 1, Key.PMPre))
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                pMContext.Add(partyMember);
                await pMContext.SaveChangesAsync();

                var accountPartyMember =
                    new AccountPartyMember(account.UserName, partyMember.PartyMemberID)
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                aPMContext.Add(accountPartyMember);
                await aPMContext.SaveChangesAsync();

                var partyCost =
                    new PartyCost(new SeriaNumber().Seria(pCContext.PartyCosts.Count() + 1, Key.PCPre),
                                  partyMember.PartyMemberID)
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now,
                    State      = Verify.Unaudited
                };
                pCContext.Add(partyCost);
                await pCContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(account));
        }
예제 #3
0
        public IActionResult RegisterUser(User user)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <User> hasher = new PasswordHasher <User>();
                string hashedpw = hasher.HashPassword(user, user.Password);
                User   newUser  = new User
                {
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Email     = user.Email,
                    Password  = hashedpw
                };

                _context.Add(newUser);
                _context.SaveChanges();

                User myUser = _context.Users.SingleOrDefault(User => User.Email == user.Email);

                HttpContext.Session.SetInt32("id", myUser.Id);
                return(RedirectToAction("Index", "Account"));
            }
            else
            {
                Console.WriteLine("******* VALIDATION FAILED*******");
                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #4
0
 public IActionResult ProcessReg(UserRegister model)
 {
     if (ModelState.IsValid)
     {
         // Check for unique email
         List <User> users = _context.Users.Where(user => user.Email == model.Email).ToList();
         if (users.Count > 0)
         {
             ModelState.AddModelError("Email", "Email already exists");
             return(View("Index"));
         }
         else
         {
             // Hash password and add to db
             PasswordHasher <UserRegister> hasher = new PasswordHasher <UserRegister>();
             string hashedPassword = hasher.HashPassword(model, model.Password);
             User   user           = new User
             {
                 FirstName = model.FirstName,
                 LastName  = model.LastName,
                 Email     = model.Email,
                 Password  = hashedPassword
             };
             _context.Add(user);
             _context.SaveChanges();
             HttpContext.Session.SetInt32("userID", (int)user.ID);
             return(RedirectToAction("Index", "Transaction", new{ id = user.ID }));
         }
     }
     return(View("Index"));
 }
예제 #5
0
        public async Task <IActionResult> Create([Bind("AccountNumber,CustomerName,Branch,JoiningDate")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("UserId,Password,NicName,UserGroup,InActivity")] UserIdentity userIdentity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userIdentity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userIdentity));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("AccountId,AccountType,FirstName,LastName")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
예제 #8
0
        public async Task <IActionResult> SignUp([Bind("username,password,email")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(account));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("AccountNumber,AccountType,CustomerID,ModifyDate")] Account account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerID"] = new SelectList(_context.Set <Customer>(), "CustomerID", "CustomerName", account.CustomerID);
            return(View(account));
        }
예제 #10
0
 public BankAccount CreateBA(BankAccount BA)
 {
     if (_accountContext.BankAccounts.Any(x => x.AccountNumber == BA.AccountNumber))
     {
         throw new ApplicationException("This BA number is already taken!");
     }
     BA.AccountType      = "Student";
     BA.RealBalance      = 50000;
     BA.AvailableBalance = 0;
     _accountContext.Add(BA);
     _accountContext.SaveChanges();
     return(BA);
 }
예제 #11
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Email,Password,ConfirmPassword")] Account account)
        {
            if (ModelState.IsValid)
            {
                account.TimeStamp = DateTime.Now;

                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
예제 #12
0
        public void EncryptAllPasswords()
        {
            IEnumerable <string> Passwords = _context.Account.Select(x => x.Password).ToList();


            foreach (var a in Passwords)
            {
                byte[] s = System.Text.ASCIIEncoding.ASCII.GetBytes(a);

                string Encrypt = Convert.ToBase64String(s);

                _context.Add(Encrypt);
            }
        }
예제 #13
0
        public BankAccount CreateAccount(Account account, string Password)
        {
            if (_accountContext.Accounts.Any(x => x.Name == account.Name))
            {
                throw new ApplicationException("This name has been already taken");
            }
            if (_accountContext.Accounts.Any(x => x.Email == account.Email))
            {
                throw new ApplicationException("This email has been already taken");
            }
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(Password, out passwordHash, out passwordSalt);
            account.PasswordHash = passwordHash;
            account.PasswordSalt = passwordSalt;
            //_accountContext.Add(account);

            BankAccount ba = initBA();

            account.AccountNumber = ba.AccountNumber;
            _accountContext.Add(ba);
            _accountContext.Add(account);
            _accountContext.SaveChanges();
            return(ba);
        }
예제 #14
0
 public IActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         var accountToAdd = new Account
         {
             Email    = model.Email,
             Login    = model.Login,
             Password = model.Password
         };
         accountContext.Add(accountToAdd);
         accountContext.SaveChanges();
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         ModelState.AddModelError("", "Некорректные логин и(или) пароль");
         return(View(model));
     }
 }
예제 #15
0
 public void Create(Account entity)
 {
     _context.Add(entity);
 }
        public void AddAccounting(AccountingVM accounting)
        {
            //Logic
            #region logic
            var _accounting = new Accounting()
            {
                senderAccountNumber   = accounting.senderAccountNumber,
                receiverAccountNumber = accounting.receiverAccountNumber,
                amount = accounting.amount
            };

            int sender   = accounting.senderAccountNumber;
            int receiver = accounting.receiverAccountNumber;
            int amount   = accounting.amount;

            var isSenderValid   = _context.Accounts.Where(x => x.accountNumber == sender).FirstOrDefault();
            var isReceiverValid = _context.Accounts.Where(x => x.accountNumber == receiver).FirstOrDefault();

            bool senderOK   = false;
            bool receiverOK = false;
            bool balanceOK  = false;
            bool currencyOK = false;

            if (isSenderValid.accountNumber == sender)
            {
                senderOK = true;
            }
            else
            {
                NotFoundSender(sender);
            }
            if (isReceiverValid.accountNumber == receiver)
            {
                receiverOK = true;
            }
            else
            {
                NotFoundReceiver(receiver);
            }
            if (isSenderValid.currencyCode == isReceiverValid.currencyCode)
            {
                currencyOK = true;
            }
            else
            {
                NotFoundCurrency(isReceiverValid.currencyCode);
            }
            if (isSenderValid.balance >= amount)
            {
                balanceOK               = true;
                isSenderValid.balance   = isSenderValid.balance - amount;
                isReceiverValid.balance = isReceiverValid.balance + amount;
            }
            else
            {
                NotFoundBalance(sender);
            }
            #endregion
            if (senderOK && receiverOK && currencyOK && balanceOK)
            {
                _context.Add(_accounting);
                _context.SaveChanges();
            }
            else
            {
                NotFound();
            }
        }
 public void InsertAccount(Account product)
 {
     _dbContext.Add(product);
     Save();
 }
 public void InsertAccount(Account account)
 {
     _dbContext.Add(account);
     Save();
 }
예제 #19
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
            .AddAzureAD(options => Configuration.Bind("AzureAd", options))
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
            {
                options.AccessDeniedPath  = "/Account/Unauthorised";
                options.ExpireTimeSpan    = TimeSpan.FromHours(1);
                options.SlidingExpiration = true;
                options.Cookie.SameSite   = SameSiteMode.Strict;
                options.EventsType        = typeof(CustomCookieAuthenticationEvents);
                options.LoginPath         = "/Landing/RealmDiscovery";
            });

            services.Configure <OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
            {
                options.Authority += "/v2.0/";
                options.TokenValidationParameters.ValidateIssuer = true;
                options.GetClaimsFromUserInfoEndpoint            = true;
                options.SkipUnrecognizedRequests = true;
                options.UseTokenLifetime         = true;
                options.RemoteSignOutPath        = "/single-signout";
                options.Events = new OpenIdConnectEvents
                {
                    OnRemoteFailure = context =>
                    {
                        context.Response.Redirect("/Landing/Unauthenticated");
                        context.HandleResponse();
                        return(Task.FromResult(0));
                    },
                    OnAuthenticationFailed = context =>
                    {
                        context.Response.Redirect("/Landing/Unauthenticated");
                        context.HandleResponse();
                        return(Task.FromResult(0));
                    },
                    OnRedirectToIdentityProvider = context =>
                    {
                        if (context.ProtocolMessage.RedirectUri.StartsWith("http://"))
                        {
                            context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http://", "https://");
                        }
                        if (context.Properties.Items.TryGetValue("prompt", out string prompt))
                        {
                            context.ProtocolMessage.Prompt = prompt;
                        }
                        if (context.Properties.Items.TryGetValue("login_hint", out string loginHint))
                        {
                            context.ProtocolMessage.LoginHint = loginHint;
                        }
                        return(Task.CompletedTask);
                    },
                    OnRedirectToIdentityProviderForSignOut = context =>
                    {
                        if (context.ProtocolMessage.PostLogoutRedirectUri.StartsWith("http://"))
                        {
                            context.ProtocolMessage.PostLogoutRedirectUri = context.ProtocolMessage.PostLogoutRedirectUri.Replace("http://", "https://");
                        }
                        return(Task.CompletedTask);
                    },
                    OnSignedOutCallbackRedirect = context =>
                    {
                        context.Response.Redirect("/Landing/Signout");
                        context.HandleResponse();
                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = loginContext =>
                    {
                        var claimsIdentity            = (ClaimsIdentity)loginContext.Principal.Identity;
                        AccountContext accountContext = loginContext.HttpContext.RequestServices.GetRequiredService <AccountContext>();
                        User retrieved = accountContext.Users.Where(u => u.IDPReference == claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value).FirstOrDefault();
                        if (retrieved != null)
                        {
                            if (!retrieved.Username.Equals(claimsIdentity.FindFirst("preferred_username").Value))
                            {
                                retrieved.Username = claimsIdentity.FindFirst("preferred_username").Value;
                            }
                            retrieved.ForceSignOut      = false;
                            retrieved.HybridSignIncount = 0;
                            foreach (var claim in claimsIdentity.Claims)
                            {
                                if (claim.Type.Equals("groups"))
                                {
                                    List <Role> retrievedRoles = accountContext.Roles.ToList();
                                    foreach (var retrievedRole in retrievedRoles)
                                    {
                                        if (retrievedRole.IDPReference.Equals(claim.Value))
                                        {
                                            retrieved.LinkedRole = retrievedRole;
                                        }
                                    }
                                }
                                else if (claim.Type.Equals(ClaimTypes.Email))
                                {
                                    retrieved.EmailAddress         = claim.Value;
                                    retrieved.VerifiedEmailAddress = true;
                                }
                                else if (claim.Type.Equals(ClaimTypes.MobilePhone))
                                {
                                    retrieved.PhoneNumber         = claim.Value;
                                    retrieved.VerifiedPhoneNumber = true;
                                }
                            }
                            if (retrieved.VerifiedEmailAddress && retrieved.VerifiedPhoneNumber)
                            {
                                retrieved.OverridableField = OverridableField.None;
                            }
                            else if (retrieved.VerifiedEmailAddress)
                            {
                                retrieved.OverridableField = OverridableField.PhoneNumber;
                            }
                            else if (retrieved.VerifiedPhoneNumber)
                            {
                                retrieved.OverridableField = OverridableField.EmailAddress;
                            }
                            retrieved.LastAuthentication = DateTime.Now;
                            accountContext.Update(retrieved);
                            accountContext.SaveChanges();
                        }
                        else
                        {
                            retrieved = accountContext.Users.Where(u => u.Username == claimsIdentity.FindFirst("preferred_username").Value).FirstOrDefault();
                            if (retrieved == null)
                            {
                                User import = new User
                                {
                                    Username           = claimsIdentity.FindFirst("preferred_username").Value,
                                    Name               = claimsIdentity.FindFirst("name").Value,
                                    Password           = Password.GetRandomSalt(),
                                    Existence          = Existence.External,
                                    IDPReference       = claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value,
                                    LastPasswordChange = DateTime.Now,
                                    LastAuthentication = DateTime.Now,
                                    Status             = UserStatus.Active,
                                    OverridableField   = OverridableField.Both
                                };
                                foreach (var claim in claimsIdentity.Claims)
                                {
                                    if (claim.Type.Equals("groups"))
                                    {
                                        List <Role> retrievedRoles = accountContext.Roles.ToList();
                                        foreach (var retrievedRole in retrievedRoles)
                                        {
                                            if (retrievedRole.IDPReference.Equals(claim.Value))
                                            {
                                                import.LinkedRole = retrievedRole;
                                            }
                                        }
                                    }
                                    else if (claim.Type.Equals(ClaimTypes.Email))
                                    {
                                        import.EmailAddress         = claim.Value;
                                        import.VerifiedEmailAddress = true;
                                    }
                                    else if (claim.Type.Equals(ClaimTypes.MobilePhone))
                                    {
                                        import.PhoneNumber         = claim.Value;
                                        import.VerifiedPhoneNumber = true;
                                    }
                                }
                                if (string.IsNullOrWhiteSpace(import.EmailAddress) && claimsIdentity.FindFirst("preferred_username").Value.Contains('@'))
                                {
                                    import.EmailAddress         = claimsIdentity.FindFirst("preferred_username").Value;
                                    import.VerifiedEmailAddress = true;
                                }
                                if (import.VerifiedEmailAddress && import.VerifiedPhoneNumber)
                                {
                                    import.OverridableField = OverridableField.None;
                                }
                                else if (import.VerifiedEmailAddress)
                                {
                                    import.OverridableField = OverridableField.PhoneNumber;
                                }
                                else if (import.VerifiedPhoneNumber)
                                {
                                    import.OverridableField = OverridableField.EmailAddress;
                                }
                                accountContext.Add(import);
                                accountContext.SaveChanges();
                                import            = accountContext.Users.Where(u => u.IDPReference == claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value).FirstOrDefault();
                                Settings settings = new Settings
                                {
                                    LinkedUserID = import.ID,
                                    LinkedUser   = import
                                };
                                if (import.VerifiedEmailAddress == true)
                                {
                                    settings.CommmuicationOptions = CommmuicationOptions.EMAIL;
                                }
                                else if (import.VerifiedPhoneNumber == true || import.OverridableField == OverridableField.None)
                                {
                                    settings.CommmuicationOptions = CommmuicationOptions.SMS;
                                }
                                accountContext.Settings.Add(settings);
                                accountContext.SaveChanges();
                            }
                            else
                            {
                                loginContext.Response.Redirect("/Landing/Unauthenticated");
                                loginContext.HandleResponse();
                                return(Task.FromResult(0));
                            }
                        }
                        foreach (var claim in claimsIdentity.Claims.ToList())
                        {
                            if (claim.Type.Equals("groups"))
                            {
                                List <Role> retrievedRoles = accountContext.Roles.ToList();
                                foreach (var retrievedRole in retrievedRoles)
                                {
                                    if (retrievedRole.IDPReference.Equals(claim.Value))
                                    {
                                        claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, retrievedRole.RoleName));
                                    }
                                }
                            }
                        }
                        if (claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/identityprovider") == null)
                        {
                            claimsIdentity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/identityprovider", claimsIdentity.FindFirst("iss").Value.Remove(claimsIdentity.FindFirst("iss").Value.Length - 4)));
                        }
                        return(Task.FromResult(0));
                    }
                };
            });