public NetworkManager() { m_NetworkLog = new NetworkLog(); m_Client = new HClient(); m_Client.OnAccountResponse += M_Client_OnAccountResponse; m_Client.OnGameDataResponse += M_Client_OnGameDataResponse; m_Client.OnTowerDataResponse += M_Client_OnTowerDataResponse; m_ClientPump = new Thread(new ThreadStart(ClientPumpThread)); m_ClientPump.Name = "Client Pump Thread"; m_ClientPump.Start(); m_SignInStatus = SignInStatus.None; if (m_VipData == null) { m_VipData = new VipDataArgs(); m_VipData.Level = 1; m_VipData.Progress = 0; m_VipData.Hints = 5; m_VipData.MegaHints = 2; m_VipData.UndoSize = 5; } }
protected void LogIn(object sender, EventArgs e) { var FailureMessage = ""; if (IsValid) { // Validate the user password var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>(); var session = Context.GetOwinContext().Get<IDocumentSession>(); // This doen't count login failures towards account lockout // To enable password failures to trigger lockout, change to shouldLockout: true var user = manager.FindByEmail(Email.Text); var result = new SignInStatus(); if(user.IsEmailConfirmed) result = signinManager.PasswordSignIn(user.UserName, Password.Text, RememberMe.Checked, shouldLockout: false); else if(!user.IsEmailConfirmed) { FailureMessage = "Check your email now for new account activation!"; result = SignInStatus.Failure; string code = manager.GenerateEmailConfirmationToken(user.Id); string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request); IdentityMessage msg = new IdentityMessage() { Destination = user.Email, Subject = "QuoteForm Email Confirmation", Body = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>." }; manager.EmailService.SendAsync(msg); } switch (result) { case SignInStatus.Success: IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); break; case SignInStatus.LockedOut: Response.Redirect("/Account/Lockout"); break; case SignInStatus.RequiresVerification: Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}", Request.QueryString["ReturnUrl"], RememberMe.Checked), true); break; case SignInStatus.Failure: default: FailureText.Text = "Invalid login attempt. " + FailureMessage; ErrorMessage.Visible = true; break; } } }
private ActionResult ProcessSignInStatus(string returnUrl, SignInStatus result, ExternalLoginInfo loginInfo) { switch (result) { case SignInStatus.Success: return this.RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return this.View("Lockout"); default: this.CreateAndSignInNewUser(loginInfo); return this.RedirectToLocal(returnUrl); } }
public NetworkManager(string address, int port) { _address = address; _port = port; NetLogger log = new NetLogger(); _signInStatus = SignInStatus.SignedOut; _theThread = new Thread(new ThreadStart(FFCManagerThreadFunc)); _theThread.Name = "Network Manager"; _theThread.Start(); }
public async Task <IdentityManagerResult <SignInResultState> > SignInAsync(SignInViewModel uploadModel) { var accountResult = new IdentityManagerResult <SignInResultState, SignInViewModel>(); MedioClinicUser user = null; try { user = await UserManager.FindByNameAsync(uploadModel.EmailViewModel.Email); } catch (Exception ex) { var ar = accountResult as IdentityManagerResult <SignInResultState>; accountResult.ResultState = SignInResultState.UserNotFound; HandleException(nameof(SignInAsync), ex, ref ar); return(accountResult); } // Registration: Confirmed registration (begin) if (user != null && !await UserManager.IsEmailConfirmedAsync(user.Id)) { accountResult.ResultState = SignInResultState.EmailNotConfirmed; return(accountResult); } // Registration: Confirmed registration (end) SignInStatus signInStatus = SignInStatus.Failure; try { signInStatus = await SignInManager.PasswordSignInAsync(uploadModel.EmailViewModel.Email, uploadModel.PasswordViewModel.Password, uploadModel.StaySignedIn, false); } catch (Exception ex) { var ar = accountResult as IdentityManagerResult <SignInResultState>; accountResult.ResultState = SignInResultState.NotSignedIn; HandleException(nameof(SignInAsync), ex, ref ar); return(accountResult); } if (signInStatus == SignInStatus.Success) { accountResult.Success = true; accountResult.ResultState = SignInResultState.SignedIn; } return(accountResult); }
public JsonResult Login(LoginViewModel info) { ApplicationSignInManager signInManager = HttpContext.GetOwinContext().Get <ApplicationSignInManager>(); SignInStatus result = signInManager.PasswordSignIn(info.Email, info.Password, true, false); switch (result) { case SignInStatus.Success: return(Json(new { success = true })); case SignInStatus.Failure: return(Json(new { success = false })); } return(Json(new { success = false })); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } SignInStatus result = this.SignInManager.PasswordSignIn(model.UserName, model.Password, model.RememberMe, false); if (result == SignInStatus.Success) { return(RedirectToAction("Index", "Home")); } return(View(model)); }
private void OnAuthenticated(SignInStatus result) { switch (result) { case SignInStatus.Success: Debugger("GPG sign in successful"); userLogginedIntoGoogle = true; break; default: Debugger($"GPG sign in failed: {result}"); userLogginedIntoGoogle = false; break; } }
//overrided passwordSignInAsync public override async Task <SignInStatus> PasswordSignInAsync(string userEmail, string password, bool isPersistent, bool shouldLockout) { SignInStatus signInStatus = SignInStatus.Success; if (this.UserManager != null) { /// changed to use email address instead of username Task <ApplicationUser> userAwaiter = this.UserManager.FindByEmailAsync(userEmail); ApplicationUser tUser = await userAwaiter; if (tUser != null) { Task <bool> cultureAwaiter1 = this.UserManager.IsLockedOutAsync(tUser.Id); if (!await cultureAwaiter1) { Task <bool> cultureAwaiter2 = this.UserManager.CheckPasswordAsync(tUser, password); if (!await cultureAwaiter2) { if (shouldLockout) { Task <IdentityResult> cultureAwaiter3 = this.UserManager.AccessFailedAsync(tUser.Id); await cultureAwaiter3; Task <bool> cultureAwaiter4 = this.UserManager.IsLockedOutAsync(tUser.Id); if (await cultureAwaiter4) { signInStatus = SignInStatus.LockedOut; return(signInStatus); } } signInStatus = SignInStatus.Failure; } } else { signInStatus = SignInStatus.LockedOut; } } else { signInStatus = SignInStatus.Failure; } } else { signInStatus = SignInStatus.Failure; } return(signInStatus); }
public async Task <JsonResult> LoginWithApi(LoginViewModel model, string returnUrl) { if (model == null) { model = new LoginViewModel { UserName = "******", Password = "******", StaySignedIn = true }; } SignInStatus signInResult = SignInStatus.Failure; try { signInResult = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.StaySignedIn, false); } catch (Exception ex) { EventLogProvider.LogException("AccountController", "Login", ex); } var user = UserManager.FindByName(model.UserName); ApiResponse <UserDto> data = new ApiResponse <UserDto>(); if (signInResult == SignInStatus.Success) { data = new ApiResponse <UserDto> { statusCode = HttpStatusCode.OK, success = true, message = "User Login Successful.", data = UserData(user) }; } else { data = new ApiResponse <UserDto> { statusCode = HttpStatusCode.Unauthorized, success = false, message = "Please verify username or passowrd", data = null }; } //return data; return(Json(data, JsonRequestBehavior.AllowGet)); }
public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { SignInStatus result = SignInManager.PasswordSignIn(model.UserName, model.Password, false, false); if (result == SignInStatus.Success) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } return(View(model)); }
public ActionResult PopiMetadatas( ) { List <DataStoreDto> dataStoreDto = new List <DataStoreDto>( ); if (Session["signInStatus"] != null) { SignInStatus signInStatus = ( SignInStatus )Session["signInStatus"]; if (signInStatus == SignInStatus.Success) { ApiCaller apiCaller = new ApiCaller( ); dataStoreDto = apiCaller.GetPopiMetada( ); } } return(View(dataStoreDto)); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { SignInStatus result = accounts.Login(model); if (result == SignInStatus.Success && User.IsInRole("Admin")) { return(RedirectToAction("Index", "Home", new { area = "Admin" })); } else if (result == SignInStatus.Failure) { return(RedirectToAction("Index", "Home")); } } return(View(model)); }
public new async Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { SignInStatus result = (SignInStatus)await base.PasswordSignInAsync(userName, password, isPersistent, shouldLockout); if (result == SignInStatus.Success) { var user = await UserManager.FindByNameAsync(userName); bool isEmailConfirmed = await UserManager.IsEmailConfirmedAsync(user.Id); if (!isEmailConfirmed) { result = SignInStatus.EmailNotConfirmed; } } return(result); }
/// <summary> /// 将登录结果转换为Ajax结果 /// </summary> public static AjaxResult ToAjaxResult(this SignInStatus status) { switch (status) { case SignInStatus.Failure: return(new AjaxResult("用户名或密码错误", AjaxResultType.Error)); case SignInStatus.LockedOut: return(new AjaxResult("用户因密码错误次数过多而被锁定,请稍后重试", AjaxResultType.Error)); case SignInStatus.RequiresVerification: return(new AjaxResult("用户登录需要验证", AjaxResultType.Error)); default: return(new AjaxResult("用户登录成功", AjaxResultType.Success)); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } SignInStatus result = await SignInManager.PasswordSignInAsync(model.TransportCardNumber); switch (result) { case SignInStatus.Success: return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Invalid login attempt"); return(View(model)); }
public async override Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { SignInStatus retorno = await base.PasswordSignInAsync(userName, password, isPersistent, shouldLockout); Usuario u = await UserManager.FindAsync(userName, password); if (u?.Deletado != true) { return(retorno); } else { retorno = await base.PasswordSignInAsync("", "", isPersistent, shouldLockout); } return(retorno); }
public IEnumerator SignInAsync() { SignInStatus signInStatus = SignInStatus.Success; TaskYieldInstruction <SignInResult> signInSilentlyTask = this.XboxLiveUser.User.SignInSilentlyAsync().AsCoroutine(); yield return(signInSilentlyTask); try { signInStatus = signInSilentlyTask.Result.Status; } catch (Exception ex) { if (XboxLiveServicesSettings.Instance.DebugLogsOn) { Debug.Log("Exception occured: " + ex.Message); } } if (signInStatus != SignInStatus.Success) { TaskYieldInstruction <SignInResult> signInTask = this.XboxLiveUser.User.SignInAsync().AsCoroutine(); yield return(signInTask); try { signInStatus = signInTask.Result.Status; } catch (Exception ex) { if (XboxLiveServicesSettings.Instance.DebugLogsOn) { Debug.Log("Exception occured: " + ex.Message); } } } // Throw any exceptions if needed. if (signInStatus == SignInStatus.Success) { XboxLive.Instance.StatsManager.AddLocalUser(this.XboxLiveUser.User); XboxLive.Instance.SocialManager.AddLocalUser(this.XboxLiveUser.User, SocialManagerExtraDetailLevel.PreferredColorLevel); } this.Refresh(); }
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 ApplicationUser signedUser = UserManager.FindByEmail(model.Email); SignInStatus result = SignInStatus.Failure; try { result = await SignInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, shouldLockout : false); } catch (Exception ex) { return(View("Error")); } switch (result) { case SignInStatus.Success: { if (string.IsNullOrEmpty(Session["extVendor"] as string)) { // Associate with vendor } 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)); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } SignInStatus result = SignInStatus.Failure; ApplicationUser user = db.Users.FirstOrDefault(b => b.Email.Equals(model.Email)); //if (user.login) //{ // ModelState.AddModelError("", "已在其他地方進行過登入 登入失敗"); // return View(model); //} //else //{ // result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); //} result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); // 這不會計算為帳戶鎖定的登入失敗 // 若要啟用密碼失敗來觸發帳戶鎖定,請變更為 shouldLockout: true switch (result) { case SignInStatus.Success: string userMail = model.Email; ApplicationUser u = db.Users.FirstOrDefault(x => x.Email.Equals(userMail)); u.login = true; db.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("", "登入嘗試失試。"); return(View(model)); } }
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 SignInStatus 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); if (UserManager.IsInRole(user.Id, RoleName.CanManageOFC)) { return(RedirectToAction("AdminDashboard", "Admin")); } else if (UserManager.IsInRole(user.Id, RoleName.Chef)) { return(RedirectToAction("ChefDashboard", "Admin")); } else if (UserManager.IsInRole(user.Id, RoleName.DeliveryTeamMember)) { return(RedirectToAction("TeamMemberDashboard", "Admin")); } else { return(RedirectToAction("CustomerDashboard", "Customer")); } 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)); } }
public async Task <ActionResult> Login(LoginModel login, string returnUrl) { if (!ModelState.IsValid) { TempData["model-errors"] = ModelState.Values; return(Redirect(returnUrl)); } SignInStatus result = await SignInManager.PasswordSignInAsync(login.Username, login.Password, true, false); if (result != SignInStatus.Success) { TempData["signin-success"] = false; } return(Redirect(returnUrl)); }
public JsonResult _Login(LoginViewModel info) { //1 Signin manegare ulaş ApplicationSignInManager sigInManager = HttpContext.GetOwinContext().Get <ApplicationSignInManager>(); //2. Giriş yapmayı dene(result dene.) SignInStatus result = sigInManager.PasswordSignIn(info.Email, info.Password, true, false); //3. ilgili Durumlara göre sonucu döndür switch (result) { case SignInStatus.Success: return(Json(new { success = true, })); //giriş case SignInStatus.Failure: return(Json(new { success = false })); } return(Json(new { success = false })); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { SignInStatus result = new SignInStatus(); //EducationDatabaseEntities ent = new EducationDatabaseEntities(); //UsersRepository userRepo = new UsersRepository(ent); IService service = new Service(); string eduId = model.Email, password = model.Password; // if(userRepo.Login(model.Email, model.Password)) if (service.Login(eduId, password)) { var user = new Users(); // user = userRepo.GetAll().FirstOrDefault(x => x.EduId == model.Email); user = service.GetAllUsers().FirstOrDefault(x => x.EduId == eduId); if (user != null) { result = SignInStatus.Success; } else { result = SignInStatus.Failure; } } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true 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)); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } model.Password = PasswordGenerator.Encrypt(model.Password); var login = await _userService.Get(u => u.Username == model.Email && u.Password == model.Password && u.Enabled && u.Rol == Demo.Model.Roles.SuperUser); SignInStatus result = login != null ? SignInStatus.Success : SignInStatus.Failure; switch (result) { case SignInStatus.Success: { string userjson = JsonConvert.SerializeObject(login); FormsAuthentication.SetAuthCookie(login.Username, true); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login.Username, DateTime.Now, DateTime.Now.AddMinutes(120), false, userjson, FormsAuthentication.FormsCookiePath); Response.Cookies.Add(new HttpCookie("TTCookieAuth", FormsAuthentication.Encrypt(ticket))); return(RedirectToAction("Index", "User")); } case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Intento de inicio de sesión no válido."); return(View(model)); } }
public async Task <SignInStatus> SignInWithTwoFactorCookieAsync(User user) { SignInStatus signInStatus = SignInStatus.Failure; var validTwoFactorUserTokenProviders = await this.userTokenTwoFactorProvider.GetValidTwoFactorUserTokenProvidersAsync(user); if (validTwoFactorUserTokenProviders.Count > 0) { if (!await this.AuthenticateIdentityAsync(user.Id, Infrastructure.Identity.Model.AuthenticationType.TwoFactorRememberBrowserCookie)) { ClaimsIdentity claimsIdentity = this.CreateUserClaimsIdentity(user.Id, Infrastructure.Identity.Model.AuthenticationType.TwoFactorCookie); this.authenticationManager.SignIn(claimsIdentity); signInStatus = SignInStatus.RequiresVerification; } } return(signInStatus); }
private ActionResult VerifyCodeRedirect(SignInStatus result, VerifyCodeViewModel model) { switch (result) { case SignInStatus.Success: return(RedirectToLocal(model.ReturnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.Failure: ModelState.AddModelError("", "Invalid code."); return(View(model)); default: ModelState.AddModelError("", "Invalid code."); return(View(model)); } }
public ActionResult Login(CustomLoginViewMode aLogin) { if (!ModelState.IsValid) { return(View(aLogin)); } PMS.App_Start.IdentityConfig.ApplicationSignInManager signInManager = Request.GetOwinContext().Get <PMS.App_Start.IdentityConfig.ApplicationSignInManager>(); SignInStatus sighInStatus = signInManager.PasswordSignIn(aLogin.Email, aLogin.Passwod, false, false); switch (sighInStatus) { case SignInStatus.Success: return(Redirect("/")); default: ModelState.AddModelError("", "Invalid Attempt"); return(View(aLogin)); } }
/// <summary> /// 用户授权登录,写cookie,分配id等 /// </summary> /// <param name="userModel"></param> /// <param name="rememberMe"></param> /// <returns></returns> public SignInStatus SignIn(BaseResult <CurrentUserModel> userModel, bool rememberMe = false) { SignInStatus status = SignInStatus.Success; if (userModel?.Data == null) { return(SignInStatus.Failure); } if (userModel.Code != (int)ResultCode.Success) { return(SignInStatus.Failure); } var user = userModel.Data; var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, user.UserId.ToString()), new Claim(ClaimTypes.Name, user.UserName), new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity"), new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user)) }; var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); var expiration = DateTime.UtcNow; if (rememberMe) { expiration = DateTime.UtcNow.AddDays(Configs.CookieMaxAge); } else { var sessionStateSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState"); expiration = DateTime.UtcNow.AddMinutes(sessionStateSection.Timeout.TotalMinutes); } AuthenticationManager.SignIn(new AuthenticationProperties() { AllowRefresh = true, IsPersistent = rememberMe, ExpiresUtc = expiration }, identity); return(status); }
public ActionResult Login(LoginViewModel model) { if (!ModelState.IsValid) { return(View(model)); } ApplicationSignInManager signInManager = Request.GetOwinContext().Get <ApplicationSignInManager>(); SignInStatus signInStatus = signInManager.PasswordSignIn(model.Email, model.Password, false, false); switch (signInStatus) { case SignInStatus.Success: return(Redirect("/")); default: ModelState.AddModelError("", "Invalid Login Attempt"); return(View(model)); } }
public async override Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { SignInStatus result = SignInStatus.Failure; var user = await this.UserManager.FindByNameAsync(userName); if (user != null) { var isCheckedPassword = await this.UserManager.CheckPasswordAsync(user, password); if (isCheckedPassword) { await base.SignInAsync(user, isPersistent, shouldLockout); result = SignInStatus.Success; } } return(result); }
public JsonResult Login(LoginViewModel info) { //1.Sign in Managera ulaş ApplicationSignInManager signInManager = HttpContext.GetOwinContext().Get <ApplicationSignInManager>(); //2.Giriş yapmayı dene (result döner) SignInStatus result = signInManager.PasswordSignIn(info.Email, info.Password, true, false); //3.Sonucu döndür switch (result) { case SignInStatus.Success: return(Json(new { success = true })); case SignInStatus.Failure: return(Json(new { success = false }));; } return(Json(new { success = false })); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { ViewBag.ReturnUrl = returnUrl; ViewBag.OperatorMode = returnUrl.ToUpper().Contains("/MES/WORKPLACE"); if (!ModelState.IsValid) { return(View(model)); } SignInStatus result = SignInStatus.RequiresVerification; if (IsAuthenticatedByLdap(model)) { User user = UserManager.FindByName(model.UserName); if (user != null) { await UpdatePasswordIfNotMatch(user, model); } else { await CreateUser(model); } } result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : true); 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(string.Empty, "Niepoprawne dane logowania."); return(View(model)); } }
/// <summary> /// Signs in a user by username and password + confirms the identity. /// </summary> /// <typeparam name="TUser"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="signInManager"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="isPersistent"></param> /// <param name="shouldLockout"></param> /// <returns></returns> public static async Task <SignInStatus> PasswordSignInAndConfirmAsync <TUser, TKey>(this SignInManager <TUser, TKey> signInManager, string userName, string password, bool isPersistent, bool shouldLockout) where TUser : class, IUser <TKey> where TKey : IEquatable <TKey>, IConvertible { SignInStatus status = await signInManager.PasswordSignInAsync(userName, password, isPersistent, shouldLockout); if (status == SignInStatus.Success) { // We have to override the existing grant with a new one, as we are adding // a new claim TUser user = await signInManager.UserManager.FindByNameAsync(userName); string userIdString = signInManager.ConvertIdToString(user.Id); AuthenticationResponseGrant grant = signInManager.AuthenticationManager.AuthenticationResponseGrant; grant.Identity.AddClaim(new Claim(DoubleConfirmIdentityConstants.ClaimType, userIdString)); signInManager.AuthenticationManager.SignIn(grant.Properties, grant.Identity); } return(status); }
private ActionResult ValidateAndReturnProperView(SignInStatus result, VerifyCodeViewModel model) { switch (result) { case SignInStatus.Success: return RedirectToLocal(model.ReturnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid code."); return View(model); } }
private void M_Client_OnAccountResponse(object sender, EventArgs e) { if( m_Client.AccountId < 0 ) m_SignInStatus = SignInStatus.InvalidAccount; else if( m_Client.DisplayName == null ) m_SignInStatus = SignInStatus.InvalidPassword; else m_SignInStatus = SignInStatus.SignedIn; }
public void SignIn(string displayName = null) { if (m_SignInStatus != SignInStatus.CredentialsSent) { m_Client.SendAccountRequest(m_szEmail, m_szPassword, displayName); m_SignInStatus = SignInStatus.CredentialsSent; } }
public void CreateAccount(string email, string password, string displayname) { _signInStatus = SignInStatus.SigningIn; _ffc.SendAccountRequest(email, password, displayname); }
void _ffc_OnAccountResponse(object sender, EventArgs e) { if (_ffc.AccountId < 0) _signInStatus = SignInStatus.AccountDoesntExist; else if (_ffc.DisplayName != null) _signInStatus = SignInStatus.SignedIn; else _signInStatus = SignInStatus.InvalidPassword; }
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { var result = new SignInStatus(); ViewBag.HideMenu = true; // Kiểm tra theo loại vai trò #region Nếu là người dùng (Tỉnh hoặc Huyện) if (model.UserRolesName.Equals("User")) // Kiểm tra login cho đơn vị { TempData["TabLoginDonVi"] = "loginDonVi"; TempData["TabLoginDonVi_ID"] = model.NhomDonVi_ID; ViewBag.TabLoginDonVi_TenDonVi = model.TenDonVi; TempData["TabLoginDonVi_TenDonVi"] = model.TenDonVi; if (string.IsNullOrEmpty(model.HoVaTen)) { ModelState.AddModelError("HoVaTen", "Tên chuyên viên không được để trống"); } if (string.IsNullOrEmpty(model.TenDonVi)) { ModelState.AddModelError("TenDonVi", "Tên đơn vị không được để trống"); } ModelState.Remove("UserName"); ModelState.Remove("Password"); if (!ModelState.IsValid) { GetViewBag(); return View("Login","_Layout_Null", model); } var objDonVi = db.Dm_DonVi.FirstOrDefault(o => o.TenDonVi.Trim().ToLower().Equals(model.TenDonVi.Trim().ToLower())); if (objDonVi == null) { ModelState.AddModelError("TenDonVi", "Không tìm thấy đơn vị"); GetViewBag(); return View("Login", "_Layout_Null", model); } var user = UserManager.Users.FirstOrDefault(o => o.HoVaTen.Trim().ToLower() == model.HoVaTen.Trim().ToLower() && o.DonVi_ID == objDonVi.DonVi_ID); if (user == null) { ModelState.AddModelError("HoVaTen", "Tên chuyên viên không đúng"); GetViewBag(); return View("Login", "_Layout_Null", model); } // Kiểm tra trạng thái Account đang bị khóa (không hoạt động) if (user.TrangThai == TrangThai.KhongHoatDong) { ModelState.AddModelError("HoVaTen", "Tài khoản đang bị khóa"); GetViewBag(); return View("Login", "_Layout_Null", model); } // Kiểm tra nhân viên có thuộc đơn vị ? if (!user.DonVi_ID.Equals(objDonVi.DonVi_ID)) { ModelState.AddModelError("HoVaTen", "Chuyên viên không thuộc đơn vị"); GetViewBag(); return View("Login", "_Layout_Null", model); } // Trường hợp đăng nhập, layout gọi login để lấy Session if (String.IsNullOrEmpty(returnUrl)) { await SignInManager.SignInAsync(user, model.RememberMe, model.RememberMe); // Lưu người dùng vào session Session.Add("User", user as ApplicationUser); Session.Add("HoVaTenUser", user.HoVaTen); GetPhanHeChucNangByUser(user); return RedirectToLocal(returnUrl); } else { // Kiểm tra đơn vị có đang đc quyền nhập dữ liệu không var objLichNhap = db.Ht_LichNhapLieu.FirstOrDefault(o => o.DonVi_ID == objDonVi.DonVi_ID && o.TuNgay <= DateTime.Now && o.DenNgay >= DateTime.Now); if (objLichNhap == null) ModelState.AddModelError("TenDonVi", "Đơn vị chưa được nhập dữ liệu"); else //login thành công { await SignInManager.SignInAsync(user, model.RememberMe, model.RememberMe); // Lưu người dùng vào session Session.Add("User", user as ApplicationUser); Session.Add("HoVaTenUser", user.HoVaTen); GetPhanHeChucNangByUser(user); return RedirectToLocal(returnUrl); } } } #endregion Nếu là người dùng (Tỉnh hoặc Huyện) #region Nếu loại vai trò là Admin, Chuyên viên, Văn thư else { ModelState.Remove("TenDonVi"); ModelState.Remove("HoVaTen"); if (!ModelState.IsValid) { GetViewBag(); return View("Login", "_Layout_Null", model); } // Kiểm tra trạng thái Account đang bị khóa (không hoạt động) var user = UserManager.Users.FirstOrDefault(o => o.UserName == model.UserName.Trim()); if (user == null) { ModelState.AddModelError("UserName", "Tài khoản nhập không đúng"); GetViewBag(); return View("Login", "_Layout_Null", model); } if (user.TrangThai == TrangThai.KhongHoatDong) { ModelState.AddModelError("UserName", "Tài khoản đang bị khóa"); GetViewBag(); return View("Login", "_Layout_Null", model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false); } #endregion Nếu loại vai trò là Admin, Chuyên viên, Văn thư switch (result) { case SignInStatus.Success: // Tạo session cho người dùng var user = UserManager.Users.FirstOrDefault(o => o.UserName == model.UserName.Trim()); if (user != null) { Session.Add("User", user as ApplicationUser); Session.Add("HoVaTenUser", user.HoVaTen); } GetPhanHeChucNangByUser(user); 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("Password", "Sai mật khẩu truy cập"); return View("Login", "_Layout_Null", model); } }
public void ResetSignIn() { _signInStatus = SignInStatus.SignedOut; }
public void SignIn(string email, string pass) { _signInStatus = SignInStatus.SigningIn; _ffc.SendAccountRequest(email, pass); }
private ActionResult ValidateAndReturnProperView(SignInStatus result, string returnUrl, ExternalLoginInfo loginInfo) { switch (result) { case SignInStatus.Success: return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }); case SignInStatus.Failure: default: // If the user does not have an account, then prompt the user to create an account ViewBag.ReturnUrl = returnUrl; ViewBag.LoginProvider = loginInfo.Login.LoginProvider; return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); } }
private ActionResult ValidateAndReturnProperView(SignInStatus result, string returnUrl, LoginViewModel model) { 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); } }