示例#1
0
 public IActionResult TryRegister(UserAccount account, string password2)
 {
     if (account.Username == null || account.Password == null)
     {
         return(RedirectToAction("FieldEmpty"));
     }
     else
     {
         if (DatabaseControl.AccountExists(account, _context))
         {
             return(RedirectToAction("UsernameTaken"));
         }
         else if (account.Username.Length < 5)
         {
             return(RedirectToAction("UsernameTooShort"));
         }
         else if (account.Password != password2)
         {
             return(RedirectToAction("PasswordsDifferent"));
         }
         else if (account.Password.Length < 5)
         {
             return(RedirectToAction("PasswordTooShort"));
         }
         else
         {
             _account = account;
             SaveChanges();
             return(RedirectToAction("CustomerInput"));
         }
     }
 }
 public IActionResult VerifyUsername(string username)
 {
     if (!DatabaseControl.AccountExists(username, _context))
     {
         return(Json($"Username {username} is already in use."));
     }
     return(Json(true));
 }
示例#3
0
 public void UserAccountExists_ReturnsFalse()
 {
     using (var _context = new P1Context())
     {
         /*DatabaseControl.SetContext(context);*/
         UserAccount account = new UserAccount
         {
             Username = "******",
             Password = "******"
         };
         bool exists = DatabaseControl.AccountExists(account, _context);
         Assert.False(exists);
     }
 }