示例#1
0
 public ActionResult Login(LoginModel loginModel)
 {
     using (BanGiayDbContext context = new BanGiayDbContext())
     {
         var user = context.TaiKhoans.Where(x => x.UserName == loginModel.UserName).FirstOrDefault();
         if (user == null)
         {
             ViewBag.Err = "Tài khoản không tồn tại";
             return(View());
         }
         if (user.PassWord.Trim() != Encryptor.MD5Hash(loginModel.PassWord))
         {
             ViewBag.Err = "Sai mật khẩu";
             return(View());
         }
         Session["Username"] = user.UserName;
         return(RedirectToAction("Products", "Products"));
     }
 }
示例#2
0
 public ActionResult Register(LoginModel loginModel, string reg)
 {
     using (BanGiayDbContext context = new BanGiayDbContext())
     {
         try
         {
             var user = context.TaiKhoans.Add(new TaiKhoan
             {
                 UserName = loginModel.UserName,
                 PassWord = Encryptor.MD5Hash(loginModel.PassWord)
             });
             context.SaveChanges();
             return(RedirectToAction("Login"));
         }
         catch (Exception ex)
         {
             ViewBag.Err = ex.Message;
             return(View());
         }
     }
 }
示例#3
0
 public tTaiKhoanModel()
 {
     context = new BanGiayDbContext();
 }