• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# LoginViewModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例7: 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


示例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


示例16: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);


                // // Insert a new user into the database
                //using (var db = new ApplicationDbContext())
                //{

                //    db.Results.Add(new Result { TeamName = model.} )
                //}






                if (user != null)
                {
                    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:nvolpe,项目名称:HappyBall,代码行数:33,代码来源:AccountController.cs


示例17: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            model.RememberMe = true;

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

            SignInStatus result;
            try
            {
                result = await _signInManager.PasswordEmailSignInAsync(model.Email, model.Password
                    , model.RememberMe, shouldLockout: IdentitySettings.ShouldLockOut);
            }
            catch(Exception exception)
            {
                _logger.Exception(exception);
                result = SignInStatus.Failure;
            }
            
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");               
                case SignInStatus.Failure:
                default:
                    string invalidMessage = IdentityResourceHelper.Load(IdentitySettings.IdentityResource, "AccountController_Login_Invalid");
                    ModelState.AddModelError("", invalidMessage);
                    
                    return View(model);
            }
        }
开发者ID:RodionKulin,项目名称:ContentManagementBackend,代码行数:35,代码来源:AccountController.cs


示例18: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.GaTechId, model.Password);
                if (user != null)
                {
                    if (user.EmailConfirmed)
                    {
                        await SignInAsync(user, model.RememberMe);
                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Account activiation is awaiting email confirmation.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password.");
                }
            }

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


示例19: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = await UserManager.FindAsync(model.Email, model.Password);

                    if (user != null)
                    {
                        await SignInAsync(user, model.RememberMe);

                        return Json(new { success = true, url = returnUrl });
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid username or password.");
                    }
                    //await experiment(user);
                }
                catch (DbEntityValidationException dbx)
                {
                    foreach(var item in dbx.EntityValidationErrors)
                    {
                        foreach(var thisThing in item.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", thisThing.PropertyName, thisThing.ErrorMessage);
                        }
                    }
                }
            }
            return PartialView(model);
        }
开发者ID:Gcobani,项目名称:urbanbooks,代码行数:33,代码来源:AccountController.cs


示例20: Login

        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                // Validate the password
                IdentityResult result =
                    await
                    this.IdentityManager.Authentication.CheckPasswordAndSignInAsync(
                       this.AuthenticationManager,
                        model.UserName,
                        model.Password,
                        model.RememberMe);
                if (result.Success)
                {
                    return this.RedirectToLocal(returnUrl);
                }
                else
                {
                    this.AddErrors(result);
                }
            }

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Lookup类代码示例发布时间:2022-05-24
下一篇:
C# LoginStatus类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap