0

I have an user class in asp.net web form application:

public int ID { get; set; }
public string UserName { get; set; }
public byte[] Password { get; set; }
public string Mail { get; set; }
public string AvatarURL { get; set; }
public Status Status { get; set; } = Status.NotConfirmed;
public Guid ConfirmationGuid { get; set; }
public DateTime RegistrationDate { get; set; } = DateTime.Today;

Status property is an enum:

public enum Status : byte {
    NotConfirmed,
    Active,
    Blocked,
    Deactivated
}

when the user signs up, its status is NotConfirmed, new Guid for this user is generated and activation link is sent to email. I`d like to remove user record from database if he/she not confirms email in 1 hour. Can you please give me a hint, how to do that?

Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27
  • 1
    Create a scheduled job in the database, the OS or using eg Hangfire that deletes all entries older than that specific threshold. – Panagiotis Kanavos Jun 04 '19 at 11:32
  • Do you really need to delete anything? It will certainly be cheaper to not implement this, and instead, just store timestamps/other indicators with the original entry that allow you to programmatically deduce whether or not the conditions have been fulfilled when the user attempts to login/confirm. – spender Jun 04 '19 at 11:39
  • Just on a point of usability, an hour seems overly harsh. What's the reason for such a tight deadline? I predict you'll annoy a fair few users with that. A week or two would be more reasonable IMHO. Lots of simple/common things could cause an hour's delay - your email service experiences delays, user's email account has issues, user loses signal, gets distracted, has to work on something else, or many other things. – ADyson Jun 04 '19 at 11:42

2 Answers2

2

Add a user created timestamp to DB and a scheduled task that removes all users from DB with status == NotConfirmed and creation time + 1 hour older than current time.

Iwavenice
  • 556
  • 5
  • 22
1

If you are using Mysql to store the user information, look at MySQL events.

If you are using MsSQL, look for SQL Jobs and schedule it.

And delete all users that are set to not confirmed and registration time is more than an hour ago.

This way your data is not dependant on any other application to clear the data.

Bradley Petersen
  • 155
  • 1
  • 10