public IIdentityManagerService Create() { var db = new IdentityDbContext<IdentityUser>(_connString); var userstore = new UserStore<IdentityUser>(db); var usermgr = new Microsoft.AspNet.Identity.UserManager<IdentityUser>(userstore); usermgr.PasswordValidator = new Microsoft.AspNet.Identity.PasswordValidator { RequiredLength = 3 }; var rolestore = new RoleStore<IdentityRole>(db); var rolemgr = new Microsoft.AspNet.Identity.RoleManager<IdentityRole>(rolestore); var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<IdentityUser, string, IdentityRole, string>(usermgr, rolemgr); var dispose = new DisposableIdentityManagerService(svc, db); return dispose; //var db = new CustomDbContext(_connString); //var userstore = new CustomUserStore(db); //var usermgr = new CustomUserManager(userstore); //var rolestore = new CustomRoleStore(db); //var rolemgr = new CustomRoleManager(rolestore); //var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<CustomUser, int, CustomRole, int>(usermgr, rolemgr); //var dispose = new DisposableIdentityManagerService(svc, db); //return dispose; }
public async System.Threading.Tasks.Task <ActionResult> Register(string username, string password) { var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); var manager = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore); var user = new Microsoft.AspNet.Identity.EntityFramework.IdentityUser() { UserName = username }; Microsoft.AspNet.Identity.IdentityResult result = await manager.CreateAsync(user, password); if (result.Succeeded) { //I have some options: log them in, or I can send them an email to "Confirm" their account details.' //I don't have email set up this week, so we'll come back to that. //This authentication manager will create a cookie for the current user, and that cookie will be exchanged on each request until the user logs out var authenticationManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await manager.CreateIdentityAsync(user, Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); authenticationManager.SignIn(new Microsoft.Owin.Security.AuthenticationProperties() { }, userIdentity); } else { ViewBag.Error = result.Errors; return(View()); } return(RedirectToAction("Index", "Home")); }
public IIdentityManagerService Create() { var db = new IdentityDbContext <IdentityUser>(_connString); var userstore = new UserStore <IdentityUser>(db); var usermgr = new Microsoft.AspNet.Identity.UserManager <IdentityUser>(userstore); usermgr.PasswordValidator = new Microsoft.AspNet.Identity.PasswordValidator { RequiredLength = 3 }; var rolestore = new RoleStore <IdentityRole>(db); var rolemgr = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(rolestore); var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService <IdentityUser, string, IdentityRole, string>(usermgr, rolemgr); var dispose = new DisposableIdentityManagerService(svc, db); return(dispose); //var db = new CustomDbContext(_connString); //var userstore = new CustomUserStore(db); //var usermgr = new CustomUserManager(userstore); //var rolestore = new CustomRoleStore(db); //var rolemgr = new CustomRoleManager(rolestore); //var svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<CustomUser, int, CustomRole, int>(usermgr, rolemgr); //var dispose = new DisposableIdentityManagerService(svc, db); //return dispose; }
public IIdentityManagerService Create() { var db = new IdentityDbContext <IdentityUser>(this.connString); var userStore = new UserStore <IdentityUser>(db); var userMgr = new Microsoft.AspNet.Identity.UserManager <IdentityUser>(userStore); var roleStore = new RoleStore <IdentityRole>(db); var roleMgr = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(roleStore); Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService <IdentityUser, string, IdentityRole, string> svc = null; svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService <IdentityUser, string, IdentityRole, string>(userMgr, roleMgr); // uncomment to add other properties that are mapped to claims //svc = new Thinktecture.IdentityManager.AspNetIdentity.AspNetIdentityManagerService<IdentityUser, string, IdentityRole, string>(userMgr, roleMgr, () => //{ // var meta = svc.GetStandardMetadata(); // meta.UserMetadata.UpdateProperties = // meta.UserMetadata.UpdateProperties.Union(new PropertyMetadata[]{ // svc.GetMetadataForClaim(Constants.ClaimTypes.Name, "Name") // }); // return Task.FromResult(meta); //}); return(new DisposableIdentityManagerService(svc, db)); //var db = new CustomDbContext("CustomAspId"); //var store = new CustomUserStore(db); //var mgr = new CustomUserManager(store); //return new Thinktecture.IdentityManager.AspNetIdentity.UserManager<CustomUser, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(mgr, db); }
public async System.Threading.Tasks.Task <ActionResult> Register(string username, string email, string password) { var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); var manager = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore); var user = new Microsoft.AspNet.Identity.EntityFramework.IdentityUser() { UserName = username, Email = email, EmailConfirmed = false }; manager.UserTokenProvider = new Microsoft.AspNet.Identity.EmailTokenProvider <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); Microsoft.AspNet.Identity.IdentityResult result = await manager.CreateAsync(user, password); if (result.Succeeded) { //I have some options: log them in, or I can send them an email to "Confirm" their account details.' //I don't have email set up this week, so we'll come back to that. string confirmationToken = await manager.GenerateEmailConfirmationTokenAsync(user.Id); string confirmationLink = Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Confirm/" + user.Id + "?token=" + confirmationToken; string apiKey = System.Configuration.ConfigurationManager.AppSettings["SendGrid.ApiKey"]; SendGrid.ISendGridClient client = new SendGrid.SendGridClient(apiKey); SendGrid.Helpers.Mail.EmailAddress from = new SendGrid.Helpers.Mail.EmailAddress("*****@*****.**", "Coding Cookware Administrator"); SendGrid.Helpers.Mail.EmailAddress to = new SendGrid.Helpers.Mail.EmailAddress(email); string subject = "Confirm your Coding Cookware Account"; string htmlContent = string.Format("<a href=\"{0}\">Confirm Your Account</a>", confirmationLink); string plainTextContent = confirmationLink; SendGrid.Helpers.Mail.SendGridMessage message = SendGrid.Helpers.Mail.MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); SendGrid.Response response = await client.SendEmailAsync(message); TempData["EmailAddress"] = email; return(RedirectToAction("ConfirmationSent")); //Commenting this out: I'm not going to log the user in on registration anymore - I'm going to send them a confirmation email instead. //This authentication manager will create a cookie for the current user, and that cookie will be exchanged on each request until the user logs out //var authenticationManager = HttpContext.GetOwinContext().Authentication; //var userIdentity = await manager.CreateIdentityAsync(user, Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); //authenticationManager.SignIn(new Microsoft.Owin.Security.AuthenticationProperties() { }, userIdentity); } else { ViewBag.Error = result.Errors; return(View()); } return(RedirectToAction("Index", "Home")); }
public AccountController( Microsoft.AspNet.Identity.UserManager<ApplicationUser> userManager, Microsoft.AspNet.Identity.SignInManager<ApplicationUser> signInManager, IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory) { _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _smsSender = smsSender; _logger = loggerFactory.CreateLogger<AccountController>(); }
public AccountController( Microsoft.AspNet.Identity.UserManager <ApplicationUser> userManager, Microsoft.AspNet.Identity.SignInManager <ApplicationUser> signInManager, IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory) { _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _smsSender = smsSender; _logger = loggerFactory.CreateLogger <AccountController>(); }
/// <summary> /// Notifies the given user of the token /// </summary> /// <param name="token">The token to send</param> /// <param name="manager">The manger that requested it</param> /// <param name="user">The user to send the token to</param> /// <returns>A task that is sending the token</returns> public override Task NotifyAsync(string token, Microsoft.AspNet.Identity.UserManager <Model.Users.User, string> manager, Model.Users.User user) { TextParser parser = new TextParser(this.Manager); TextDefinition subject = parser.ParseMessage(this.Subject, new Dictionary <ReplaceableObjectKeys, object>() { { ReplaceableObjectKeys.Code, token }, { ReplaceableObjectKeys.User, user } }); TextDefinition body = parser.ParseMessage(this.BodyFormat, new Dictionary <ReplaceableObjectKeys, object>() { { ReplaceableObjectKeys.Code, token }, { ReplaceableObjectKeys.User, user } }); new TaskFactory().StartNew(() => { SmtpMailClient.SendMail(user.Email, subject.Text, body.Text, body.Html); }); return(Task.FromResult <int>(0)); }
public static IUserManager Create() { //Either paste in your key here or just put into a file and avoid committing it to github. var db = new IdentityTableContext<IdentityUser>(new CloudStorageAccount( new StorageCredentials("c1azuretests", File.ReadAllText("C:\\dev\\storagekey.txt")), true)); var store = new UserStore<IdentityUser>(db); var mgr = new Microsoft.AspNet.Identity.UserManager<IdentityUser,string>(store); return new UserManager<IdentityUser,string,IdentityUserLogin,IdentityRole,IdentityUserClaim>(mgr, db); //var db = new CustomDbContext("CustomAspId"); //var store = new CustomUserStore(db); //var mgr = new CustomUserManager(store); //return new Thinktecture.IdentityManager.AspNetIdentity.UserManager<CustomUser, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(mgr, db); }
public async System.Threading.Tasks.Task <ActionResult> LogOn(string username, string password, bool?staySignedIn, string returnUrl) { var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); var manager = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore); var user = await manager.FindByNameAsync(username); bool result = await manager.CheckPasswordAsync(user, password); if (result) { if (user.EmailConfirmed) { //I have some options: log them in, or I can send them an email to "Confirm" their account details.' //I don't have email set up this week, so we'll come back to that. //This authentication manager will create a cookie for the current user, and that cookie will be exchanged on each request until the user logs out var authenticationManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await manager.CreateIdentityAsync(user, Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); authenticationManager.SignIn(new Microsoft.Owin.Security.AuthenticationProperties() { }, userIdentity); } else { ViewBag.Error = new string[] { "Your email address has not been confirmed." }; return(View()); } } else { ViewBag.Error = new string[] { "Unable to Log In, check your username and password" }; return(View()); } if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(returnUrl)); } }
public IIdentityManagerService Create() { var db = new IdentityDbContext <IdentityUser>(this.connString); var store = new UserStore <IdentityUser>(db); var mgr = new Microsoft.AspNet.Identity.UserManager <IdentityUser>(store); mgr.PasswordValidator = new Microsoft.AspNet.Identity.PasswordValidator { RequiredLength = 3 }; return(new Thinktecture.IdentityManager.AspNetIdentity.IdentityManagerService <IdentityUser, string>(mgr, db)); //var db = new CustomDbContext("CustomAspId"); //var store = new CustomUserStore(db); //var mgr = new CustomUserManager(store); //return new Thinktecture.IdentityManager.AspNetIdentity.UserManager<CustomUser, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(mgr, db); }
public AspNetIdentityUserService(Microsoft.AspNet.Identity.UserManager <TUser, TKey> userManager, Func <string, TKey> parseSubject = null) { if (userManager == null) { throw new ArgumentNullException("userManager"); } this.userManager = userManager; if (parseSubject != null) { ConvertSubjectToKey = parseSubject; } else { var keyType = typeof(TKey); if (keyType == typeof(string)) { ConvertSubjectToKey = subject => (TKey)ParseString(subject); } else if (keyType == typeof(int)) { ConvertSubjectToKey = subject => (TKey)ParseInt(subject); } else if (keyType == typeof(uint)) { ConvertSubjectToKey = subject => (TKey)ParseUInt32(subject); } else if (keyType == typeof(long)) { ConvertSubjectToKey = subject => (TKey)ParseLong(subject); } else if (keyType == typeof(Guid)) { ConvertSubjectToKey = subject => (TKey)ParseGuid(subject); } else { throw new InvalidOperationException("Key type not supported"); } } EnableSecurityStamp = true; }
public async System.Threading.Tasks.Task <ActionResult> Confirm(string id, string token) { var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); var manager = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore); manager.UserTokenProvider = new Microsoft.AspNet.Identity.EmailTokenProvider <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(); var result = await manager.ConfirmEmailAsync(id, token); if (result.Succeeded) { TempData["Confirmed"] = true; return(RedirectToAction("LogOn")); } else { return(HttpNotFound()); } }
public EnforcingLocalSignup(Microsoft.AspNet.Identity.UserManager <TUser, TKey> userManager, Func <string, TKey> parseSubject = null) { }
/// <summary> /// Generates identity from this user entity. /// </summary> /// <typeparam name="T">Type of the user for which generate claims.</typeparam> /// <param name="manager">User manager which used for create identity</param> /// <returns>Task which return identity based on current user entity</returns> public override async System.Threading.Tasks.Task <System.Security.Claims.ClaimsIdentity> GenerateUserIdentityAsync <T>(Microsoft.AspNet.Identity.UserManager <T> manager) { var userIdentity = await base.GenerateUserIdentityAsync <T>(manager); if (this.ClientId.HasValue) { userIdentity.AddClaim(new Claim(WellKnownClaims.ClientClaim, this.ClientId.ToString())); } return(userIdentity); }
public ActionResult Index() { var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<NetCafeWeb.Models.ApplicationUser>(new NetCafeWeb.Models.ApplicationDbContext()); var manager = new Microsoft.AspNet.Identity.UserManager<NetCafeWeb.Models.ApplicationUser>(store); var a = manager.IsInRoleAsync(User.Identity.GetUserId(), "Admin"); bool isAdmin = a.Result; IRepository<User> userRepository = new UserRepository(); IEnumerable<User> users = userRepository.List; ViewBag.users = users.Cast<User>().ToList(); IRepository<PC> pcRepository = new PCRepository(); IEnumerable<PC> pcs = pcRepository.List; ViewBag.pcs = pcs.Cast<PC>().ToList(); if (isAdmin) { //show het order IRepository<Order> repository = new OrderRepository(); IEnumerable<Order> order = repository.List; ViewBag.orders = order.Cast<Order>().ToList(); //FormsAuthentication.SetAuthCookie("asd", false); return View(); } else //La supervisor { //Lay supervior user String supervisorName = User.Identity.Name; //Lay supervior id UserRepository repo = new UserRepository(); NetCafeRepository netRepo = new NetCafeRepository(); OrderRepository orderRepo = new OrderRepository(); int supervisorId = repo.getIDByUsername(supervisorName); //Lay netcafe id int netID = netRepo.getNetCafeIDByName(supervisorId); //hien thi order cua netcafe id List<Order> orders = orderRepo.getOrderByNetCafe(netID); ViewBag.orders = orders; } return View(); }
public AuthRepository() { _ctx = new AuthContext(); _userManager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_ctx)); }
public ActionResult Index(int? id) { var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<NetCafeWeb.Models.ApplicationUser>(new NetCafeWeb.Models.ApplicationDbContext()); var manager = new Microsoft.AspNet.Identity.UserManager<NetCafeWeb.Models.ApplicationUser>(store); var a = manager.IsInRoleAsync(User.Identity.GetUserId(), "Admin"); //var b = manager.IsInRoleAsync(User.Identity.GetUserId(), "Supervisor"); bool isAdmin = a.Result; a = manager.IsInRoleAsync(User.Identity.GetUserId(), "Supervisor"); bool isSupervisor = a.Result; List<PC> PCList = new List<PC>(); List<NetCafe> NetList = new List<NetCafe>(); if (isSupervisor) { string username = User.Identity.Name; NetList = PCService.GetManageNet(username); int selectedNetID = 0; if (NetList != null && NetList.Count > 0) { foreach (NetCafe netCafe in NetList) { PCList = PCService.FindByNetID(netCafe.NetCafeID); selectedNetID = netCafe.NetCafeID; } } var query = PCList.OrderBy(p => p.PCStatus).ThenBy(p => p.PCName).ThenBy(p => p.Price); ViewBag.PCList = query.ToList(); ViewBag.NetList = NetList; ViewBag.Role = "Supervisor"; return View(); } else { if (id != null && id > 0) { PCList = PCService.FindByNetID(id.Value); ViewBag.pcList = PCList; ViewBag.SelectedNetcafe = PCService.GetNetCafeByID(id.Value); } else { PCList = PCService.GetPCList(); ViewBag.pcList = PCList; } var query = PCList.OrderBy(p => p.NetCafeID).ThenBy(p => p.PCStatus).ThenBy(p => p.PCName).ThenBy(p => p.Price); ViewBag.PCList = query.ToList(); ViewBag.NetList = PCService.GetNetList(); ViewBag.Role = "Admin"; return View(); } }
public UsersController(Microsoft.AspNet.Identity.UserManager <User> userManager, ISecurityService securityService, ISecurityServiceAsync securityServiceAsync) { UserManager = userManager; _securityService = securityService; _securityServiceAsync = securityServiceAsync; }
public UserManager(UserManager <AppUser, int> userManager) { userManager.ThrowIfNull("userManager"); _userManager = userManager; }
public static ApplicationUser GetApplicationUser() { ApplicationDbContext db = new ApplicationDbContext(); var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<VSMR12.Models.ApplicationUser>(new VSMR12.Models.ApplicationDbContext()); var userManager = new Microsoft.AspNet.Identity.UserManager<VSMR12.Models.ApplicationUser>(store); VSMR12.Models.ApplicationUser user = userManager.FindByNameAsync(System.Web.HttpContext.Current.User.Identity.Name).Result; return user; }
public static vResource GetResource() { ApplicationDbContext db = new ApplicationDbContext(); var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<VSMR12.Models.ApplicationUser>(new VSMR12.Models.ApplicationDbContext()); var userManager = new Microsoft.AspNet.Identity.UserManager<VSMR12.Models.ApplicationUser>(store); VSMR12.Models.ApplicationUser user = userManager.FindByNameAsync(System.Web.HttpContext.Current.User.Identity.Name).Result; vResource resource = db.vResource.Find(user.UserId); return resource; }