コード例 #1
0
        //
        // POST: /Account/LogOff
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            AuthenticationManager.SignOut();
            Session.Clear();
            Session[Sessions.LogoutType] = 1;

            IUserLogActvityModel accModel = new UserLogActvityModel();
            AccountDAL           _dal     = new AccountDAL();

            accModel.UserId       = Convert.ToInt64(Session[Constant.UserId]);
            accModel.LogoutType   = 1;
            accModel.ActivityForm = "Logout";
            accModel.ModuleId     = 1;
            accModel.SessionId    = Session.SessionID;
            string hostName = Dns.GetHostName();

            accModel.IPAddress = Dns.GetHostEntry(hostName).AddressList[1].ToString();
            _dal.LogUserActvity(accModel);


            Session.Abandon();
            Response.Cookies.Clear();
            Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

            return(RedirectToAction(Constant.LoginAction, Constant.LoginController));
        }
コード例 #2
0
        public async Task <ActionResult> Login(AccountViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Require the user to have a confirmed email before they can log on.
            var user = await _userManager.FindAsync(model.UserName, model.Password);

            if (user != null)
            {
                if (!user.IsEmailConfirmed)
                {
                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account-Resend");

                    ViewBag.errorMessage = "You must have a confirmed email to log on.";
                    model.UserId         = user.Id;
                    model.EmailId        = user.EmailId;
                    model.UserName       = user.UserName;

                    ModelState.Clear();
                    return(View("EmailNotVerified", model));
                }
                await SignInAsync(user, model.RememberMe);

                Session[Constant.EmailId] = user.EmailId;
                //Session[Constant.TimeZoneId] = user.TimeZoneId;
                Session[Constant.UserId] = user.Id;
                Session[Constant.RoleId] = user.RoleId;



                IUserLogActvityModel accModel = new UserLogActvityModel();
                AccountDAL           _dal     = new AccountDAL();

                accModel.UserId       = Convert.ToInt64(Session[Constant.UserId]);
                accModel.LoginType    = 1;
                accModel.ActivityForm = "LogIn";
                accModel.ModuleId     = 1;
                accModel.SessionId    = Session.SessionID;
                string hostName = Dns.GetHostName();
                accModel.IPAddress = Dns.GetHostEntry(hostName).AddressList[1].ToString();
                _dal.LogUserActvity(accModel);

                if (user.RoleId != null && user.RoleId == 70043)
                {
                    return(RedirectToLocal(TempConstants.DefaultPublicPage));
                }
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ViewData["Error"] = true;
                ModelState.AddModelError("", "Invalid username or password.");
                return(View(model));
            }
        }