public Task AddToRoleAsync(TUser user, string roleName) { RoleDocument rol = _cosmosIdentityManage.GetRoles().Where(r => r.Name == roleName).Single(); user.Roles.Add(rol); return(Task.CompletedTask); }
//[HttpPost] //[AllowAnonymous] //[ValidateAntiForgeryToken] //public async Task<ActionResult> CreateAccount(Models.Access.CreateAccountViewModel m) //{ // if (ModelState.IsValid) // { // if (m.AgreeTerms) // { // Models.Wallet.CreateWalletModel _wallet = await new Helpers.NethereumHelper().CreateUserWallet(); // var user = new ApplicationUser { UserName = m.Email, Email = m.Email, Hometown = "", TokenAddress = _wallet.blobname, WalletAddress = _wallet.walletaddress }; // var result = await UserManager.CreateAsync(user, m.Password); // if (result.Succeeded) // { // var userRegister = UserManager.FindByEmail(user.Email); // UserManager.AddToRole(userRegister.Id, m.Role); // //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action( // "AccountVerified", "Access", // new { userId = user.Id, code = code }, // protocol: Request.Url.Scheme); // string mailContent = String.Format(new MailManager().GetMailContent(EMailType.createAccount), user.UserName, callbackUrl); // await UserManager.SendEmailAsync(user.Id, // "Confirm your email", // //"Hi, thank you for join us!<br><br>Please click the following link to verify your email address. <a href=\"" + callbackUrl + "\">link</a><br><br><br> Kind Ads" // //String.Format(GetMailBodyFromXML("createAccount"), callbackUrl) // mailContent // ); // return View("CheckEmailActivation"); // //return RedirectToAction("Index", "Home"); // } // AddErrors(result); // } // else // { // ModelState.AddModelError("", "You must accept terms and policy"); // } // } // return View(m); //} private void FillRoles() { CosmosIdentityManager manager = new CosmosIdentityManager(); var roles = manager.GetRoles(); if (roles != null && roles.Any()) { var listaUsuarios = new SelectList(roles, "Name", "Name"); Session["roles"] = listaUsuarios; } }
public ActionResult ChangeRol(string rolName) { var currentUser = UserManager.FindByName(User.Identity.Name); var rolCandidate = currentUser.Roles.FirstOrDefault(r => r.Name == rolName); if (rolCandidate != null) { currentUser.LastRolId = Convert.ToInt32(rolCandidate.Id); _cosmosIdentityManage.UpSertApplicationUser(currentUser); var authenticationManager = HttpContext.GetOwinContext().Authentication; // create a new identity from the old one var identity = new ClaimsIdentity(User.Identity); // update claim value identity.RemoveClaim(identity.FindFirst(@"http://schemas.microsoft.com/ws/2008/06/identity/claims/role")); identity.AddClaim(new Claim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", rolName)); authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant( new ClaimsPrincipal(identity), new AuthenticationProperties { IsPersistent = true } ); } string realRol = _cosmosIdentityManage.GetRoles().Single(r => r.Id == currentUser.LastRolId.ToString()).Name; if (realRol.Contains(Roles.Advertiser.ToString())) { return(RedirectToAction("Advertiser", "Marketplace")); } else if (realRol.Contains(Roles.Publisher.ToString())) { return(RedirectToAction("Publisher", "Marketplace")); } return(RedirectToAction("Login")); }
private ApplicationUser SetRol(List <AspNetRole> oldRoles, ApplicationUser user) { List <RoleDocument> defaultRoles = _cosmosIdentityManager.GetRoles(); AspNetRole primaryRole = oldRoles.FirstOrDefault(); switch (primaryRole.Name) { case "Publisher": user.PrimaryRolId = user.LastRolId = Convert.ToInt32(defaultRoles.FirstOrDefault(r => r.Name == "Publisher").Id); user.SecondaryRolId = Convert.ToInt32(defaultRoles.FirstOrDefault(r => r.Name == "Advertiser").Id); break; case "Advertiser": user.PrimaryRolId = user.LastRolId = Convert.ToInt32(defaultRoles.FirstOrDefault(r => r.Name == "Advertiser").Id); user.SecondaryRolId = Convert.ToInt32(defaultRoles.FirstOrDefault(r => r.Name == "Publisher").Id); break; } user.Roles = defaultRoles; return(user); }
public MigrateUsersToCosmosETL() { _cosmosIdentityManager = new CosmosIdentityManager(); roles = _cosmosIdentityManager.GetRoles(); }