public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { try { if (WebSecurity.UserExists(model.Email)) { ViewBag.Message = "Email Id is already exist"; return View(); } else { string Confimation_Token = WebSecurity.CreateUserAndAccount(model.Email, model.Password, new { FirstName = model.FirstName, LastName = model.LastName, IsActive = model.IsActive, EmailID = model.Email }, true); Roles.AddUserToRole(model.Email, "Customer"); if (Confimation_Token != null) { System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage( new System.Net.Mail.MailAddress("*****@*****.**", "Vishwapress Registration"), new System.Net.Mail.MailAddress(model.Email)); m.Subject = "Email confirmation"; m.Body = string.Format("Hello,<BR/><BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a><BR/><BR/>Regards,<BR/>Vishwapress Team", model.Email, Url.Action("ConfirmEmail", "Account", new { Token = Confimation_Token, Email = model.Email }, Request.Url.Scheme)); m.IsBodyHtml = true; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.vishwapress.com"); smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "DsFlTQs2"); smtp.EnableSsl = false; smtp.Send(m); return RedirectToAction("Confirm", "Account", new { Email = model.Email }); } } //Roles.AddUserToRole(model.Email, "Customer"); //WebSecurity.Login(model.Email, model.Password); //return RedirectToAction("IndexNew", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { FirstName = model.FirstName, LastName = model.LastName, EmailID = model.Email }); Roles.AddUserToRole(model.UserName, "Customer"); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("IndexNew", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }