public ActionResult ChangePassword(string password, string confirm)
        {
            SettingsViewModel svm = new SettingsViewModel {
                UserLogin = Login
            };

            if (password.Length < 8)
            {
                MessageBox.Show("Password must be at least 8 characters long.", "Password too short");
                return(View("ChangePassword"));
            }

            if (!password.Equals(confirm))
            {
                MessageBox.Show("New password and password confirmation do not match.", "Error");
                return(View("ChangePassword"));
            }
            else
            {
                User userInDb = Context.Users.Single(u => u.Login == Login);
                userInDb.Password = password;
                Context.SaveChanges();
                MessageBox.Show("Password has been successfully changed.", "Success");
            }

            return(RedirectToAction("Index", svm));
        }
        public ActionResult Edit(int id, string title, string login, string email, string password)
        {
            Account accountInDb = Context.Accounts.Single(a => a.Id == id);

            accountInDb.Title    = title;
            accountInDb.Login    = login;
            accountInDb.Email    = email;
            accountInDb.Password = password;
            Context.SaveChanges();

            User user = Context.Users.Single(u => u.Id == accountInDb.UserId);

            MainViewModel mvm = new MainViewModel
            {
                Login    = user.Login,
                Accounts = Context.Accounts.Where(a => a.UserId == user.Id).ToList()
            };

            return(RedirectToAction("Index", mvm));
        }
Exemple #3
0
 public void ImportAccounts(List <AccountImport> accountVMs)
 {
     foreach (var accountVM in accountVMs)
     {
         Account account = new Account
         {
             AccountNumber = accountVM.account_number,
             Balance       = accountVM.balance,
             Firstname     = accountVM.firstname,
             Lastname      = accountVM.lastname,
             Age           = accountVM.age,
             Gender        = accountVM.gender,
             Address       = accountVM.address,
             Employer      = accountVM.employer,
             Email         = accountVM.email,
             City          = accountVM.city,
             State         = accountVM.state
         };
         _context.Add(account);
         _context.SaveChanges();
     }
 }
        public ActionResult Register(string login, string email, string password, string confirm, string pin)
        {
            if (Context.Users.SingleOrDefault(u => u.Login == login) != null)     // found user with given login = login used
            {
                MessageBox.Show("Login \"" + login + "\" is already used.", "Login used");
                return(RedirectToAction("Index"));
            }

            if (password.Length < 8)
            {
                MessageBox.Show("Password must be at least 8 characters long.", "Password too short");
                return(RedirectToAction("Index"));
            }

            if (!password.Equals(confirm))
            {
                MessageBox.Show("Password and password confirmation do not match.", "No match");
                return(RedirectToAction("Index"));
            }

            string verificationCode = new Random().Next(100000, 999999).ToString();

            EmailManager.SendEmail(email, "greeting", login, verificationCode);

            string code = Interaction.InputBox("A verification code has been sent to " +
                                               "your email address. Enter it in order to verify your email account and proceed with the registration.",
                                               "Authorization", "", 1, 1);

            if (!code.Equals(verificationCode))
            {
                MessageBox.Show("Invalid verification code, please try again.", "Invalid verification code.");
                return(RedirectToAction("Index"));
            }

            Context.Users.Add(new User {
                Login = login, Email = email, Password = password, Pin = pin
            });
            Context.SaveChanges();

            MessageBox.Show("User \"" + login + "\" has been successfully registered.", "Registration successful");
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        private void SeedDB()
        {
            using AccountManagerContext context = new AccountManagerContext(_options);
            var accounts = new List <Account>
            {
                new Account
                {
                    ID          = 1,
                    DomainName  = "domain1",
                    AccountName = "Account1",
                    Password    = "******"
                },
                new Account
                {
                    ID          = 2,
                    DomainName  = "domain1",
                    AccountName = "Account2",
                    Password    = "******"
                },
                new Account
                {
                    ID          = 3,
                    DomainName  = "domain2",
                    AccountName = "Account1",
                    Password    = "******"
                },
                new Account
                {
                    ID          = 4,
                    DomainName  = "domain2",
                    AccountName = "Account3",
                    Password    = "******"
                },
            };

            context.Account.AddRange(accounts);
            context.SaveChanges();
        }
Exemple #6
0
 protected virtual int Save()
 {
     return(_dataContext.SaveChanges());
 }
Exemple #7
0
 public int SaveChanges()
 {
     return(_dataContext.SaveChanges());
 }