本文整理汇总了C#中AuthenticationIdentityManager类的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationIdentityManager类的具体用法?C# AuthenticationIdentityManager怎么用?C# AuthenticationIdentityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationIdentityManager类属于命名空间,在下文中一共展示了AuthenticationIdentityManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
var db = new ApplicationDbContext();
var manager = new AuthenticationIdentityManager(new IdentityStore(db));
ApplicationUser u = new ApplicationUser()
{
UserName = userName,
FirstName = tb_FirstName.Text,
LastName = tb_LastName.Text,
Email = tb_Email.Text
};
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
var foundRole = db.Roles.Single(x => x.Name == dl_Roles.SelectedValue);
u.Roles = new System.Collections.Generic.HashSet<UserRole>();
u.Roles.Add(new UserRole()
{
Role = foundRole,
User = u
});
db.SaveChanges();
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:35,代码来源:Register.aspx.cs
示例2: LogIn
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
var context = new ApplicationDbContext();
var signinUser = context.Users.FirstOrDefault(u => u.UserName == UserName.Text);
if (signinUser!= null && !signinUser.IsDeleted)
{
// Validate the user password
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext())).Authentication;
IdentityResult result = manager.CheckPasswordAndSignIn(Context.GetOwinContext().Authentication, UserName.Text, Password.Text, RememberMe.Checked);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
FailureText.Text = result.Errors.FirstOrDefault();
ErrorMessage.Visible = true;
}
}
else
{
FailureText.Text = "Please register";
ErrorMessage.Visible = true;
}
}
}
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:30,代码来源:Login.aspx.cs
示例3: LogIn
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user password
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext())).Authentication;
IdentityResult result = manager.CheckPasswordAndSignIn(Context.GetOwinContext().Authentication, UserName.Text, Password.Text, RememberMe.Checked);
if (result.Success)
{
var context = new ApplicationDbContext();
var curUserName = UserName.Text;
var userId = context.Users.FirstOrDefault(u => u.UserName == curUserName).Id;
var userRole = context.UserRoles.FirstOrDefault(u => u.UserId == userId).Role.Name;
if (userRole == "Banned")
{
ErrorSuccessNotifier.AddErrorMessage("You are banned!");
return;
}
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorSuccessNotifier.AddErrorMessage(result.Errors.FirstOrDefault());
}
}
}
开发者ID:nnaidenov,项目名称:TelerikAcademy,代码行数:27,代码来源:Login.aspx.cs
示例4: LogIn
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user password
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
IdentityResult result = manager.CheckPasswordAndSignIn(Context.GetOwinContext().Authentication, UserName.Text, Password.Text, RememberMe.Checked);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
var errorMessageText = result.Errors.FirstOrDefault();
FailureText.Text = errorMessageText;
ErrorMessage.Visible = true;
ErrorSuccessNotifier.AddErrorMessage(errorMessageText);
}
}
else
{
ErrorSuccessNotifier.AddErrorMessage(
"An unexpected error occured! Please refresh the page...");
}
}
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:25,代码来源:Login.aspx.cs
示例5: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string firstName = FirstName.Text;
string lastName = LastName.Text;
string userName = UserName.Text;
string email = Email.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
ApplicationUser u = new ApplicationUser()
{
FirstName = firstName,
LastName = lastName,
UserName = userName,
Email = email
};
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:25,代码来源:Register.aspx.cs
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
//manager.Roles.CreateRoleAsync(new Role("Moderator"));
//manager.Roles.AddUserToRoleAsync("54fbcab5-d65b-47d4-b517-2eba10002e21", "186c2138-de27-42a6-94f0-8b830c2e8b9c");
var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
if (!manager.Logins.HasLocalLogin(User.Identity.GetUserId()))
{
grdMessages.EmptyDataTemplate = null;
if (grdMessages.FooterRow != null)
{
grdMessages.FooterRow.Visible = false;
}
}
else
{
var userId = User.Identity.GetUserId();
var db = new ApplicationDbContext();
var user = db.Users.FirstOrDefault(u => u.Id == userId);
if (user != null)
{
if (user.Roles.Any(r => r.Role.Name == "Moderator"))
{
grdMessages.Columns[2].Visible = true;
}
else if (user.Roles.Any(r => r.Role.Name == "Administrator"))
{
grdMessages.Columns[2].Visible = true;
grdMessages.Columns[3].Visible = true;
}
}
}
}
开发者ID:NikolayKostadinov,项目名称:TelerikAkademy,代码行数:34,代码来源:Default.aspx.cs
示例7: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore());
User u = new User(userName) { UserName = userName };
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
//OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
using (SocialNetworkDbEntities context = new SocialNetworkDbEntities())
{
UserDetail details = new UserDetail();
context.UserDetails.Add(details);
context.SaveChanges();
var user = context.AspNetUsers.Find(u.Id);
user.UserDetailsId = details.UserDetailsId;
context.SaveChanges();
}
Response.Redirect("~/Account/UserDetails");
}
else
{
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:nikimoto,项目名称:JadeiteSocialNetwork,代码行数:27,代码来源:Register.aspx.cs
示例8: LinkButtonBanUser_Command
protected void LinkButtonBanUser_Command(object sender, CommandEventArgs e)
{
var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
string roleBanId = "2";
manager.Roles.AddUserToRoleAsync(e.CommandArgument.ToString(), roleBanId);
}
开发者ID:nnaidenov,项目名称:TelerikAcademy,代码行数:8,代码来源:Users.aspx.cs
示例9: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore(new AcademyDbContext()));
ApplicationUser u = new ApplicationUser(userName)
{
UserName = userName,
FirstName = this.TextBoxFirstName.Text,
LastName = this.TextBoxLastName.Text,
Email = this.TextBoxEmail.Text,
JoinDate = DateTime.Now,
};
var context = new AcademyDbContext();
string fileName = string.Empty;
var fileUpload = this.FileUploadAvatar;
if (fileUpload.HasFile)
{
if (fileUpload.PostedFile.ContentLength < 102400 &&
(fileUpload.PostedFile.ContentType == PngImageFormat ||
fileUpload.PostedFile.ContentType == JpegImageFormat ||
fileUpload.PostedFile.ContentType == GifImageFormat))
{
fileName = userName.Replace("<", string.Empty).Replace(">", string.Empty) + GetAvatarExtension(FileUploadAvatar.PostedFile.FileName);
fileUpload.SaveAs(Server.MapPath(MainPath) + fileName);
u.AvatarPath = MainPath + fileName;
}
else
{
ErrorSuccessNotifier.ShowAfterRedirect = true;
ErrorSuccessNotifier.AddErrorMessage("The uploaded avatar exceeds 100KB or is in a wrong format.");
Response.Redirect(Request.RawUrl, false);
return;
}
}
else
{
u.AvatarPath = DefaultImagePath;
}
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
ErrorSuccessNotifier.ShowAfterRedirect = true;
ErrorSuccessNotifier.AddSuccessMessage("Registration completed successfully.");
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorSuccessNotifier.AddErrorMessage(result.Errors.FirstOrDefault());
}
}
开发者ID:BobbyBorisov,项目名称:ChrysoberylAcademySystem,代码行数:56,代码来源:Register.aspx.cs
示例10: AccountController
public AccountController()
{
var context = new MoviesContext();
userRole = context.Roles
.Where(r => r.Name == "user")
.Select(r => r.Id)
.FirstOrDefault()
.ToString();
IdentityManager = new AuthenticationIdentityManager(new IdentityStore(context));
}
开发者ID:ben12345,项目名称:Movie-Room,代码行数:10,代码来源:AccountController.cs
示例11: Page_Load
protected void Page_Load()
{
// Process the result from an auth provider in the request
ProviderName = OpenAuthProviders.GetProviderNameFromRequest(Request);
if (String.IsNullOrEmpty(ProviderName))
{
Response.Redirect("~/Account/Login");
}
if (!IsPostBack)
{
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
var auth = Context.GetOwinContext().Authentication;
ClaimsIdentity id = manager.GetExternalIdentity(auth);
var context = new ApplicationDbContext();
var user = context.UserRoles.FirstOrDefault(u => u.User.UserName == id.Name);
if (user != null)
{
var userRole = user.Role.Name;
if (userRole == "Banned")
{
ErrorSuccessNotifier.AddErrorMessage("You are banned!");
ErrorSuccessNotifier.ShowAfterRedirect = true;
Response.Redirect("~/Account/Login");
}
}
IdentityResult result = manager.SignInExternalIdentity(auth, id);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else if (User.Identity.IsAuthenticated)
{
result = manager.LinkExternalIdentity(id, User.Identity.GetUserId());
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
AddErrors(result);
return;
}
}
else
{
userName.Text = id.Name;
}
}
}
开发者ID:nnaidenov,项目名称:GoldstoneForum,代码行数:50,代码来源:RegisterExternalLogin.aspx.cs
示例12: Redirect
private async void Redirect()
{
AuthenticationIdentityManager manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
var userId = User.Identity.GetUserId();
var roles = await manager.Roles.GetRolesForUserAsync(userId);
if (roles.Any(r => r.Name == "Administrator"))
{
Response.Redirect("~/Administrator/AdministratorDefault.aspx");
}
else if (roles.Any(r => r.Name == "Moderator"))
{
Response.Redirect("~/Moderator/ModeratorDefault.aspx");
}
}
开发者ID:Gerya,项目名称:TelerikAcademy,代码行数:14,代码来源:Default.aspx.cs
示例13: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
string email = Email.Text;
string filename = "default.png";
if (UploadAvatar.HasFile)
{
if (UploadAvatar.PostedFile.ContentType == "image/jpeg" ||
UploadAvatar.PostedFile.ContentType == "image/gif" ||
UploadAvatar.PostedFile.ContentType == "image/png")
{
if (UploadAvatar.PostedFile.ContentLength < 102400)
{
filename = userName + Path.GetExtension(UploadAvatar.FileName);
UploadAvatar.SaveAs(Server.MapPath("~/Avatar_Files/") + filename);
}
else
{
ErrorSuccessNotifier.AddErrorMessage("Upload status: The file has to be less than 100 kb!");
return;
}
}
else
{
ErrorSuccessNotifier.AddErrorMessage("Upload status: Only JPEG files are accepted!");
return;
}
}
var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
ApplicationUser u = new ApplicationUser()
{
UserName = userName,
Email = email,
Avatar = filename
};
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorSuccessNotifier.AddErrorMessage(result.Errors.FirstOrDefault());
}
}
开发者ID:nnaidenov,项目名称:GoldstoneForum,代码行数:48,代码来源:Register.aspx.cs
示例14: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore());
User u = new User(userName) { UserName = userName };
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
OpenAuthProviders.RedirectToReturnUrl("~/library-system/Default.aspx", Response);
}
else
{
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:krasiuzunov7,项目名称:WebFormsBookLibrary,代码行数:16,代码来源:Register.aspx.cs
示例15: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = this.UserName.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore(new BooksLibrarySystemContext()));
User u = new User(userName) { UserName = userName };
IdentityResult result = manager.Users.CreateLocalUser(u, this.Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(this.Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
this.Response.Redirect(this.Request.QueryString["ReturnUrl"], false);
//BooksLibrarySystem.Web.Account.OpenAuthProviders.RedirectToReturnUrl(this.Request.QueryString["ReturnUrl"], this.Response);
}
else
{
this.ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:stoskov,项目名称:books-library-system,代码行数:17,代码来源:Register.aspx.cs
示例16: LogIn
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user password
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
IdentityResult result = manager.CheckPasswordAndSignIn(Context.GetOwinContext().Authentication, UserName.Text, Password.Text, RememberMe.Checked);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl("~/library-system/Default.aspx", Response);
}
else
{
FailureText.Text = result.Errors.FirstOrDefault();
ErrorMessage.Visible = true;
}
}
}
开发者ID:krasiuzunov7,项目名称:WebFormsBookLibrary,代码行数:18,代码来源:Login.aspx.cs
示例17: CreateAndLoginUser
private void CreateAndLoginUser()
{
if (!IsValid)
{
return;
}
var user = new User(userName.Text);
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore()).Authentication;
IdentityResult result = manager.CreateAndSignInExternalUser(Context.GetOwinContext().Authentication, user);
if (result.Success)
{
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
AddErrors(result);
return;
}
}
开发者ID:PetarPenev,项目名称:Telerik,代码行数:19,代码来源:RegisterExternalLogin.aspx.cs
示例18: LogIn
protected void LogIn(object sender, EventArgs e)
{
if (this.IsValid)
{
// Validate the user password
IAuthenticationManager manager = new AuthenticationIdentityManager(new IdentityStore(new BooksLibrarySystemContext())).Authentication;
IdentityResult result = manager.CheckPasswordAndSignIn(this.Context.GetOwinContext().Authentication, this.UserName.Text, this.Password.Text, this.RememberMe.Checked);
if (result.Success)
{
this.Response.Redirect(this.Request.QueryString["ReturnUrl"], false);
//OpenAuthProviders.RedirectToReturnUrl(this.Request.QueryString["ReturnUrl"], this.Response);
}
else
{
this.FailureText.Text = result.Errors.FirstOrDefault();
this.ErrorMessage.Visible = true;
}
}
}
开发者ID:stoskov,项目名称:books-library-system,代码行数:19,代码来源:Login.aspx.cs
示例19: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore(new ApplicationDbContext()));
User u = new User(userName) { UserName = userName };
IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent: false);
ErrorSuccessNotifier.AddSuccessMessage("Welcome back.");
ErrorSuccessNotifier.ShowAfterRedirect = true;
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorSuccessNotifier.AddErrorMessage("Register details are incorect.");
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:19,代码来源:Register.aspx.cs
示例20: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
string userName = UserName.Text;
var manager = new AuthenticationIdentityManager(new IdentityStore(new ForumEmeraldContext()));
string filename = string.Empty;
ForumUser user = new ForumUser()
{
UserName = userName,
Email = this.TextBoxEmail.Text,
};
var fileUpload = this.FileUploadPhoto;
if (fileUpload.HasFile && (fileUpload.PostedFile.ContentType == PngImageFormat ||
FileUploadPhoto.PostedFile.ContentType == JpegImageFormat))
{
filename = userName + GetPhotoExtension(FileUploadPhoto.PostedFile.FileName);
fileUpload.SaveAs(Server.MapPath(MainPath) + filename);
user.PhotoPath = MainPath + filename;
}
else
{
user.PhotoPath = DefaultImagePath;
}
IdentityResult result = manager.Users.CreateLocalUser(user, Password.Text);
if (result.Success)
{
manager.Authentication.SignIn(Context.GetOwinContext().Authentication, user.Id, isPersistent: false);
this.AddUserToRole();
OpenAuthProviders.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
if (this.FileUploadPhoto.HasFile)
{
File.Delete(this.Server.MapPath(MainPath + filename));
}
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:43,代码来源:Register.aspx.cs
注:本文中的AuthenticationIdentityManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论