I am creating a new user on the site. User must be active. I must send an activation email to the registered email address with a link to activate the account. This link must be encrypted so that it cannot be intercepted. When the user clicks the link and the system activates the account and registers it. My table usercontains:
ID
Username
Password
ContactInfoID
AddressID
Role
My table ContactInformation:
ID
Email
Tel
Cell,
Fax,
Name
Surname
user.ContactInfoID- this is my field ContactInformation.ID.
This is how I add the user:
UserEmailCompare ma = new UserEmailCompare();
ma.email = db.ContactInformations.Where(x => x.EMail != null).Select(x => x.EMail);
if (model.Password != model.PasswordCheck)
{
return ErrorResponse("The password you have entered does not match");
}
else
{
if (ma.email.Contains(model.Email))
{
return ErrorResponse("The e-mail address you have entered has already been registered");
}
else
{
if (ModelState.IsValid)
{
User user;
ContactInformation info;
info = new ContactInformation()
{
EMail = model.Email
};
db.ContactInformations.Add(info);
db.SaveChanges();
var only = db.ContactInformations.FirstOrDefault(x => x.EMail == model.Email).ID;
if (model.UserID == 0)
{
user = new User()
{
Username = model.Username,
Password = Globals.CreateHashPassword(model.Password),
ContactInfoID = only
};
db.Users.Add(user);
}
}
}
}
Can anyone help me go further. I have classes for sending email.
source
share