private void Form1_Load(object sender, EventArgs e) { base.WindowState = FormWindowState.Maximized; MainForm mainForm = new MainForm(); mainForm.MdiParent = this; mainForm.Anchor = AnchorStyles.Top | AnchorStyles.Right; mainForm.Dock = DockStyle.Fill; mainForm.Show(); this.InitialStatus(false); SigninForm signinForm = new SigninForm(); signinForm._form1 = this; signinForm.Show(); }
public async Task <ActionResult> Sigin([FromBody, BindRequired] SigninForm signinForm) { var result = new RestfulData <TokenObj>(); //验证用户名和密码 var userInfo = new UserDao().GetUser(signinForm.username, signinForm.password); if (userInfo != null) { var claims = new Claim[] { new Claim(ClaimTypes.Sid, userInfo.Id.ToString()), new Claim(ClaimTypes.Name, userInfo.Nickname ?? ""), new Claim(ClaimTypes.Role, userInfo.Role), new Claim(ClaimTypes.NameIdentifier, userInfo.Username), }; var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(ConfigHelper.GetValueByKey("SecurityKey"))); var expires = DateTime.Now.AddDays(30);// var token = new JwtSecurityToken( issuer: ConfigHelper.GetValueByKey("issuer"), audience: ConfigHelper.GetValueByKey("audience"), claims: claims, notBefore: DateTime.Now, expires: expires, signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256)); //生成Token string jwtToken = new JwtSecurityTokenHandler().WriteToken(token); result.data = new TokenObj() { token = jwtToken, expires = expires.ToFileTimeUtc() }; result.message = "授权成功!"; return(Ok(result)); } else { result.message = "账号或密码错误"; result.code = 400; return(BadRequest(result)); } }
/// <summary> /// Presents a login window to the user. /// </summary> /// <remarks>Created: Theo Crous 14/11/2011</remarks> static void Signin() { try { if (BL.ApplicationDataContext.Instance.LoggedInUser != null) { // Henko - TODO: Security removed from user roles - still need acceptable replacement //if (BL.ApplicationDataContext.Instance.AccessGranted(BL.SEC.AccessCodes.SYGE02)) RestoreSize(); Application.Run(MainForm.Instance); } else { // User credentials have not yet been provided, show login form SigninForm frmLogin = new SigninForm(); frmLogin.ShowDialog(); if (frmLogin.DialogResult == DialogResult.OK) { // Henko - TODO: Security removed from user roles - still need acceptable replacement //if (BL.ApplicationDataContext.Instance.AccessGranted(BL.SEC.AccessCodes.SYGE02)) RestoreSize(); Application.Run(MainForm.Instance); } else { Application.Exit(); } } } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }