Ejemplo n.º 1
0
 //pratial view(_Login) func for login.
 public IActionResult Login(LoginViewModel vm)
 {
     //if form is not completed, send model back.
     if (!ModelState.IsValid)
     {
         View("_Login", vm);
     }
     else
     {
         //get user form database.
         var user = _db.UserRepository.GetByUserName(vm.UserName);
         if (user != null)
         {
             //try to decrypt password.
             if (!EncryptionHelper.VerifyHash(vm.Password, "SHA512", user.Password))
             {
                 //decryption failed, username and password does not match.
                 //raise a flag to reveal a warning.
                 //send model back to view.
                 ViewBag.WrongInput = true;
                 View("_Login", vm);
             }
             else
             {
                 //username and password match.
                 //log in the user.
                 _um.CreateCurrentUserCookie(user);
             }
         }
         else
         {
             ViewBag.WrongInput = true;
             View("_Login", vm);
         }
     }
     //redirect to main site view.
     return(View("~/views/Product/Index.cshtml", _productsManagement.GetProducts()));
 }
Ejemplo n.º 2
0
 //sits's main view, shows all currentl available products.
 public IActionResult Index(bool isOrdered = false)
 {
     return(View(_productsManagement.GetProducts(isOrdered)));
 }