示例#1
0
 public ActionResult Register(UserModel user)
 {
     if (ModelState.IsValid)
     {
         user.Register(user);
         return RedirectToAction("Index", "Home");
     }
     
     return View(user);
 }
示例#2
0
        public void Register(UserModel user)
        {
            using (var db = new shamethethronesContext())
            {
                User newUser = new User();

                newUser.username = user.UserName;
                newUser.email = user.Email;
                newUser.pasword = CalculateMD5Hash(user.Password);
                
                db.Users.Add(newUser);
                db.SaveChanges();
            }
        }
示例#3
0
        public ActionResult Login(UserModel user)
        {
          
//            if (ModelState.IsValid)
//            {
                if (user.isValid(user.Email, user.Password))
                {

                    var userDat = new UserData();
                    userDat.UserName = user.UserName;
                    userDat.Email = user.Email;
                    userDat.Id = user.getId();
                string userData = new JavaScriptSerializer().Serialize(userDat);
                FormsAuthenticationTicket authTicket = new
                    FormsAuthenticationTicket(1, //version
                                              userDat.Id.ToString(), // user name
                                              DateTime.Now,             //creation
                                              DateTime.Now.AddMinutes(30), //Expiration
                                              true, userData); //storing the json data

                string encTicket = FormsAuthentication.Encrypt(authTicket);
                var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
                {
                    Expires = authTicket.Expiration,
                    Path = FormsAuthentication.FormsCookiePath
                };
                Response.Cookies.Add(cookie);
                return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Either your username or password is incorrect.");
                }
//            }
            return View(user);
        }