private void RegisterAccount(NHibernate.ISession session, UserAccountEF user, string aggregatorGroupId) { switch (user.UserType) { case RegisterType.Contrator: ContractorUser cu = new ContractorUser(); cu.AggGroupId = aggregatorGroupId; cu.ContractStatus = (int)ContractStatusCodes.Signing; cu.UserId = user.Id; session.SaveAsync(cu); Task t = _userManager.AddToRoleAsync(user, UserRoleTypes.Contractor); t.Wait(); break; //case RegisterType.Supervisor: // var role_add_result = await _userManager.AddToRoleAsync(user, UserRoleTypes.Supervisor); // //_userManager.AddClaimAsync(user, new Claim()) // SupervisorUser supervisorUser = new SupervisorUserEF(); // supervisorUser.UserId = user.Id; // await _accountContext.SupervisorUsers.AddAsync(supervisorUser); // break; case RegisterType.Aggregator: Task ta = _userManager.AddToRoleAsync(user, UserRoleTypes.Aggregator); ta.Wait(); //_userManager.AddClaimAsync(user, new Claim()) AggregatorUser aggregatorUser = new AggregatorUser(); aggregatorUser.AggGroupId = aggregatorGroupId; aggregatorUser.UserId = user.Id; session.SaveAsync(aggregatorUser); break; } }
// Allow Initialization with an instance of ApplicationUser: public EditContractorUserViewModel(ContractorUser user) { this.ContractorID = user.ContractorID; this.UserName = user.UserName; this.FirstName = user.FirstName; this.LastName = user.LastName; this.Email = user.Email; }
public ActionResult UsersDeleteConfirmed(string username) { ContractorUser contractoruser = userManager.FindByName(username); if (contractoruser == null) { return(HttpNotFound()); } var result = userManager.Delete(contractoruser); if (result.Succeeded) { return(RedirectToAction("Users", "Contractors", new { id = contractoruser.ContractorID })); } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); }
public ActionResult UsersDelete(string username) { if ((username == null) || (username.ToString().Length == 0)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ContractorUser contractoruser = userManager.FindByName(username); if (contractoruser == null) { return(HttpNotFound()); } var model = new EditContractorUserViewModel((ContractorUser)contractoruser); return(View(model)); }
public async Task <ActionResult> UsersCreate(RegisterContractorUserViewModel model) { if (ModelState.IsValid) { ContractorUser user = (ContractorUser)model.GetUser(); user.ContractorID = model.ContractorID; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var resultRole = userManager.AddToRole(user.Id, "ContractorRole"); if (resultRole.Succeeded) { await workflowMessageService.SendContractorUserRegistrationNotificationMessageAsync(model); // 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>"); await workflowMessageService.SendUserRegistrationMessageAsync(userManager, user.Id, Request.Url.Scheme, Url); return(RedirectToAction("Users", "Contractors", new { id = model.ContractorID })); } else { var errors = string.Join(",", resultRole.Errors); ModelState.AddModelError(string.Empty, errors); } } else { var errors = string.Join(",", result.Errors); ModelState.AddModelError(string.Empty, errors); } } // If we got this far, something failed, redisplay form return(View(model)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> RegistTemporarySite([FromBody] RegisterSiteModel model) { //model.Email = value["Email"].ToString(); //model.Password = value["Password"].ToString(); //model.ConfirmPassword = value["ConfirmPassword"].ToString(); //model.Username if (ModelState.IsValid) { UserAccount contractor = await _userManager.FindByEmailAsync(model.ContractorEmail); if (contractor == null) { IdentityError error = (_userManager.ErrorDescriber as LocalizedIdentityErrorDescriber).ContractorNotFounded(model.ContractorEmail); IdentityResult _result = IdentityResult.Failed(error); return(BadRequest(new { Result = _result })); } ContractorUser cu = await _accountContext.ContractorUsers.FindAsync(contractor.Id); TemporaryContractorSite newSite = new TemporaryContractorSite(); newSite.Address1 = model.Address1; newSite.Address2 = model.Address2; newSite.ContractUserId = contractor.Id; newSite.Latitude = model.Latitude; newSite.Longtidue = model.Longtidue; newSite.LawFirstCode = model.LawFirstCode; newSite.LawMiddleCode = model.LawMiddleCode; newSite.LawLastCode = model.LawLastCode; newSite.ServiceCode = model.ServiceCode; newSite.RegisterTimestamp = DateTime.Now; foreach (RegisterAssetModel asset in model.Assets) { string assetName = $"{asset.Type}{asset.Index}"; TemporaryContractorAsset newAsset = new TemporaryContractorAsset(); newAsset.AssetName = assetName; newAsset.AssetType = asset.Type; newAsset.CapacityKW = asset.CapacityMW; newAsset.ContractorSite = newSite; newAsset.UniqueId = Guid.NewGuid().ToString(); await _accountContext.TemporaryContractorAssets.AddAsync(newAsset); } await _accountContext.TemporaryContractorSites.AddAsync(newSite); await _accountContext.SaveChangesAsync(); //var user = new ReservedAssetLocation //{ // AccountId = model.AccountId, // Address1 = model.Address1, // Address2 = model.Address2, // ControlOwner = model.ControlOwner, // //SiteInformation = model.SiteInformation, // RegisterTimestamp = DateTime.Now, // LawFirstCode = model.LawFirstCode, // LawMiddleCode = model.LawMiddleCode, // LawLastCode = model.LawLastCode, // ServiceCode = model.ServiceCode, // Latitude = model.Latitude, // Longtidue = model.Longtidue //}; //accountContext.ReservedAssetLocations.Add(user); //await accountContext.SaveChangesAsync(); return(Ok()); } // If we got this far, something failed, redisplay form return(BadRequest()); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> SignonContractor([FromBody] ContractorRegistModel model) { if (ModelState.IsValid) { AggregatorGroup aggregatorGroup = await _accountContext.AggregatorGroups.FindAsync(model.AggregatorId); if (aggregatorGroup == null) { IdentityError error = (_userManager.ErrorDescriber as LocalizedIdentityErrorDescriber).AggregatorNotFounded(model.AggregatorId); IdentityResult _result = IdentityResult.Failed(error); return(base.BadRequest(new { Result = _result })); } var user = CreateUserAccount(model, RegisterType.Contrator); JObject obj = JObject.FromObject(user); var result = await _userManager.CreateAsync(user, model.Password); //result.Errors if (result.Succeeded) { ContractorUser cu = new ContractorUser(); cu.AggGroupId = aggregatorGroup.ID; cu.ContractStatus = ContractStatusCodes.Signing; cu.UserId = user.Id; _accountContext.ContractorUsers.Add(cu); await _userManager.AddToRoleAsync(user, UserRoleTypes.Contractor); await _accountContext.SaveChangesAsync(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); await Publisher.PublishMessageAsync(obj.ToString(), cancellationTokenSource.Token); if (model.NotifyEmail) { string email_contents = htmlGenerator.GenerateHtml("NotifyEmail.html", new { Name = $"{user.FirstName} {user.LastName}", Company = model.Company, Email = model.Email, Phone = model.PhoneNumber, Address = model.Address, Aggregator = aggregatorGroup.AggName }); var aggregator_account_users = await _userManager.GetUsersInRoleAsync(UserRoleTypes.Supervisor); string sender = "PEIU 운영팀"; await _emailSender.SendEmailAsync(sender, "새로운 발전사업자 가입이 요청되었습니다", email_contents, aggregator_account_users.Select(x => x.Email).ToArray()); } return(Ok(new { Result = result })); //_userManager.find //if (user.AuthRoles == (int)AuthRoles.Aggregator || user.AuthRoles == (int)AuthRoles.Business) // await Publisher.PublishMessageAsync(obj.ToString(), cancellationTokenSource.Token); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); //await _signInManager.SignInAsync(user, isPersistent: false); //_logger.LogInformation(3, "User created a new account with password."); } else { return(BadRequest(new { Result = result })); } } // If we got this far, something failed, redisplay form return(BadRequest()); }