当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.FindByNameAsync方法代码示例

本文整理汇总了C#中UserManager.FindByNameAsync方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.FindByNameAsync方法的具体用法?C# UserManager.FindByNameAsync怎么用?C# UserManager.FindByNameAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.FindByNameAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Invoke

        public async Task Invoke(HttpContext httpContext, UserManager<ApplicationUser> manager)
        {
            if (httpContext.Request.Path.StartsWithSegments(_options.Path))
            {
                var headers = httpContext.Request.Headers;
                if (!(headers.ContainsKey("ApiUser") && headers.ContainsKey("ApiToken")))
                {
                    await httpContext.Authentication.ChallengeAsync();
                    return;
                }

                var apiUser = headers.FirstOrDefault(h => h.Key == "ApiUser").Value;
                var token = headers.FirstOrDefault(h => h.Key == "ApiToken").Value;

                var user = await manager.FindByNameAsync(apiUser).ConfigureAwait(false);
                var authorized = await manager.VerifyUserTokenAsync(user, "Default", "api-request-injest", token).ConfigureAwait(false);

                if (!authorized)
                {
                    await httpContext.Authentication.ChallengeAsync();
                    return;
                }
            }

            await _next(httpContext);
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:26,代码来源:TokenProtectedResource.cs

示例2: submitCodePost

        public string submitCodePost(string title, string content, string type)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                CodePost tmp = new CodePost();

                content = HttpUtility.JavaScriptStringEncode(content);

                var store = new UserStore<ApplicationUser>(db);
                var userManager = new UserManager<ApplicationUser>(store);
                ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;
                var currentUser = userManager.FindById(User.Identity.GetUserId());

                if (title != null && content != null && type != null)
                {
                    tmp.title = title;
                    tmp.content = content;
                    tmp.votes = 0;
                    tmp.user_id = user.Id;
                    tmp.userName = user.user;
                    tmp.userImgPath = currentUser.userImgPath;
                }

                bool result = updateHashTags(tmp);

                if(result == false)
                    db.posts.Add(tmp);

                db.SaveChanges();

                return "success";
            }
        }
开发者ID:yippee-ki-yay,项目名称:Codetweets,代码行数:33,代码来源:RoutesDemoController.cs

示例3: getAppUser

        public ApplicationUser getAppUser(IPrincipal User)
        {
            var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
            var userManager = new UserManager<ApplicationUser>(store);
            ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;

            return user;
        }
开发者ID:RodricDegroote,项目名称:Server-Side-Advanced,代码行数:8,代码来源:UserService.cs

示例4: GetUserId

        private string GetUserId(string userName)
        {
            var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
            var userManager = new UserManager<ApplicationUser>(store);
            ApplicationUser user = userManager.FindByNameAsync(userName).Result;

            return user.Id;
        }
开发者ID:derderov,项目名称:Trucizny,代码行数:8,代码来源:Comment.cs

示例5: UpdateRuoloUtente

        public async Task<IHttpActionResult> UpdateRuoloUtente(UpdateRuoloUtenteModel Model)
        {
            if (Model == null || !ModelState.IsValid)
                return BadRequest(ModelState);

            using (var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
            {
                var utente = await userManager.FindByNameAsync(Model.Username);
                if (utente == null)
                    return NotFound();

                if (Model.NuovoStato)
                {
                    await userManager.AddToRoleAsync(utente.Id, Model.Ruolo);
                }
                else
                {
                    await userManager.RemoveFromRoleAsync(utente.Id, Model.Ruolo);
                }
            }

            return Ok();
        }
开发者ID:Simone000,项目名称:SPA_Template,代码行数:23,代码来源:AdminController.cs

示例6: GetUserByName

        public async Task<MyUser> GetUserByName(string name)
        {
            var db = new DataContext();
            var userMan = new UserManager<MyUser>(new UserStore<MyUser>(db));
            
            var currentUser = await userMan.FindByNameAsync(name);

            return currentUser;
        }
开发者ID:biggash730,项目名称:SemanticUI_Knockout_ASPMVC_Starter,代码行数:9,代码来源:SecurityHelpers.cs

示例7: SetDisplayName

 public static async Task SetDisplayName(this Controller baseController, ClaimsPrincipal user, UserManager<User> userManager)
 {
     if (baseController.TempData["UserDisplayName"] == null || string.IsNullOrEmpty(baseController.TempData["UserDisplayName"].ToString()))
     {
         if (user.Identity.IsAuthenticated)
         {
             var loggedInUser = await userManager.FindByNameAsync(user.Identity.Name);
             baseController.TempData["UserDisplayName"] = loggedInUser.GetFirstName();
         }
     }
 }
开发者ID:gwartnes,项目名称:Blogness,代码行数:11,代码来源:ControllerExtensions.cs

示例8: Index

 public ActionResult Index()
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
     ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;
     model = new ImageModel();
     if (user != null)
     {
         model.ImageUrl = user.ImageUrl;
     }
     return PartialView("~/Views/Shared/_LoginPartial.cshtml", model);
 }
开发者ID:hilakuker,项目名称:Interexts,代码行数:11,代码来源:ImageController.cs

示例9: AddToCart

 public ActionResult AddToCart(Product product)
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
     ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;
     List<Product> products = new List<Product>();
     user.UserCart.Products.Add(product);
     foreach (var item in user.UserCart.Products)
     {
         products.Add(item);
     }
     return View(products);
 }
开发者ID:usermail555555,项目名称:ImperiaonlineTools,代码行数:12,代码来源:CartController.cs

示例10: GetCalcRelease

 // GET: api/CalcReleases
 public IQueryable<CalcRelease> GetCalcRelease()
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;
     string[] myInClause = null;
     if (user.Scheme != null)
     {
         myInClause = user.Scheme.Split(',');
         return db.CalcRelease.Where(s => myInClause.Contains(s.Scheme));
     }
     else
     {
         return null;
     }
 }
开发者ID:Jaysonh1985,项目名称:CalcEngine,代码行数:16,代码来源:CalcReleasesController.cs

示例11: Create

        // GET: Files/Create
        public ActionResult Create()
        {
            var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
            var userManager = new UserManager<ApplicationUser>(store);
            ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;

            if (user == null)
                return View();

            ViewBag.OwnerId = new SelectList(db.Users.Where(u => u.Id == user.Id), "Id", "FirstName");
            ViewBag.ReceiverId = AddFirstItem(new SelectList(db.Users, "Id", "FirstName"));
            ViewBag.GroupId = AddFirstItem(new SelectList(db.Groups, "GroupID", "GroupName"));

            return View();
        }
开发者ID:behzadvef,项目名称:LMS-Repo,代码行数:16,代码来源:FilesController.cs

示例12: Get

 public IQueryable<string> Get()
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     ApplicationUser user = userManager.FindByNameAsync(User.Identity.Name).Result;
     string[] myInClause = null;
     var response = Request.CreateResponse();
     if (user.Scheme != null)
     {
         myInClause = user.Scheme.Split(',');
         return db.Schemes.Where(s => myInClause.Contains(s.Name)).Select(m => m.Name).Distinct();
     }
     else
     {
         return null;
     }
 }
开发者ID:Jaysonh1985,项目名称:CalcEngine,代码行数:16,代码来源:SchemeWebApiController.cs

示例13: Invoke

        public async Task Invoke(HttpContext context, SignInManager<ApplicationUser> signInManager, UserManager<ApplicationUser> userManager)
        {
            if (context.User.Identity.IsAuthenticated)
            {
                this.SetNTContext(context);
            }

            // automatically logging in in the dev mode
            else if (SiteSettings.IsEnvironment(SecurityConstants.DevEnvironment))
            {
                ApplicationUser user = await userManager.FindByNameAsync(SecuritySettings.NootusProfileUserName);
                await signInManager.SignInAsync(user, false);
            }

            await this.next(context);
        }
开发者ID:Nootus,项目名称:MegaMine,代码行数:16,代码来源:ProfileMiddleWare.cs

示例14: OnAuthenticated

		/// <summary>
		/// Invoked after the LTI request has been authenticated so the application can sign in the application user.
		/// </summary>
		/// <param name="context">Contains information about the login session as well as the LTI request.</param>
		/// <param name="claims">Optional set of claims to add to the identity.</param>
		/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
		public static async Task OnAuthenticated(LtiAuthenticatedContext context, IEnumerable<Claim> claims = null)
		{
			// Find existing pairing between LTI user and application user
			var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new LtiDb()));
			var loginProvider = string.Join(":", new[] { context.Options.AuthenticationType, context.LtiRequest.ConsumerKey });
			var providerKey = context.LtiRequest.UserId;
			var login = new UserLoginInfo(loginProvider, providerKey);
			var user = await userManager.FindAsync(login);
			if (user == null)
			{
				var usernameContext = new LtiGenerateUserNameContext(context.OwinContext, context.LtiRequest);
				await context.Options.Provider.GenerateUserName(usernameContext);
				if (string.IsNullOrEmpty(usernameContext.UserName))
				{
					return;
				}
				user = await userManager.FindByNameAsync(usernameContext.UserName);
				if (user == null)
				{
					user = new ApplicationUser { UserName = usernameContext.UserName };
					var result = await userManager.CreateAsync(user);
					if (!result.Succeeded)
					{
						return;
					}
				}
				// Save the pairing between LTI user and application user
				await userManager.AddLoginAsync(user.Id, login);
			}

			// Create the application identity, add the LTI request as a claim, and sign in
			var identity = await userManager.CreateIdentityAsync(user, context.Options.SignInAsAuthenticationType);
			identity.AddClaim(new Claim(context.Options.ClaimType, JsonConvert.SerializeObject(context.LtiRequest, Formatting.None,
					new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), ClaimValueTypes.String, context.Options.AuthenticationType));
			if (claims != null)
			{
				foreach (var claim in claims)
				{
					identity.AddClaim(claim);
				}
			}
			context.OwinContext.Authentication.SignIn(new AuthenticationProperties { IsPersistent = false }, identity);

			// Redirect to original URL so the new identity takes affect
			context.RedirectUrl = context.LtiRequest.Url.ToString();
		}
开发者ID:Tinkturianec,项目名称:uLearn.Lti,代码行数:52,代码来源:SecurityHandler.cs

示例15: Save

        public async Task<WikiDownUser> Save(IPrincipal principal, UserManager<WikiDownUser> userManager)
        {
            var user = await userManager.FindByNameAsync(this.UserName);

            var roles = this.GetRoles(principal, user);

            if (user != null)
            {
                if (user.UserName == principal.Identity.Name)
                {
                    var userAccessLevel = ArticleAccessHelper.GetAccessLevel(user.Roles);
                    if (userAccessLevel < ArticleAccessLevel.Admin)
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }
                }

                user.SetRoles(roles);
                user.SetDisplayName(this.DisplayName);
                user.SetEmail(this.Email);

                if (!string.IsNullOrWhiteSpace(this.Password))
                {
                    await userManager.RemovePasswordAsync(user.Id);
                    await userManager.AddPasswordAsync(user.Id, this.Password);
                }

                await userManager.UpdateAsync(user);

                WikiDownUserCacheHelper.Clear(user.UserName);
            }
            else
            {
                user = new WikiDownUser(this.UserName) { Roles = roles };
                user.SetDisplayName(this.DisplayName);
                user.SetEmail(this.Email);

                await userManager.CreateAsync(user, this.Password);
            }

            return user;
        }
开发者ID:sebnilsson,项目名称:WikiDown,代码行数:42,代码来源:AccountUserApiModel.cs


注:本文中的UserManager.FindByNameAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。