Activation Mail for registered MVC users

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)
            { //add
                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.

+3
source share
1 answer

gmail , ,

System.Net.Mail

const string accountName = "";                             // # Gmail account name
const string password = "";                                // # Gmail account password
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient("smtp.gmail.com");

smtp.Credentails = new System.Net.NetworkCredential(accountName, password);

mail.From = new MailAddress("youremailaddress@gmail.com"); // # Remember to change here with the mail you got
mail.To.Add(model.Email);                                  // # Email adress to send activation mail
mail.Subject = "Activation Mail";
mail.Body = "Hey there, click this link for activation";   // # You will need to change here with HTML containing a link (which contains a generated activation code)
mail.IsHtml = true;

smtp.Send(mail);

. :

  • HTML , .
  • IsActive ActivationCode User
  • Guid
  • User ,
  • , ( IsActive true)
+2

All Articles