当前位置: 首页>>代码示例>>C#>>正文


C# LoginViewModel类代码示例

本文整理汇总了C#中LoginViewModel的典型用法代码示例。如果您正苦于以下问题:C# LoginViewModel类的具体用法?C# LoginViewModel怎么用?C# LoginViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LoginViewModel类属于命名空间,在下文中一共展示了LoginViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            if (model.Email.Contains("@"))
            {
                var user = this.UserManager.FindByEmail(model.Email);
                if (user != null)
                {
                    model.Email = user.UserName;
                }
            }

            var result = await this.SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return this.RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return this.View("Lockout");
                case SignInStatus.RequiresVerification:
                    return this.RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    this.ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return this.View(model);
            }
        }
开发者ID:TomaNikolov,项目名称:EventSystem,代码行数:31,代码来源:AccountController.cs

示例2: GetUserDetails

 public string GetUserDetails(string userName)
 {
     string isCaptchaDisplay = null;
     var loginType = CheckInputType(userName);
     var loginViewModel = new LoginViewModel();
     var user = _wcfService.InvokeService<IUserService, User>(svc => svc.GetUserByUsername(userName, loginType));
     if (user != null)
     {
         var ipAddress = GetClientIpAddress();
         var userHistory = user.UserLogins.Select(x => x.UserHistories.FirstOrDefault(y => y.IpAddress == ipAddress)).ToList();
         if (userHistory == null)
         {
             isCaptchaDisplay = "False";
             loginViewModel.IsCaptchaDisplay = isCaptchaDisplay.AsBool();
             return isCaptchaDisplay;
         }
         else
         {
             isCaptchaDisplay = "True";
             loginViewModel.IsCaptchaDisplay = isCaptchaDisplay.AsBool();
             return isCaptchaDisplay;
         }
     }
     //ModelState.AddModelError("UserName", "The user name is not correct.");
     return isCaptchaDisplay;
 }
开发者ID:prescripds,项目名称:PreScripds.UI,代码行数:26,代码来源:AccountController.cs

示例3: Login

        public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            EnsureDatabaseCreated(_applicationDbContext);
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
                if (result.Succeeded)
                {
                    return RedirectToLocal(returnUrl);
                }
                if (result.RequiresTwoFactor)
                {
                    return RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                }
                if (result.IsLockedOut)
                {
                    return View("Lockout");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return View(model);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
开发者ID:ashimoon,项目名称:dotnetliberty-aspnet5-dependency-demo,代码行数:31,代码来源:AccountController.cs

示例4: LogIn

        public ActionResult LogIn(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {

                bool temp = true;
                try
                {
                    temp = model.Email == "[email protected]";
                    temp = model.Password == "123";

                    temp = Membership.ValidateUser(model.Email, model.Password);

                }
                catch (Exception e)
                {

                    System.Console.WriteLine("Error");
                }

                return RedirectToAction("Index", "Home");

            }

            return RedirectToAction("LogIn", "Account");
        }
开发者ID:santhoshthangaraj,项目名称:Find-Your-Car,代码行数:26,代码来源:AccountController.cs

示例5: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    {
                        var visitor = new Visitor();
                        var userTemp = db.Users.FirstOrDefault(x => x.Email == model.Email);
                        visitor.UserId = userTemp.Id;
                        visitor.Time = DateTime.Now.ToString();
                        visitor.VisitorIP = GetIPAdress(Request);
                        visitor.VisitorCountry = "";// await GetCountryFromIp(visitor.VisitorIP);
                        myContext.Visitors.Add(visitor);
                        myContext.Entry(visitor).State = System.Data.Entity.EntityState.Added;
                        myContext.SaveChanges();
                        return RedirectToLocal(returnUrl);
                    }
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
开发者ID:mdfkmita,项目名称:isvb,代码行数:35,代码来源:AccountController.cs

示例6: Login

    public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
    {
        ViewBag.ReturnUrl = returnUrl;
        if (ModelState.IsValid)
        {
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, set shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
            if (result.Succeeded)
            {
                return RedirectToLocal(returnUrl);
            }
            if (result.RequiresTwoFactor)
            {
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            }
            if (result.IsLockedOut)
            {
                return View("Lockout");
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return View(model);
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }
开发者ID:hoetz,项目名称:3dshootercom,代码行数:30,代码来源:AccountController.cs

示例7: SignIn

        public async Task<ActionResult> SignIn(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                //return PartialView("_Login", model);
                //return PartialView();
                return View("Error");
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    var user = await UserManager.FindAsync(model.Email, model.Password);
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    //return RedirectToAction("Index", "Home");
                    //return View("_LoginPartial");
                    //return PartialView("_Login",model);
                    return View("Error");
            }
        }
开发者ID:handsofstone,项目名称:hp,代码行数:31,代码来源:AccountController.cs

示例8: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);
                if (user != null)
                {
                    var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
                    identity.AddClaim(new Claim("FirstName", user.FirstName));
                    identity.AddClaim(new Claim("LastName", user.LastName));
                    identity.AddClaim(new Claim("Email", user.Email));
                    identity.AddClaim(new Claim("Role", user.role.ToString()));

                    await SignInAsync(user, model.RememberMe);
                    return RedirectToLocal(returnUrl);
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
开发者ID:nroach44,项目名称:tothemoon,代码行数:25,代码来源:AccountController.cs

示例9: TestLoginIngresoFallido

        public void TestLoginIngresoFallido()
        {
            var userStore = new Mock<IUserStore<ApplicationUser>>();
            var userManager = new Mock<ApplicationUserManager>(userStore.Object);
            var authenticationManager = new Mock<IAuthenticationManager>();
            var signInManager = new Mock<ApplicationSignInManager>(userManager.Object, authenticationManager.Object);


            signInManager.Setup(s => s.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
                .Returns<string, string, bool, bool>(MockPasswordSignInAsync);


            var controller = new AccountController(userManager.Object, signInManager.Object);


            var contextMock = new Mock<HttpContextBase>();
            controller.Url = new UrlHelper(new RequestContext(contextMock.Object, new RouteData()));

            var loginViewmodel = new LoginViewModel
            {
                Email = "[email protected]",
                Password = "[email protected]",
                RememberMe = false
            };
            var returnUrl = "/Home/Index";

            //Act
            var result = controller.Login(loginViewmodel, returnUrl);

            //Assert

            Assert.IsInstanceOfType(result.Result, typeof(ViewResult));
            Assert.AreEqual("Usuario o Clave incorrectos", (result.Result as ViewResult).ViewData.ModelState[""].Errors[0].ErrorMessage);

        }
开发者ID:gustavosantisteban,项目名称:SeguridadMCGA,代码行数:35,代码来源:AccountControllerTest.cs

示例10: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result =
                await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false);
            switch (result)
            {
                case SignInStatus.Success:
                     //var hubContext = GlobalHost.ConnectionManager.GetHubContext<BaseHub>();
            
                    var user = await UserManager.FindAsync(model.UserName, model.Password);
                    //hubContext.Clients.AllExcept(user.UserName).kur("qjhui");
                    if (UserManager.IsInRole(user.Id, "Administrator"))
                    {
                        return RedirectToAction("Index", "Home");
                    }
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new {ReturnUrl = returnUrl, model.RememberMe});
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
开发者ID:SoftUni-GRIP,项目名称:PhotoContest,代码行数:33,代码来源:AccountController.cs

示例11: Logar

        public ActionResult Logar(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View("Index", model);
            }

            AutenticacaoService service = new AutenticacaoService();

            Stopwatch sw = Stopwatch.StartNew();

            bool resultado = service.Autenticar(model.Usuario, model.Senha);

            sw.Stop();

            Trace.WriteLine("Autenticar em " + sw.ElapsedMilliseconds);

            if (!resultado)
            {
                ModelState.AddModelError("Usuario",
                    "Usuário ou senha inválidos");

                return View("Index", model);
            }

            return Content("TOP SECRET!");
        }
开发者ID:TiagoSoczek,项目名称:MOC,代码行数:27,代码来源:LoginController.cs

示例12: Login

 public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     
     // This doesn't count login failures towards account lockout
     // To enable password failures to trigger account lockout, change to shouldLockout: true
     var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
     
     switch (result)
     {
         case SignInStatus.Success:
             {
                 //SessionHelper.UserSessionID = "TEMPSESSIONID";
                 AspNetUsersController aspUserCon = new AspNetUsersController();
                 var user = aspUserCon.GetUser(model.Email);
                 //SessionHelper.UserSessionID = user.Id;
                 SessionHelper.LoggedInUser<AspNetUser>(user, user.UserName);
                 return RedirectToLocal(returnUrl);
             }
         case SignInStatus.LockedOut:
             return View("Lockout");
         case SignInStatus.RequiresVerification:
             return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
         case SignInStatus.Failure:
         default:
             ModelState.AddModelError("", "Invalid login attempt.");
             return View(model);
     }
 }
开发者ID:hguomin,项目名称:MyFitnessTracker,代码行数:32,代码来源:AccountController.cs

示例13: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);
                if (user != null)
                {
                    // Put in the session the logged user.
                    Session["user"] = user;
                    TempData["userName"] = user.UserName;

                    // Define if the user is Administrator. If not I need go get his ID to use in the query.
                    if (user.UserName.Equals("Admin"))
                        TempData["userId"] = null;
                    else
                        TempData["userId"] = user.Id;
                    
                    TempData.Keep();

                    await SignInAsync(user, model.RememberMe);
                    return RedirectToLocal(returnUrl);
                }
                else
                    ModelState.AddModelError(string.Empty, "The User Name and/or Password entered is invalid. Please try again.");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
开发者ID:Aldonei,项目名称:Stefanini,代码行数:29,代码来源:AccountController.cs

示例14: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
           // var user = new ApplicationUser { UserName = "[email protected]", Email = "[email protected]" };
           // var re = await UserManager.CreateAsync(user, "[email protected]");

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
开发者ID:vanan08,项目名称:ADSoft,代码行数:27,代码来源:AccountController.cs

示例15: Main

        public async Task<ActionResult> Main(string LID)
        {
            if (LID != null)
            {
                var db = getDB0();
                var getItem = db.Apply_User.Where(x => x.userid == LID).FirstOrDefault();
                if (getItem != null)
                {
                    LoginViewModel md = new LoginViewModel() { account = "user", password = "4257386-", lang = "zh-TW", rememberme = false };
                    var getResult = await ajax_Login(md);

                    LoginResult trnResult = Newtonsoft.Json.JsonConvert.DeserializeObject<LoginResult>(getResult);
                    if (trnResult.result)
                    {
                        Response.Cookies.Add(new HttpCookie("user_id", Server.UrlEncode(EncryptString.desEncryptBase64(getItem.userid))));
                        Response.Cookies.Add(new HttpCookie("user_name", Server.UrlEncode(getItem.username)));
                        Response.Cookies.Add(new HttpCookie("user_login", Server.UrlEncode(EncryptString.desEncryptBase64("Y"))));

                        return Redirect(trnResult.url + "/Users");
                    }
                }
            }

            HttpContext.GetOwinContext().Authentication.SignOut();
            ViewData["username"] = "";
            ViewData["password"] = "";

#if DEBUG
            ViewData["username"] = CommWebSetup.AutoLoginUser;
            ViewData["password"] = CommWebSetup.AutoLoginPassword;
#endif
            return View("Index");
        }
开发者ID:jcincloud,项目名称:C071416_EEI_Textile,代码行数:33,代码来源:MNGLoginController.cs


注:本文中的LoginViewModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。