private async Task PopulateLoyaltyPointAsync() { // var g = new Global(); var ls = new LoginJson(); // Task.Run(() => _authenticationService.AuthenticateUser(username, password)); ls = await Task.Run(() => _userClientService.GetLoyatyData(Global.GetUserId())); // bar.imgbarcode = "business_growth_executive_red.png"; // var renderer = Platform.CreateRenderer(TopBarPage.SelectedPage); // Image e = Umbrella.Controls.BarcodeImage; // bar.setBarcode("business_growth_executive_red.png"); // var obj = JObject.Parse(rest.Content); System.Diagnostics.Debug.WriteLine("Back barcode " + ls.barcode); System.Diagnostics.Debug.WriteLine("Back points " + ls.points); Global.SetLoyaltyPoints(ls.points); Global.SetBarCodeString(ls.barcode); System.Diagnostics.Debug.WriteLine("Global barcode " + Global.GetBarCodeString()); System.Diagnostics.Debug.WriteLine("Global points " + Global.GetLoyaltyPoints()); // await lblLoyaltyPoints.Text = ls.points; imgbarcode.Source = Global.GetBarCodeString(); System.Diagnostics.Debug.WriteLine("lblLoyaltyPoints " + lblLoyaltyPoints.Text); System.Diagnostics.Debug.WriteLine("imgbarcode.Source " + imgbarcode.Source); //imgbarcode.source = ""; //imgbarcode.//imgbarcode. // Global.SetBarCodeString( "business_growth_executive_red.png"); // BarcodeImage.* }
public JsonResult IsValidUser(string username, string password) { User user = UserDAO.Instance.GetByUsername(username); LoginJson json = new LoginJson(); if (user == null) { json.Error = "fail"; json.Message = "Tài khoản không tồn tại"; } else if (!user.Password.Equals(password)) { json.Error = "fail"; json.Message = "Mật khẩu không đúng"; } else { Session[Constants.SESSION_USER] = user; json.Error = "success"; if (user.UserGroupId.Equals("CUSTOMER")) { json.Message = "/Client/Home/Index"; } else { json.Message = "/Admin/Home/Index"; } } return(Json(json)); }
private void loginButton_Click(object sender, RoutedEventArgs e) { LoginServiceClient loginClient = new LoginServiceClient("LoginEndpoint"); LoginJson json = new LoginJson { Login = LoginTextBox.Text, Password = PasswordBox.Password }; try { LoginFailedLabel.Visibility = Visibility.Hidden; loginClient.Login(json); var productList = new ProductList(); productList.Show(); Close(); } catch (MessageSecurityException) { LoginFailedLabel.Visibility = Visibility.Visible; } }
public void SignIn(string username, string password, bool rememberUser, Action <User> onSuccess, Action <Core.Error> onError) { var loginData = new LoginJson(username, password, rememberUser); string proxy = XsollaSettings.UseProxy ? "proxy/" : string.Empty; string url = GetUrl(URL_USER_SIGNIN, proxy); WebRequestHelper.Instance.PostRequest <LoginResponse, LoginJson>(url, loginData, (response) => { if (rememberUser) { SaveLoginPassword(username, password); } Token = ParseUtils.ParseToken(response.login_url); if (XsollaSettings.UseJwtValidation) { ValidateToken(Token, onSuccess, onError); } else { onSuccess?.Invoke(new User()); } }, onError, Core.Error.LoginErrors); }
public ILogin Map_LoginJSON_To_DTO(LoginJson loginJson) { return(new Login() { EmailId = loginJson.EmailId, Password = loginJson.Password }); }
public async Task <IActionResult> Login([FromBody] LoginJson loginJson) { var tokenValue = await accountRepository.Login(loginJson); if (tokenValue.GetType() == typeof(String)) { return(Ok(new { token = tokenValue })); } return(new BadRequestResult()); }
public int Login(LoginJson json) { var user = userRepository.FindByLoginAndPassword(json.Login, json.Password); if (user == null) { throw new WebFaultException(HttpStatusCode.Unauthorized); } Debug.Assert(WebOperationContext.Current != null, "WebOperationContext.Current != null"); WebOperationContext.Current.OutgoingResponse.Headers.Add(Authorization.AuthToken, Authorization.GenerateToken(json.Login, json.Password)); return(user.Id); }
public async Task <String> Login(LoginJson loginModel) { var user = await userManager.FindByEmailAsync(loginModel.Email); var result = await signInManager.PasswordSignInAsync(user.UserName, loginModel.Password, false, false); if (result.Succeeded) { var appUser = userManager.Users.FirstOrDefault(u => u.Email == user.Email); return(GenerateJwtToken(user.Email, appUser)); } return(null); }
public async Task <LoginJson> GetLoyatyData(string partner_id) { var ls = new LoginJson(); var client = new RestSharp.RestClient($"{UmbrellaApi.SCHEME}://{UmbrellaApi.API_HOST_URL}/loyalt_ycard/"); // var client = new RestSharp.RestClient("http://mastereman.com/firebase/qr.php"); var request = new RestRequest(Method.POST); request.AddParameter("partner_id", partner_id); request.AddHeader("umbrella-api-username", UmbrellaApi.USERNAME); request.AddHeader("umbrella-api-key", UmbrellaApi.PASSKEY); request.AddHeader("umbrella-partner-id", UmbrellaApi.PARTNER_ID); EventWaitHandle Wait = new AutoResetEvent(false); var asyncHandle = client.ExecuteAsync <LoginJson>(request, response => { System.Diagnostics.Debug.WriteLine(response.Content); try { var json = response.Content.Replace("<", ""); ls = JsonConvert.DeserializeObject <LoginJson>(json); } catch (InvalidCastException e) { System.Diagnostics.Debug.WriteLine("ERRor : " + e.ToString()); } Wait.Set(); }); Wait.WaitOne(); if (ls.points == "0") { System.Diagnostics.Debug.WriteLine("NULL if Stat" + ls.points); return(null); } else { System.Diagnostics.Debug.WriteLine("else Stat" + ls.points); //u.Registered = ""; System.Diagnostics.Debug.WriteLine("u.Id " + ls.barcode); return(ls); } }
public async Task <JsonResult> login([FromBody] LoginJson data) { int id = await cache.user.requestUserLogin(data.email, data.password); if (id != -1) { CookieOptions option = new CookieOptions(); option.Expires = new DateTimeOffset?(DateTime.Now.AddDays(5)); var auth = Guid.NewGuid().ToString(); Response.Cookies.Append("auth", auth, option); await cache.user.onUserLogin(id, auth); return(Json(new { success = true, auth = auth })); } return(Json(new { success = false, message = "Wrong password." })); }
/// <summary> /// 根据token进行登录验证 /// </summary> public IEnumerator LoginPost(string token) { WWWForm form = new WWWForm(); form.AddField("token", token); WWW www = new WWW(Constant.BaseUrl + uri, form); yield return(www); if (www.error != null) { Debug.Log(www.error); IsOffInternet = true; yield return(null); } else { LoginJson loginJson = JsonTool.JsonToClass <LoginJson> (www.text); if (loginJson == null) { IsOffInternet = true; } else { Debug.Log(www.text); if (loginJson.status == Constant.Status_OK) { result = loginJson.resp; IsLoginSucceess = true; } } } IsDone = true; }
public HttpResponseMessage LogIn([FromBody] LoginJson loginJson) { #if DEBUG loginJson = new LoginJson() { EmailId = "*****@*****.**", Password = "******" }; #endif try { if (loginJson == null) { throw new ArgumentNullException("loginJson"); } if (string.IsNullOrEmpty(loginJson.EmailId)) { throw new ArgumentNullException("Emaild"); } if (string.IsNullOrEmpty(loginJson.Password)) { throw new ArgumentNullException("Password"); } PeopleJSON user = new PeopleControllerHelper().Map_PeopleDTO_To_JSON(_peopleService.LogIn(new LoginControllerHelper().Map_LoginJSON_To_DTO(loginJson))); return(Request.CreateResponse(HttpStatusCode.OK, user)); } catch (Exception ex) { _logger.Error(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public async Task <User> AuthenticateToAPI(string username, string password, AuthenticationType authType) { var ls = new LoginJson(); ls.status = "empty"; var Error = AuthenticationStatus.ServerError; var client = new RestSharp.RestClient($"{UmbrellaApi.SCHEME}://{UmbrellaApi.API_HOST_URL}/validateaccount/"); // var client = new RestSharp.RestClient("http://mastereman.com/restful/"); var request = new RestRequest(Method.POST); request.AddParameter("email", username); request.AddParameter("password", password); request.AddParameter("Type", "army"); request.AddHeader("umbrella-api-username", UmbrellaApi.USERNAME); request.AddHeader("umbrella-api-key", UmbrellaApi.PASSKEY); request.AddHeader("umbrella-partner-id", UmbrellaApi.PARTNER_ID); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); // var response = client.Execute(request, cts.Token); EventWaitHandle Wait = new AutoResetEvent(false); var asyncHandle = client.ExecuteAsync <LoginJson>(request, response => { System.Diagnostics.Debug.WriteLine(response.Content); try { System.Diagnostics.Debug.WriteLine("ResponseStatus " + response.ResponseStatus); /* if(response.Content.Contains("<div>")){ * System.Diagnostics.Debug.WriteLine("Pre "); * System.Diagnostics.Debug.WriteLine("Failed : "); * ls.status = "false"; * }else{ */ try { var json = response.Content.Replace("<", ""); ls = JsonConvert.DeserializeObject <LoginJson>(json); } catch (FormatException fex) { //Invalid json format System.Diagnostics.Debug.WriteLine(fex); System.Diagnostics.Debug.WriteLine("FormatException : "); ls.status = "ServerError"; } catch (Exception ex) //some other exception { System.Diagnostics.Debug.WriteLine(ex.ToString()); System.Diagnostics.Debug.WriteLine("Exception : " + ex.Message); ls.status = "ServerError"; } // } Wait.Set(); } catch (InvalidCastException e) { System.Diagnostics.Debug.WriteLine("ERRor : " + e.ToString()); } // status = ls.Status; // email = ls.Email; System.Diagnostics.Debug.WriteLine("ls.status " + ls.status.ToString()); // StopBusyIndicator(); }); Wait.WaitOne(); System.Diagnostics.Debug.WriteLine("Finish asyncHandle"); if (ls == null || ls.status == "ServerError") { System.Diagnostics.Debug.WriteLine("ServerError"); User u = new User(); //u.Username = username; //u.Email = username; u.AuthenticationStatus = AuthenticationStatus.ServerError; return(u); } else if (ls != null && ls.status == "false") { System.Diagnostics.Debug.WriteLine("NULL if Stat" + ls.status); User u = new User(); //u.Username = username; //u.Email = username; u.AuthenticationStatus = AuthenticationStatus.AuthenticationFailed; return(u); // return null; } else { System.Diagnostics.Debug.WriteLine("else Stat" + ls.status); User u = new User(); u.Username = username; u.Email = username; // = int.TryParse(ls.partner_id); u.AuthenticationStatus = AuthenticationStatus.AuthenticationSuccess; if (Int32.TryParse(ls.partner_id, out int j)) { // Console.WriteLine(j); u.Id = j; } u.FirstName = ""; u.LastName = ""; u.Nickname = ""; u.DisplayName = ""; u.Description = ""; //u.Registered = ""; System.Diagnostics.Debug.WriteLine("u.Id" + u.Id); System.Diagnostics.Debug.WriteLine("u.Email" + u.Email); System.Diagnostics.Debug.WriteLine("Returned" + ls.status); return(u); } }
public static string GetAuthKey(String Username, String Password, String LoginQueue) { StringBuilder sb = new StringBuilder(); string payload = "user="******",password="******"payload=" + payload; WebRequest authRequest = WebRequest.Create(LoginQueue + "login-queue/rest/queue/authenticate"); authRequest.Method = "POST"; Stream authOutput = authRequest.GetRequestStream(); authOutput.Write(Encoding.ASCII.GetBytes(query), 0, Encoding.ASCII.GetByteCount(query)); WebResponse authResponse = authRequest.GetResponse(); Stream authInput = authResponse.GetResponseStream(); int c; while ((c = authInput.ReadByte()) != -1) { sb.Append((char)c); } authOutput.Close(); authInput.Close(); authRequest.Abort(); authResponse.Close(); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(sb.ToString()); //Do we have to wait in queue? if ((string)deserializedJSON["status"] == "LOGIN") { LoginJson deserializedLogin = serializer.Deserialize <LoginJson>(sb.ToString()); return(deserializedLogin.token); } else if ((string)deserializedJSON["status"] == "FAILED") { string reason = (string)deserializedJSON["reason"]; Console.WriteLine("Failed to logging in: " + reason); } else if ((string)deserializedJSON["status"] == "QUEUE") { QueueJson deserializedLogin = serializer.Deserialize <QueueJson>(sb.ToString()); //Read URL WebClient client = new WebClient(); while (true) { int id = 0; int cur = 0; //Get our node foreach (QueueTicker ticker in deserializedLogin.tickers) { //Find our queue if (ticker.node == deserializedLogin.node) { id = ticker.id; cur = ticker.current; break; } Console.WriteLine("In login queue #" + (id - cur).ToString()); //Request the queue until there's only 'rate' left to go while (id - cur > deserializedLogin.rate) { //Sleep until the queue updates System.Threading.Thread.Sleep(deserializedLogin.delay); //Request queue infos string queueInfo = null; GetQueue: try { queueInfo = client.DownloadString(LoginQueue + "login-queue/rest/queue/ticker/" + deserializedLogin.champ); } catch (Exception e) { System.Threading.Thread.Sleep(deserializedLogin.delay); goto GetQueue; } //Get cur position Dictionary <string, object> deserializedQueue = serializer.Deserialize <Dictionary <string, object> >(queueInfo); cur = (int)deserializedQueue[deserializedLogin.node.ToString()]; Console.WriteLine("#" + (id - cur).ToString()); } } //Console.WriteLine("Getting token..."); TryAgain :; try { string authResp = client.DownloadString(LoginQueue + "login-queue/rest/queue/authToken/" + Username.ToLower()); deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(authResp); string status = (string)deserializedJSON["status"]; //System.Threading.Thread.Sleep(1000); if (status == "JOIN") { return((string)deserializedJSON["token"]); break; } } catch (Exception e) { System.Threading.Thread.Sleep(500); goto TryAgain; } } } else { Console.WriteLine("..."); return(GetAuthKey(Username, Password, LoginQueue)); } return(null); }