public IHttpActionResult KineticLogin([FromBody] LoginArguments args) { try { LoginResponse result = GetLoginResponse(); return(Ok(result)); } catch (Exception ex) { _logger.LogError(ex, "Error attempting to log in Kinetic Console user."); return(InternalServerError()); } }
public IHttpActionResult Login([FromBody] LoginArguments loginArgs) { try { LoginResponse result = GetLoginResponse(); return(Ok(result)); } catch (Exception ex) { _logger.LogError(ex, "Error attempting to log in user."); return(InternalServerError()); // Don't return specific error, user not authenticated yet. } }
public ActionResult Login(LoginArguments args) { if (ModelState.IsValid) { var user = this.Bus.FindOneWhere <User, LoggedUser>(args); if (user != null) { user.LoginTime = DateTime.Now; MvcClient.Identity = user; return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("Model", "账号或密码错误。"); } return(View(args)); }
public ActionResult Login(LoginArguments args) { if (ModelState.IsValid) { if (args.Password == "123456") { MvcClient.Identity = new User() { Username = args.Username, LoginTime = DateTime.Now }; return(RedirectToAction("Index")); } ModelState.AddModelError("Model", "账号或密码错误"); } return(View(args)); }
public async Task <IActionResult> Login([FromBody] LoginArguments arguments) { // 初次/重置后,登陆自动初始化系统 if (!SystemManager.Initialized) { await SystemManager.InitializeAsync(); } var user = await AccountManager.LoginAsync(arguments.Username, arguments.Password, JwtManager); if (user == null) { return(ApplicationError("用户名或密码错误。")); } await SignInManager.SignInAsync(await UserManager.FindByIdAsync(arguments.Username), arguments.RememberMe); return(Json(user)); }
public static String RetrieveAuthToken(LoginArguments loginArgs) { if (String.IsNullOrWhiteSpace(loginArgs.Username) || String.IsNullOrWhiteSpace(loginArgs.Password)) { throw new ArgumentException("Invalid username and/or password."); } LoginData loginData = VerifyLogin(loginArgs.Username, loginArgs.Password); String loginToken = new JwtBuilder() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSecret(_serverToken) .AddClaim("exp", loginData.ExpirationSeconds) .AddClaim("userid", loginData.UserId) .AddClaim("name", loginData.UserDisplayName) .Build(); return(loginToken); }
public static bool Authorize(LoginArguments arguments) { return(Program.config.root.username == arguments.username && Program.config.root.password == arguments.password); }
public bool Login([FromBody] LoginArguments loginArguments) { return(Authorize(loginArguments)); }
public override void OnAuthorization(HttpActionContext actionContext) { Boolean allowAnonymous = actionContext.ActionDescriptor.GetCustomAttributes <System.Web.Http.AllowAnonymousAttribute>().Count > 0 || actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes <System.Web.Http.AllowAnonymousAttribute>().Count > 0; if (!allowAnonymous) { CurrentSessionHandler session = new CurrentSessionHandler(HttpContext.Current.Session); try { LoginArgs loginArgs; String authToken = null; // Get request body object using (StreamReader sr = new StreamReader(actionContext.Request.Content.ReadAsStreamAsync().Result)) { sr.BaseStream.Position = 0; String srStr = sr.ReadToEnd(); _logger.LogInfo(srStr); loginArgs = JsonConvert.DeserializeObject <LoginArgs>(srStr); if (!String.IsNullOrWhiteSpace(loginArgs?.Token)) { _logger.LogInfo("Logging in Kinetic Console user with token..."); authToken = loginArgs.Token; } } // ReSharper disable once ConstantConditionalAccessQualifier if ((String.IsNullOrWhiteSpace(loginArgs?.Username) || String.IsNullOrWhiteSpace(loginArgs.Password)) && String.IsNullOrWhiteSpace(loginArgs?.Token)) { SetUnauthorized(actionContext, session); } else { if (authToken == null) { LoginArguments loginArguments = new LoginArguments(); loginArguments.Username = loginArgs.Username; loginArguments.Password = loginArgs.Password; authToken = AccountRepo.RetrieveAuthToken(loginArguments); } LoginData loginData = AccountRepo.GetLoginData(authToken); _logger.LogInfo($"LoginData retrieved: {JsonConvert.SerializeObject(loginData)}"); String[] userRoles = AccountRepo.GetKcUserPermissions(loginData.UserId).ToArray(); _logger.LogInfo($"User Roles retrieved: {JsonConvert.SerializeObject(userRoles)}"); Boolean userAuthorized = false; if (!String.IsNullOrWhiteSpace(authToken)) { session.LMRoles = userRoles; userAuthorized = session.HasRoles(RequiredRoles); if (!userAuthorized) { _logger.LogWarning($"User does not have required roles.\r\n\tRequired Roles: {JsonConvert.SerializeObject(RequiredRoles)}"); } } else { _logger.LogWarning("User has invalid auth token"); } if (userAuthorized) { // Give IIS a few seconds to create the session ID if it hasn't already been created CookieHeaderValue sessionId = null; Int32 tryCt = 0; while (tryCt < 10) { sessionId = actionContext.Request.Headers.GetCookies("ASP.NET_SessionId").FirstOrDefault(); if (sessionId != null) { break; } Thread.Sleep(500); tryCt++; } if (sessionId == null) { _logger.LogWarning("Unable to find ASP.NET SessionId"); SetUnauthorized(actionContext, session); } else { User user = AccountRepo.GetKcUser(loginData.UserId); LMUser lmUser = new LMUser(); lmUser.AuthToken = authToken; lmUser.TokenExpiresUtc = DateTime.UtcNow.AddSeconds(loginData.ExpirationSeconds); lmUser.IsAuthenticated = true; lmUser.UserName = loginData.UserId; lmUser.Roles = userRoles; lmUser.SessionId = sessionId["ASP.NET_SessionId"].Value; lmUser.DomainId = user.DomainId; lmUser.DomainName = Caching.GetDomainName(user.DomainId); session.AuthToken = authToken; session.TokenExpiresUtc = DateTime.UtcNow.AddSeconds(loginData.ExpirationSeconds); session.IsAuthenticated = true; session.Username = loginData.UserId; session.DomainId = user.DomainId; // Remove DomainUser if exists so Signal-R connection ID for this user is reset. DomainUsersHandler.RemoveDomainUser(lmUser.UserName); // Add new DomainUser DomainUsersHandler.AddDomainUser(user.DomainId, lmUser); _logger.LogInfo($"User '{lmUser.UserName}' successfully logged in"); _logger.LogInfo($"User Info: {JsonConvert.SerializeObject(lmUser)}"); base.OnAuthorization(actionContext); } } else { SetUnauthorized(actionContext, session); _logger.LogWarning($"User does not have required permissions. Required roles: {JsonConvert.SerializeObject(RequiredRoles)}"); } } } catch (Exception ex) { SetUnauthorized(actionContext, session); actionContext.Response.Headers.Add("Error", ex.Message); _logger.LogError(ex, "Error authenticating user"); if (ex.InnerException != null) { actionContext.Response.Headers.Add("ErrorInner", ex.InnerException.Message); _logger.LogError(ex.InnerException, "Error authenticating user (Inner Exception)"); } } } }
public void btnLogin_OnClick() { //These will be used in order to validate the text. Username = txt_username.text; Password = txt_password.text; txtMessage.text = ""; if ((Username.Contains("/") || Username.Contains("'") || Username.Contains(" ") || Username.Contains("$")) || Password.Contains("/") || Password.Contains("'") || Password.Contains(" ") || Password.Contains("$")) { txtMessage.text = "Invalid Username or Password"; } else { if (!string.IsNullOrEmpty(txt_password.text) && !string.IsNullOrEmpty(txt_username.text)) { LoginArguments loginArguments = new LoginArguments { UserId = Username, Password = Password }; Debug.Log(loginArguments.UserId); Debug.Log(loginArguments.Password); //translate to Json string json = JsonUtility.ToJson(loginArguments); Debug.Log(json); //Add Json Flag JsonEntity jsonEntity = new JsonEntity(); jsonEntity.JsonFlag = "LoginRequest"; jsonEntity.JsonObject = json; string flaggedJson = JsonUtility.ToJson(jsonEntity); Debug.Log(jsonEntity); //Establish the connection //Send loginArguments to server. LoginCommunication serverCommunication = new LoginCommunication(); string Log = serverCommunication.SendDataToServer(flaggedJson); Debug.Log(Log); txtMessage.text = Log; LoginCommunication serverCommunication2 = new LoginCommunication(); ServerResponse = serverCommunication2.ReceiveDataFromServer(); int a = Convert.ToInt32(ServerResponse); if (a == 1) { txtMessage.text = "Login Succesful"; SceneManager.LoadScene("MainMenu"); //Load Main Scene } else if (a == 0) { txtMessage.text = "Unable to create the teamcenter session"; //Stay in the Login Scene } else { Debug.Log("There is a connection Error"); } /*if (txt_username.text.Equals("e1") && txt_password.text.Equals("123hm123")) * { * Debug.Log("Login Successful."); * txtMessage.text = "Login" + "Successful"; * //redirect to the other scene * } * else * { * Debug.Log("Error: Username and password do not match."); * txtMessage.text = "Error: Username and password do not match."; * }*/ } else { Debug.Log("Error: Username and password can not be empty."); txtMessage.text = "Error: Username and password can not be empty."; } /* * LoginArguments loginArguments = new LoginArguments(); * loginArguments.UserId = Username; * loginArguments.Password = Password; * * //translate to Json * string json = JsonUtility.ToJson(loginArguments); * * //Establish the connection * //Send loginArguments to server. * ServerCommunication serverCommunication = new ServerCommunication(); * ServerResponse = serverCommunication.SendDataToServer(json); * * //If serverResponse == true, show main page * * //TODO * * * //If success, display main page * SceneManager.LoadScene("MainMenu");*/ } }