//[ValidateAntiForgeryToken] public async Task <JsonResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CompanyId = model.CompanyId, RoleName = model.RoleName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var roles = new Models.UserRoles { UserId = user.Id, RoleId = model.RoleName }; UnitOfRoleTable.Save(roles); //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(Json(new { success = true })); } AddErrors(result); return(Json(ModelState.Values.SelectMany(m => m.Errors) .Select(e => e.ErrorMessage) .ToList() )); } // If we got this far, something failed, redisplay form return(Json(model)); }
public async Task <ActionResult> UserRegister(RegisterModel model, HttpPostedFileBase Upload, string cbxRequestType) { DataTable dtUsers = new DataTable(); ViewBag.CompanyName = model.CompanyName; string UploadFileName = ""; model.RequestType = cbxRequestType; if (cbxRequestType == "Individual") { model.Upload = "No File"; model.PasswordName = model.Password; model.ConfirmPasswordName = model.ConfirmPassword; if (ModelState.IsValid) { // Attempt to register the user var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { Models.DBContext dbContext = new Models.DBContext(); Models.UserRoles usr = new Models.UserRoles(); usr.UserId = model.UserName; usr.Role = model.Roles.Replace("Planner", "Player"); usr.CompanyName = model.CompanyName; usr.Email = model.Email; dbContext.UserRoles.Add(usr); dbContext.SaveChanges(); try { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = model.Email, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "'> " + "link" + "</a>"; //HTML Template for Send email string subject = "Login Created"; string body = "<b>Dear " + model.UserName + ", </b><br/><br/>"; body = body + "<b>Your login credentials created, Kindly change the pasword at the earliest" + lnkHref + "</b><br/>"; body = body + "<b>User Name : " + model.UserName + "</b><br/>";; body = body + "<b>Password : "******"</b><br/>";; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>" + model.CompanyName + "Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); } catch (Exception ex) { UploadFileName += model.UserName + " email not sent to this user(" + ex.Message + ")\n"; } } else { UploadFileName += result.Errors.First() + "\n"; } if (UploadFileName == "") { UploadFileName = "User Successfuly loaded."; } ViewBag.ErrorMessage = UploadFileName; } } else if (cbxRequestType == "Mass") { string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = Upload.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = Upload.FileName; } // Get the complete folder path and store the file inside it. fname = Path.Combine(Server.MapPath("~/App_Data/Uploads/"), fname); Upload.SaveAs(fname); ExcelAPI API = new ExcelAPI(); API.CreateDataTableFromExcel(fname, dtUsers); foreach (DataRow dr in dtUsers.Rows) { model.UserName = dr["Name"].ToString(); model.Email = dr["Email"].ToString(); model.Roles = dr["Roles"].ToString(); model.Password = model.PasswordName; model.ConfirmPassword = model.ConfirmPasswordName; // Attempt to register the user var user = new ApplicationUser { UserName = dr["Name"].ToString(), Email = dr["Email"].ToString(), CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.PasswordName); if (result.Succeeded) { Models.DBContext dbContext = new Models.DBContext(); Models.UserRoles usr = new Models.UserRoles(); usr.UserId = model.UserName; usr.Role = model.Roles.Replace("Planner", "Player"); usr.CompanyName = model.CompanyName; usr.Email = model.Email; dbContext.UserRoles.Add(usr); dbContext.SaveChanges(); try { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = model.Email, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "'> " + "link" + "</a>"; //HTML Template for Send email string subject = "Login Created"; string body = "<b>Dear " + model.UserName + ", </b><br/><br/>"; body = body + "<b>Your login credentials created, Kindly change the pasword at the earliest" + lnkHref + "</b><br/>"; body = body + "<b>User Name : " + model.UserName + "</b><br/>";; body = body + "<b>Password : "******"</b><br/>";; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>" + model.CompanyName + "Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); } catch (Exception ex) { UploadFileName += model.UserName + " email not sent to this user(" + ex.Message + ")\n"; } } else { UploadFileName += result.Errors.First() + "\n"; } } if (UploadFileName == "") { UploadFileName = "Users Successfuly loaded."; } ViewBag.ErrorMessage = UploadFileName; } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterModel model, string cbxDataPrivacy) { if (cbxDataPrivacy == "on") { Models.DBContext dbContext = new Models.DBContext(); Models.CompanyDetails cmp = new Models.CompanyDetails(); var FindCompany = (from d in dbContext.Company where d.CompanyName == model.CompanyName select new { d.CompanyName }).ToList(); string wcCompanyName = ConfigurationManager.AppSettings["wcCompanyName"].ToString(); var INI = (from ini in dbContext.InitializeTables where ini.Authentication.ToUpper() == "WINDOWS" && ini.CompanyName == wcCompanyName select ini).FirstOrDefault(); if (INI != null) { string[] WindowsUser = Request.LogonUserIdentity.User.ToString().Split('\\'); string WindowUserName = WindowsUser[0]; if (WindowsUser.Length >= 2) { WindowUserName = WindowsUser[1]; } model.UserName = WindowUserName; } if (ModelState.IsValid) { // Attempt to register the user if (FindCompany.Count == 0) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, CompanyName = model.CompanyName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { cmp.CompanyName = user.CompanyName; cmp.EmailID = user.Email; cmp.UserName = user.UserName; cmp.Logo = null; dbContext.Company.Add(cmp); Models.UserRoles usr = new Models.UserRoles(); usr.UserId = model.UserName; usr.Role = model.Roles; usr.CompanyName = user.CompanyName; usr.Email = model.Email; dbContext.UserRoles.Add(usr); dbContext.SaveChanges(); using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = 0; cmd.CommandText = "PROC_CONFIGURE_COMPANY"; cmd.Parameters.Add("@CURRENT_COMPANY", SqlDbType.VarChar, 500).Value = ConfigureCompany; cmd.Parameters.Add("@CONFIGURE_COMPANY", SqlDbType.VarChar, 500).Value = user.CompanyName; Common csobj = new Common(); csobj.SPReturnDataTable(cmd); } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string EMail = ConfigurationManager.AppSettings.Get("EmailID"); string To = model.Email, UserID, Password, SMTPPort, Host; var request = HttpContext.Request; string lnkHref = "<a href='" + HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + "/Home/ApprovalList/?CustRegId=" + user.Id + "'>" + "Approval link" + "</a>"; //HTML Template for Send email string subject = "Request for Approval of subscription"; string body = "<b>Dear Admin, </b><br/><br/>"; body = body + "<b>Kindly Approve The Customer: " + user.CompanyName + " Request for enrollement.</b><br/>" + "<b>Please find the Customers list </b> : " + lnkHref; body = body + "<br/><br/><b>Thanks,</b><br/>" + "<b>Mcbitss Team.</b>"; //Get and set the AppSettings using configuration manager. EmailManager.AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. EmailManager.SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); return(Redirect("~/")); } ViewBag.ErrorMessage = result.Errors.First(); } else { ViewBag.ErrorMessage = "Company details are already added"; } } } else { ViewBag.ErrorMessage = "Please accept data privacy policy && Terms"; } // If we got this far, something failed, redisplay form return(View(model)); }