コード例 #1
0
        public ActionResult LogOut(MVCLoginInternet.Models.userModel user)
        {
            FormsAuthentication.SignOut();
            //  HttpContext.CurrentHandler
            HttpContext.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
            Session.Abandon();

            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
        public ActionResult Registration(MVCLoginInternet.Models.userModel user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var db = new MainDBEntities())
                    {
                        var sysUser = db.users.Create();

                        sysUser.userId    = Guid.NewGuid();
                        sysUser.email     = user.email;
                        sysUser.password  = user.password;
                        sysUser.userName  = user.userName;
                        sysUser.firstName = user.firstName;
                        sysUser.lastName  = user.lastName;
                        //sysUser.twitterName = user.twitterName;
                        // sysUser.tw
                        //   sysUser.twitterName = user.twitterName;

                        db.users.Add(sysUser);
                        db.SaveChanges();


                        FormsAuthentication.SetAuthCookie(user.email, false);

                        return(RedirectToAction("List"));
                        // return RedirectToAction("Index", "Home");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Add unique values to username and email, this user already exists");
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("", "Registration data is incorrect");
            }
            return(View());
        }