public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { // throw new Exception("called"); var identity = new ClaimsIdentity(context.Options.AuthenticationType); if (context != null && !string.IsNullOrEmpty(context.UserName) && !string.IsNullOrEmpty(context.Password)) { Model.LoginModel model = new Model.LoginModel() { Email = context.UserName, Password = context.Password, HashPassword = Common.SecurityManager.EncryptText(context.Password) }; model = _dataServices.LoginService.ValidateUserLogin(model); if (model != null && model.Success == true) { identity.AddClaim(new Claim(ClaimTypes.Role, ((Role)model.RoleId).ToString())); context.Validated(identity); return; } } context.SetError("invalid_grant", "Provided username or password is incorrect"); return; //https://www.youtube.com/watch?v=rMA69bVv0U8 }
public void ResetarSenha(Model.LoginModel login) { string json = JsonConvert.SerializeObject(login); StringContent body = new StringContent(json, Encoding.UTF8, "application/json"); var resp = client.PutAsync("http://localhost:5000/Professor/resetarsenha/", body).Result; string jsonresposta = LerJsonResposta(resp); }
private void btnSalvar_Click(object sender, EventArgs e) { try { if (modeloProf.IdProfessor != 0) { Model.ProfessorRequest request = new Model.ProfessorRequest(); List <Model.Model.DiciplinaModel> disciplina = lbxDisciplinasDoProfessor.DataSource as List <Model.Model.DiciplinaModel>; Model.ProfessorModel prof = DadosProfessor(); prof.IdProfessor = modeloProf.IdProfessor; request.Disciplina = disciplina; request.Professor = prof; request.Login = modeloProf.Login; request.Login.DsLogin = txtLogin.Text; request.Login.BtAtivo = chkAtivo.Checked; api.Alterar(request); MessageBox.Show("Alterado com sucesso!", "NSF", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Model.ProfessorRequest request = new Model.ProfessorRequest(); List <Model.Model.DiciplinaModel> disciplina = lbxDisciplinasDoProfessor.DataSource as List <Model.Model.DiciplinaModel>; Model.ProfessorModel prof = DadosProfessor(); Model.LoginModel login = DadosLogin(); request.Disciplina = disciplina; request.Professor = prof; request.Login = login; request = api.Inserir(request); MessageBox.Show("Inserido com sucesso!", "NSF", MessageBoxButtons.OK, MessageBoxIcon.Information); panelId.Visible = true; lblId.Text = request.Professor.IdProfessor.ToString(); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "NSF", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception) { MessageBox.Show("Ocorreu um erro. Entre em contato com o administrador.", "NSF", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private Model.LoginModel DadosLogin() { Model.LoginModel login = new Model.LoginModel(); login.BtAtivo = true; login.BtTrocar = true; login.DsLogin = txtLogin.Text; login.DsSenha = "1234"; login.DtInclusao = DateTime.Now; login.DtUltimoLogin = DateTime.Now; login.IdRole = 1; return(login); }
public IActionResult GetToken([FromBody] Model.LoginModel login) { IActionResult response = Unauthorized(); Model.RepoUserModel repoM = new Model.RepoUserModel(); Model.RepoLoginmodel repoL = new Model.RepoLoginmodel(); var user = repoM.Authenticate(login); if (user.Username != null) { var tokenString = repoL.BuildToken(_config, user); response = Ok(new { token = tokenString }); } return(response); }
public IActionResult Login(Model.LoginModel loginModel) { string token = string.Empty; //authenticate if (InMemoryDB.Users.Any(p => p.Username == loginModel.Username && p.Password == loginModel.Password)) { token = Guid.NewGuid().ToString(); InMemoryDB.Tokens.Add (token, new IdentityServer.Model.SecurityToken() { Roles = InMemoryDB.UserPermissions[loginModel.Username], Username = loginModel.Username }); } return(Ok(new { Token = token })); }
public IActionResult Login([FromBody] Model.LoginModel login) { if (login.Username != "oscar" || login.Password != "123123") { return(BadRequest("User or pass invalid")); } var authClaims = new[] { new Claim(ClaimTypes.Name, "oscar"), new Claim(ClaimTypes.NameIdentifier, login.Username) }; var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["ApiAuth:SecretKey"])); var signingCredentials = new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256Signature); ClaimsIdentity claimsIdentity = new ClaimsIdentity(authClaims); var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.CreateJwtSecurityToken( issuer: _configuration["ApiAuth:Issuer"], audience: _configuration["ApiAuth:Audience"], expires: DateTime.Now.AddHours(int.Parse(_configuration["ApiAuth:ExpireTime"])), subject: claimsIdentity, notBefore: DateTime.UtcNow, signingCredentials: signingCredentials ); Model.Users user = new Model.Users() { Firstname = "Oscar", User = "******", RoleId = 1, Role = "Administrator", token = tokenHandler.WriteToken(token) }; return(Ok(new { token = tokenHandler.WriteToken(token), expiration = token.ValidTo, user = user })); }
public void Send(int sendUserId, int receiverUserId, string roomId, string message, string type, decimal filesize, string filename, int messagejobID) { Business.MatchBXMessage _obj = new Business.MatchBXMessage(); Model.MatchBXMessageModel _model = new Model.MatchBXMessageModel(); _obj.SendUserId = sendUserId; _obj.ReceiverId = receiverUserId; _obj.Message = message; _obj.MessageType = type; _obj.FileSize = filesize; _obj.FileName = filename; _obj.JobId = messagejobID; _model.Save(_obj); Model.LoginModel _objLoginModel = new Model.LoginModel(); Business.Login _objLogin = new Business.Login(); _objLogin = _objLoginModel.CheckUserOnlineStatus(receiverUserId, sendUserId); Clients.All.addNewMessageToPage(message, receiverUserId, sendUserId, "Chat", _objLogin.IsOnline, roomId, type, filesize, filename, _objLogin.ProfilePic); if (_objLogin.IsMailSent == 0) { MatchBxCommon.OfflineMessageMail(sendUserId, receiverUserId, _model.Id); } }
public ActionResult Login(Model.LoginModel model, string returnUrl) { var IsLogin = ""; try { if (ModelState.IsValid) { string[] SplitAccount = new string[] { }; var username = ""; Entity.advt_users users = new advt_users(); Regex RegEmail = new Regex(@"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?");//w 英文字母或数字的字符串,和 [a-zA-Z0-9] 语法一样 Match m = RegEmail.Match(model.UserName); //工号 var wuser = Data.ExamUsersFromehr.Get_ExamUsersFromehr(new { UserCode = model.UserName }); if (wuser != null) { Service.IProvider.IAuthorizationServices services = new Service.Provider.AuthorizationServices(); users = services.EmailAuthenticate(wuser.CommpanyEmail, model.Password); if (users != null) //验证通过 { username = wuser.EamilUsername; } else { IsLogin = "******"; } } var cuser = Data.ExamUsersFromehr.Get_ExamUsersFromehr(new { EamilUsername = model.UserName }); if (cuser != null) { var acc = "acn\\" + cuser.EamilUsername.Trim(); SplitAccount = acc.Split('\\'); username = cuser.EamilUsername; } if (cuser != null) { if (SplitAccount.Length > 1) { String adPath = ""; //Fully-qualified Domain Name switch (SplitAccount[0].ToLower().Trim()) { case "acn": adPath = "LDAP://acn.advantech.corp"; //acn break; case "aeu": adPath = "LDAP://aeu.advantech.corp"; //advantech break; case "aus": adPath = "LDAP://aus.advantech.corp"; //advantech break; case "advantech": adPath = "LDAP://advantech.corp"; //advantech break; default: adPath = "LDAP://acn.advantech.corp"; //acn break; } LdapAuthentication adAuth = new LdapAuthentication(adPath); string password = model.Password.Trim(); if (true == adAuth.IsAuthenticated(SplitAccount[0], SplitAccount[1], model.Password)) { Service.IProvider.IAuthorizationServices service = new Service.Provider.AuthorizationServices(); users = service.Authenticate(username, model.Password); } else { IsLogin = "******"; } } } if (wuser == null && cuser == null) { IsLogin = "******"; } if (string.IsNullOrEmpty(IsLogin) && !string.IsNullOrEmpty(users.username)) { SetUserAuthIn(users.username.ToString(), users.password, string.Empty, false); //写入Cookie,无需登入。 var LF = Guid.NewGuid().ToString(); //写内存 Manager.Login.Lock_Flag = LF; //写本地 Utils.WriteCookie("ALock", LF); users.msn = LF; advt.Data.advt_users.Update_advt_users(users, null, new string[] { "id" }); XUtils.WriteUserCookie(users, model.CookieTime ?? 0, Config.BaseConfigs.Passwordkey, 1); IsLogin = "******"; } } } catch (Exception ex) { return(Json(new { IsLogin = ex.Message }, JsonRequestBehavior.AllowGet)); throw; } //ModelState.AddModelError("", "用户名或者密码错误!"); return(Json(new { IsLogin }, JsonRequestBehavior.AllowGet)); }
public LoginController(View.Login viewlogin) { this.viewlogin = viewlogin; modellogin = new Model.LoginModel(); }