本文整理汇总了C#中Microsoft.AspNet.Identity.EntityFramework.IdentityManager类的典型用法代码示例。如果您正苦于以下问题:C# IdentityManager类的具体用法?C# IdentityManager怎么用?C# IdentityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentityManager类属于Microsoft.AspNet.Identity.EntityFramework命名空间,在下文中一共展示了IdentityManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:stoskov,项目名称:books-library-system,代码行数:7,代码来源:Manage.aspx.cs
示例2: AccountController
public AccountController(IdentityManager identityManager, OAuthAuthorizationServerOptions oAuthOptions,
CookieAuthenticationOptions cookieOptions)
{
IdentityManager = identityManager;
OAuthOptions = oAuthOptions;
CookieOptions = cookieOptions;
}
开发者ID:shcheahgmail,项目名称:DotNetSamples,代码行数:7,代码来源:AccountController.cs
示例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;
}
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:7,代码来源:Manage.aspx.cs
示例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);
}
}
}
开发者ID:quela,项目名称:myprojects,代码行数:33,代码来源:Manage.aspx.cs
示例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);
}
开发者ID:W1R3D-Code,项目名称:TheExordium,代码行数:34,代码来源:UserAdministrationController.cs
示例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);
}
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:9,代码来源:Manage.aspx.cs
示例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);
}
开发者ID:justSteve,项目名称:Asp.Net-Identity-RC1-sample-app,代码行数:14,代码来源:AccountController.cs
示例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));
// }
//}
}
开发者ID:polinaak,项目名称:Polina-Telerik-Academy,代码行数:48,代码来源:ChangeUserPassword.aspx.cs
示例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);
}
}
}
开发者ID:quela,项目名称:myprojects,代码行数:16,代码来源:Manage.aspx.cs
示例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);
}
开发者ID:mdotz,项目名称:Biblioteka-ASP-MVC,代码行数:16,代码来源:AccountController.cs
示例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);
}
}
}
开发者ID:quela,项目名称:myprojects,代码行数:17,代码来源:Manage.aspx.cs
示例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);
}
开发者ID:mdotz,项目名称:Biblioteka-ASP-MVC,代码行数:19,代码来源:AccountController.cs
示例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);
}
}
开发者ID:karthikeyanar,项目名称:wvcnet,代码行数:39,代码来源:ApplicationOAuthProvider.cs
示例14: AccountController
public AccountController()
{
IdentityManager = new IdentityManager(new IdentityStore());
AuthenticationManager = new AuthenticationManager(new IdentityAuthenticationOptions(), IdentityManager);
}
开发者ID:Kazzje,项目名称:Asp.Net-Identity-sample-app,代码行数:5,代码来源:AccountController.cs
示例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();
}
开发者ID:shirish7151,项目名称:CIMS,代码行数:20,代码来源:AccountController.cs
示例16: CreateIdentity
public static ClaimsIdentity CreateIdentity(IdentityManager identityManager, IEnumerable<Claim> claims,
string authenticationType)
{
if (identityManager == null)
{
throw new ArgumentNullException("identityManager");
}
if (claims == null)
{
throw new ArgumentNullException("claims");
}
IdentityAuthenticationOptions options = identityManager.Settings.GetAuthenticationOptions();
return new ClaimsIdentity(claims, authenticationType, options.UserNameClaimType, options.RoleClaimType);
}
开发者ID:rusty02,项目名称:TNTT,代码行数:16,代码来源:ApplicationOAuthProvider.cs
示例17: CreatePropertiesAsync
public static async Task<AuthenticationProperties> CreatePropertiesAsync(IdentityManager identityManager,
string userId)
{
if (identityManager == null)
{
throw new ArgumentNullException("identityStore");
}
IUser user = await identityManager.Store.Users.FindAsync(userId, CancellationToken.None);
IDictionary<string, string> data = new Dictionary<string, string>
{
{ "userName", user.UserName }
};
return new AuthenticationProperties(data);
}
开发者ID:rusty02,项目名称:TNTT,代码行数:15,代码来源:ApplicationOAuthProvider.cs
示例18: GetClaimsAsync
public static Task<IList<Claim>> GetClaimsAsync(IdentityManager identityManager, string userId)
{
if (identityManager == null)
{
throw new ArgumentNullException("identityManager");
}
AuthenticationManager authenticationManager = new AuthenticationManager(
identityManager.Settings.GetAuthenticationOptions(), identityManager);
return authenticationManager.GetUserIdentityClaimsAsync(userId, new Claim[0], CancellationToken.None);
}
开发者ID:rusty02,项目名称:TNTT,代码行数:12,代码来源:ApplicationOAuthProvider.cs
示例19: UserRoles
public ActionResult UserRoles(SelectUserRolesViewModel model)
{
if (ModelState.IsValid)
{
var idManager = new IdentityManager();
var Db = new ApplicationDbContext();
var user = Db.Users.First(u => u.UserName == model.UserName);
idManager.ClearUserRoles(user.Id);
var allRoles = Db.Roles;
if (!String.IsNullOrEmpty(model.WebRole))
{
//Try to get this
var newRole = allRoles.Where(r => r.Name == model.WebRole).FirstOrDefault();
if (newRole != null)
{
idManager.AddUserToRole(user.Id, newRole.Name);
}
}
if (!String.IsNullOrEmpty(model.GestorRole))
{
//Try to get this
var newRole = allRoles.Where(r => r.Name == model.GestorRole).FirstOrDefault();
if (newRole != null)
{
idManager.AddUserToRole(user.Id, newRole.Name);
}
}
return RedirectToAction("index");
}
return View(model);
}
开发者ID:felixh0,项目名称:RequestManager,代码行数:33,代码来源:AccountController.cs
示例20: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
// Save file to disk and retreive calculated file name or null if handled exception occure
// if user don't provide photo then he don't want photo
model.PhotoUrl = Utils.SavePhotoFileToDisk(model.Photo, this, null, model.Photo == null ? true : false);
var user = model.GetUser();
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var idManager = new IdentityManager();
idManager.AddUserToRole(user.Id, "User");
return RedirectToAction("Index", "Account");
}
else
{
AddErrors(result);
}
}
// Si nous sommes arrivés là, un échec s’est produit. Réafficher le formulaire
return View(model);
}
开发者ID:jalvarez54,项目名称:NorthWind54,代码行数:27,代码来源:AccountController.cs
注:本文中的Microsoft.AspNet.Identity.EntityFramework.IdentityManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论