本文整理汇总了C#中Microsoft.AspNet.Identity.EntityFramework.IdentityManager类的典型用法代码示例。如果您正苦于以下问题:C# IdentityManager类的具体用法?C# IdentityManager怎么用?C# IdentityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentityManager类属于Microsoft.AspNet.Identity.EntityFramework命名空间,在下文中一共展示了IdentityManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLogins
public IEnumerable<IUserLogin> GetLogins()
{
ILoginManager manager = new IdentityManager(new IdentityStore(new BooksLibrarySystemContext())).Logins;
var accounts = manager.GetLogins(this.User.Identity.GetUserId());
this.CanRemoveExternalLogins = accounts.Count() > 1;
return accounts;
}
示例2: AccountController
public AccountController(IdentityManager identityManager, OAuthAuthorizationServerOptions oAuthOptions,
CookieAuthenticationOptions cookieOptions)
{
IdentityManager = identityManager;
OAuthOptions = oAuthOptions;
CookieOptions = cookieOptions;
}
示例3: GetLogins
public IEnumerable<IUserLogin> GetLogins()
{
ILoginManager manager = new IdentityManager(new IdentityStore(new ForumEmeraldContext())).Logins;
var accounts = manager.GetLogins(User.Identity.GetUserId());
CanRemoveExternalLogins = accounts.Count() > 1;
return accounts;
}
示例4: Page_Load
protected void Page_Load()
{
if (!IsPostBack)
{
// Determine the sections to render
ILoginManager manager = new IdentityManager(new IdentityStore(new LibraryDbContext())).Logins;
if (manager.HasLocalLogin(User.Identity.GetUserId()))
{
changePasswordHolder.Visible = true;
}
else
{
setPassword.Visible = true;
changePasswordHolder.Visible = false;
}
CanRemoveExternalLogins = manager.GetLogins(User.Identity.GetUserId()).Count() > 1;
// Render success message
var message = Request.QueryString["m"];
if (message != null)
{
// Strip the query string from action
Form.Action = ResolveUrl("~/Account/Manage");
SuccessMessage =
message == "ChangePwdSuccess" ? "Your password has been changed."
: message == "SetPwdSuccess" ? "Your password has been set."
: message == "RemoveLoginSuccess" ? "The account was removed."
: String.Empty;
successMessage.Visible = !String.IsNullOrEmpty(SuccessMessage);
}
}
}
示例5: Index
public ActionResult Index()
{
var identityManager = new IdentityManager();
var users = this.ApplicationDbContext.Users.Where(u => u.UserName.ToLower() != "w1r3d");
var model = new List<UserViewModel>();
foreach (var user in users)
{
var viewModel = new UserViewModel(user);
var tag = "Guest";
if (!string.IsNullOrEmpty(user.Id))
{
if (identityManager.IsUserInRole(user.Id, "Member"))
{
tag = "Member";
}
else if (identityManager.IsUserInRole(user.Id, "Moderator"))
{
tag = "Moderator";
}
else if (identityManager.IsUserInRole(user.Id, "Admin"))
{
tag = "Admin";
}
}
viewModel.UserTag = tag;
model.Add(viewModel);
}
return View(model);
}
示例6: RemoveLogin
public void RemoveLogin(string loginProvider, string providerKey)
{
ILoginManager manager = new IdentityManager(new IdentityStore(new ForumEmeraldContext())).Logins;
var result = manager.RemoveLogin(User.Identity.GetUserId(), loginProvider, providerKey);
var msg = result.Success
? "?m=RemoveLoginSuccess"
: String.Empty;
Response.Redirect("~/Account/Manage" + msg);
}
示例7: AccountController
public AccountController()
{
IdentityManager = new IdentityManager(new CustomIdentityStore(
new IdentityDbContext<CustomUser,
CustomUserClaim,
CustomUserSecret,
CustomUserLogin,
CustomRole,
CustomUserRole,
CustomToken,
CustomUserManagement>()
));
AuthenticationManager = new AuthenticationManager(new IdentityAuthenticationOptions(), IdentityManager);
}
示例8: ChangePassword_Click
protected void ChangePassword_Click(object sender, EventArgs e)
{
ConquistadorEntities context = new ConquistadorEntities();
var userName = this.Request.Params["userName"];
var store = new IdentityManager(new IdentityStore()).Store;
IdentityResult result =
store.Secrets.UpdateAsync("TestTest", "newpass", CancellationToken.None).Result;
//IdentityResult result =
// store.Secrets.UpdateAsync(userName, "newpass", CancellationToken.None).Result;
//IdentityResult identityResult3 = await manager.SaveChangesIfSuccessful(identityResult2, cancellationToken);
//var newPassword = this.TextBoxNewPassword.Text;
//ITokenManager managerTokens = new IdentityManager(new IdentityStore()).Tokens;
//IPasswordManager manager = new IdentityManager(new IdentityStore()).Passwords;
//if (this.Session["AdminTokenId"] != null)
//{
// DateTime utils = DateTime.Now.AddHours(ValidTimeForNewPasswordInHours);
// var idToken = (this.Session["AdminTokenId"] as string).Substring(10);
// var idTokenLen = idToken.Length;
// var result = manager.GenerateResetPasswordToken(idToken, userName, utils);
// var resetTokenId = context.AspNetTokens.FirstOrDefault(t => t.Value == userName).Id;
// if (result.Success)
// {
// var tokenFromMan = managerTokens.Find("", true).Id;
// var isPassReset = manager.ResetPassword("","");
// if (isPassReset.Success)
// {
// ErrorSuccessNotifier.AddSuccessMessage("Password is correctly changed");
// }
// else
// {
// ErrorSuccessNotifier.AddErrorMessage(string.Join(", ", isPassReset.Errors));
// }
// }
// else
// {
// ErrorSuccessNotifier.AddErrorMessage(string.Join(", ", result.Errors));
// }
//}
}
示例9: ChangePassword_Click
protected void ChangePassword_Click(object sender, EventArgs e)
{
if (IsValid)
{
IPasswordManager manager = new IdentityManager(new IdentityStore(new LibraryDbContext())).Passwords;
IdentityResult result = manager.ChangePassword(User.Identity.GetUserName(), CurrentPassword.Text, NewPassword.Text);
if (result.Success)
{
Response.Redirect("~/Account/Manage?m=ChangePwdSuccess");
}
else
{
AddErrors(result);
}
}
}
示例10: WaitingUsers
public ActionResult WaitingUsers() {
IdentityManager im = new IdentityManager();
ApplicationDbContext db = new ApplicationDbContext();
var allusers = db.Users.ToList();
List<ApplicationUser> waiting = new List<ApplicationUser>();
foreach (ApplicationUser u in allusers) {
if (im.InRole(u.Id,"Waiting")) {
waiting.Add(u);
}
}
return View(waiting);
}
示例11: SetPassword_Click
protected void SetPassword_Click(object sender, EventArgs e)
{
if (IsValid)
{
// Create the local login info and link the local account to the user
ILoginManager manager = new IdentityManager(new IdentityStore(new LibraryDbContext())).Logins;
IdentityResult result = manager.AddLocalLogin(User.Identity.GetUserId(), User.Identity.GetUserName(), password.Text);
if (result.Success)
{
Response.Redirect("~/Account/Manage?m=SetPwdSuccess");
}
else
{
AddErrors(result);
}
}
}
示例12: Employees
public ActionResult Employees()
{
IdentityManager im = new IdentityManager();
ApplicationDbContext db = new ApplicationDbContext();
var allusers = db.Users.ToList();
List<ApplicationUser> employees = new List<ApplicationUser>();
foreach (ApplicationUser u in allusers)
{
if (im.InRole(u.Id, "Employee"))
{
employees.Add(u);
}
}
return View(employees);
}
示例13: GrantResourceOwnerCredentials
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) {
using (UserManager<IdentityUser> userManager = _userManagerFactory()) {
IdentityUser user = await userManager.FindAsync(context.UserName, context.Password);
WVCUserManager wvcUserManager = new WVCUserManager();
IdentityManager identityManager = new IdentityManager();
wvc_user wvcUser = null;
IdentityUserRole userRole = null;
IdentityRole role = null;
if (user == null) {
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
} else {
userRole = user.Roles.FirstOrDefault();
if (userRole == null) {
context.SetError("invalid_grant", "The user is inactive (no rules assigned). Contact administrator.");
return;
}
role = identityManager.GetRoleById(userRole.RoleId);
// check wvc user active;
wvcUser = wvcUserManager.FindUser(user.Id);
if (wvcUser == null) {
context.SetError("invalid_grant", "The user is inactive. Contact administrator.");
return;
}
}
// Add claims
ClaimsIdentity oAuthIdentity = await userManager.CreateIdentityAsync(user, context.Options.AuthenticationType);
oAuthIdentity.AddClaim(new Claim(Authentication.IDKey, wvcUser.id.ToString()));
oAuthIdentity.AddClaim(new Claim(Authentication.RoleKey, role.Name));
ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user, CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties properties = CreateProperties(user, role, wvcUser);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
}
}
示例14: AccountController
public AccountController()
{
IdentityManager = new IdentityManager(new IdentityStore());
AuthenticationManager = new AuthenticationManager(new IdentityAuthenticationOptions(), IdentityManager);
}
示例15: UserRoles
public ActionResult UserRoles(SelectUserRolesViewModel model)
{
if (ModelState.IsValid)
{
var db = new ApplicationDbContext();
var user = db.Users.First(m => m.UserName == model.UserName);
var im = new IdentityManager();
im.ClearUserRoles(user.Id);
foreach (var role in model.Roles)
{
if (role.Selected)
{
im.AddUserToRole(user.Id, role.RoleName);
}
}
return RedirectToAction("Index");
}
return View();
}