public virtual System.Web.Mvc.ActionResult Login(ViewModels.Account.LoginViewModel viewModel) { try { System.Web.Security.FormsAuthentication.SetAuthCookie (userName: viewModel.Username, createPersistentCookie: false); //System.Web.Security.FormsAuthentication.SetAuthCookie // (userName: user.Username, createPersistentCookie: viewModel.RememberMe); if (string.IsNullOrWhiteSpace(viewModel.ReturnUrl) == false) { return(Redirect(url: viewModel.ReturnUrl)); } else { //return RedirectToAction(MVC.Home.Index()); return(Redirect(url: System.Web.Security.FormsAuthentication.DefaultUrl)); } } catch (System.Exception ex) { //Dtx.Logger.LogError // (type: GetType(), exception: ex); //return RedirectToAction // (MVC.Error.UnexpectedError()); } return(View(model: viewModel)); }
public ActionResult Login(ViewModels.Account.LoginViewModel viewModel, string returnUrl) { if (ModelState.IsValid) { if (MembershipService.ValidateUser(viewModel.Username, viewModel.Password)) { FormsService.SignIn(viewModel.Username, viewModel.RememberMe); if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return(View(viewModel)); }
public async Task <ActionResult> Login(ViewModels.Account.LoginViewModel model) { //await SetInitialDataAsync(); if (ModelState.IsValid) { UserDTO userDto = new UserDTO { Email = model.Email, Password = model.Password }; ClaimsIdentity claim = await UserService.Authenticate(userDto); if (claim == null) { ModelState.AddModelError("", "Неверный логин или пароль."); } else { AuthenticationManager.SignOut(); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claim); return(RedirectToAction("Index", "Home")); } } return(View(model)); }
public override System.Web.Mvc.ActionResult Login(ViewModels.Account.LoginViewModel viewModel) { var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Login); ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "viewModel", viewModel); LoginOverride(callInfo, viewModel); return(callInfo); }
public System.Web.Mvc.ActionResult Login(ViewModels.Account.LoginViewModel viewModel) { return(View()); }
public System.Web.Mvc.ViewResult Login(ViewModels.Account.LoginViewModel loginViewModel) { return(View()); }
public Microsoft.AspNetCore.Mvc.IActionResult Login(ViewModels.Account.LoginViewModel viewModel) { // References: // https://jwt.io // https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/ // Create Jwt Security Token Handler Object var jwtSecurityTokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler(); // ************************************************** // Symmetric key must be atleast 128 bits long string strSymmetricKey = "This is the Symmetric Key"; var symmetricSecurityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey (System.Text.Encoding.ASCII.GetBytes(strSymmetricKey)); var signingCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials (key: symmetricSecurityKey, algorithm: Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature); // ************************************************** // Creating Token Description part var securityTokenDescriptor = new Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor { Subject = new System.Security.Claims.ClaimsIdentity(new System.Security.Claims.Claim[] { new System.Security.Claims.Claim("Username", "[Any Name]"), new System.Security.Claims.Claim("RoleName", "[Any Role]"), //new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, "[Any Name]"), //new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, "[Any Role]"), }), Issuer = "[Token Issuer Name]", Audience = "http://www.IranianExperts.com", // define lifetime of the token Expires = System.DateTime.Now.AddMinutes(5), SigningCredentials = signingCredentials, }; // Create Token var securityToken = jwtSecurityTokenHandler.CreateToken(securityTokenDescriptor); // convert Token to string string strTokenString = jwtSecurityTokenHandler.WriteToken(securityToken); var result = new { Token = strTokenString, }; VerifyToken(strTokenString); //VerifyToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IltBbnkgTmFtZV0iLCJyb2xlIjoiW0FueSBSb2xlXSIsIm5iZiI6MTQ5MzU1MzAxOSwiZXhwIjoxNDkzNTUzMzE2LCJpYXQiOjE0OTM1NTMwMTksImlzcyI6IltUb2tlbiBJc3N1ZXIgTmFtZV0iLCJhdWQiOiJodHRwOi8vd3d3LklyYW5pYW5FeHBlcnRzLmNvbSJ9.zLgzHAUxoCsNLhC-nLkYyMhckD-uNop5JRM_m-PGz5o"); // ************************************************** return(Json(data: result, serializerSettings: Infrastructure.JsonSerializerSettings.Instance)); }
Login(ViewModels.Account.LoginViewModel viewModel, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; //if (ModelState.IsValid) //{ // var user = // await _userManager.FindByNameAsync(viewModel.Username).ConfigureAwait(false); // if (user == null) // { // ModelState.AddModelError // (string.Empty, "نام کاربری و یا کلمهی عبور وارد شده معتبر نیستند."); // return (View(viewModel)); // } // if (user.IsActive == false) // { // ModelState.AddModelError // (string.Empty, "اکانت شما غیرفعال شدهاست."); // return (View(viewModel)); // } // if (_siteOptions.Value.EnableEmailConfirmation && // !await _userManager.IsEmailConfirmedAsync(user).ConfigureAwait(false)) // { // ModelState.AddModelError // (string.Empty, "لطفا به پست الکترونیک خود مراجعه کرده و ایمیل خود را تائید کنید!"); // return (View(viewModel)); // } // var result = // await // _signInManager.PasswordSignInAsync( // viewModel.Username, // viewModel.Password, // viewModel.RememberMe, // lockoutOnFailure: true) // .ConfigureAwait(false); // if (result.Succeeded) // { // _logger.LogInformation(1, $"{viewModel.Username} logged in."); // if (Url.IsLocalUrl(returnUrl)) // { // return Redirect(returnUrl); // } // return (RedirectToAction(nameof(HomeController.Index), "Home")); // } // if (result.RequiresTwoFactor) // { // return RedirectToAction // (nameof(TwoFactorController.SendCode), // "TwoFactor", // new { ReturnUrl = returnUrl, RememberMe = viewModel.RememberMe }); // } // if (result.IsLockedOut) // { // _logger.LogWarning(2, $"{viewModel.Username} قفل شدهاست."); // return (View("~/Areas/Identity/Views/TwoFactor/Lockout.cshtml")); // } // if (result.IsNotAllowed) // { // ModelState.AddModelError // (string.Empty, "عدم دسترسی ورود."); // return (View(viewModel)); // } // ModelState.AddModelError // (string.Empty, "نام کاربری و یا کلمهی عبور وارد شده معتبر نیستند."); // return (View(viewModel)); //} //// If we got this far, something failed, redisplay form //return (View(viewModel)); return(null); }
partial void LoginOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, ViewModels.Account.LoginViewModel viewModel);