示例#1
0
 public ActionResult Register(RegisterViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         using (CryptoWalletDbContext ctx = new CryptoWalletDbContext())
         {
             CryptoWalletDb.Domain.User user = ctx.Users.AsNoTracking().FirstOrDefault(u => u.Email == viewModel.Email);
             if (user == null)
             {
                 user = new User
                 {
                     Email    = viewModel.Email,
                     Name     = viewModel.Name,
                     Password = viewModel.Password
                 };
                 ctx.Users.Add(user);
                 ctx.SaveChanges();
                 return(RedirectToAction("Login"));
             }
             else
             {
                 ModelState.AddModelError("", "Email is already registered.");
                 return(View(viewModel));
             }
         }
     }
     else
     {
         return(View(viewModel));
     }
 }
示例#2
0
 public ActionResult Login(LoginViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         using (CryptoWalletDbContext ctx = new CryptoWalletDbContext())
         {
             CryptoWalletDb.Domain.User user = ctx.Users.FirstOrDefault(u => u.Email == viewModel.Username && u.Password == viewModel.Password);
             if (user != null)
             {
                 FormsAuthentication.SetAuthCookie(viewModel.Username, true);
                 return(RedirectToAction("Index", "BankAccounts"));
             }
             else
             {
                 ModelState.AddModelError("", "Invalid credentials.");
                 return(View(viewModel));
             }
         }
     }
     else
     {
         return(View(viewModel));
     }
 }