private static bool SetSession(UserDataFetcher UDF) { /* Session. unix in file. * we will hash it. * send it to server. * __________________ * check procedure: * if hash matches -> proceed * does not match -> invalid session */ if (!InputValidator.ValidateId(UDF.GetId())) { return(error.SetErrorAndReturnFalse(ErrorCode.USER_NOT_FOUND)); } //-----timestamp long unix = DataFetcher.GetServerTimeStamp(); UserDataPusher.PushSessionFileLoggedIn(unix); string hashedUnix = timestampHasher.Hash(unix.ToString(), DataFetcher.GetDeviceIdentifier()); UserDataPusher.UpdateUserSession(UDF, unix, hashedUnix); //System.Windows.Forms.MessageBox.Show($"hashedUnix: {hashedUnix} ({hashedUnix.Length})"); return(true); /* * if (UDF.GetCurrentUserTimeStamp().IsTimeStampOlderThan(7 * 24)) //^extension * //user has not been logged in for a whole week * return true; * return true; */ }
static public bool IsTimeStampOlderThan(this long timeStamp, uint hours = 0, uint minutes = 0, uint seconds = 0)//^extension { uint compareTo = hours * 60 * 60 + minutes * 60 + seconds; long now = DataFetcher.GetServerTimeStamp(); now -= timeStamp; if (now <= 0) { return(false); } if (now <= compareTo) { return(false); } return(true); }
public bool Write(string commentToShow) { error.Clear(); //validate //user if (!CurrentUser.isLoggedIn) { return(error.SetErrorAndReturnFalse(ErrorCode.INVALID_SESSION)); } if (!InputValidator.ValidateId(CurrentUser.id)) { return(error.SetErrorAndReturnFalse(ErrorCode.USER_NOT_FOUND)); } //good text if (!InputValidator.ValidateForumProblemCommentText(commentToShow)) { return(error.SetErrorAndReturnFalse(ErrorCode.INVALID_TEXT_FIELD | InputValidator.error.no)); } //valid as comment //first get timestamp long unix = DataFetcher.GetServerTimeStamp(); Comment comment = new Comment(0, CurrentUser.id, forumPost.id, commentToShow, unix); //push if (!UserDataPusher.PushNewForumProblemComment(comment)) { return(error.SetErrorAndReturnFalse(ErrorCode.PUSH_ERROR)); } //retrieve id this.lastComment = DataFetcher.GetCommentFromTemplate(comment); //changes only id comments.Add(this.lastComment); //this.LoadLast(this.commentsPanel); if (SuccessfullyAddedCommentEvent != null) { SuccessfullyAddedCommentEvent.Invoke(this, new SuccessfullyAddedCommentEventArgs(commentToShow, unix)); //invokes event if it has subscribers } return(true); }
private void LabelTest_Click(object sender, EventArgs e) { labelTest.Text = DataFetcher.GetServerTimeStamp().ToString(); }