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


C# IUserRepository.Save方法代码示例

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


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

示例1: AuthenticationService

        public AuthenticationService(IUserRepository userRepository)
        {
            _userRepository = userRepository;

            //create couple of default users
            var salt = GenerateSalt(6);
            var saltedPass = GenerateSaltedHash(Encoding.UTF8.GetBytes("pass"), salt);
            _userRepository.Save(new User("joe", Convert.ToBase64String(saltedPass), Convert.ToBase64String(salt), new [] {Roles.Administrator}));
            _userRepository.Save(new User("bob", Convert.ToBase64String(saltedPass), Convert.ToBase64String(salt), new[] { Roles.Consumer }));
        }
开发者ID:EdsonF,项目名称:WebAPISample,代码行数:10,代码来源:AuthenticationService.cs

示例2: SetUp

            public void SetUp()
            {
                _userRepository = new UserRepository();

                _userId = "TestId";
                _user = new User
                    {
                        UserId = _userId,
                    };
                _userRepository.Save(_user);
            }
开发者ID:RitsukoO,项目名称:sampleprojects,代码行数:11,代码来源:UserRepositoryTests.cs

示例3: SetupTest

        public void SetupTest()
        {
            _userRepositoryInstance = new InMemoryUserRepository();

            // add the "ewise" user to the 'database'
            _userRepositoryInstance.Save(
                new User()
                {
                    UserName = "ewise",
                    FirstName = "Eric",
                    LastName = "Wise"
                });
        }
开发者ID:mvoronkin,项目名称:TestRep,代码行数:13,代码来源:UserTests.cs

示例4: ResolveUserByWindowsIdentity

 private static User ResolveUserByWindowsIdentity(IUserRepository repository, WindowsIdentity windowsIdentity)
 {
     // 1. User is already registered by Windows identity
     var user = repository.GetByUsername(windowsIdentity.Name);
     if (user == null)
     {
         // 2. User is already registered, but not associated with a Windows identity    
         var email = UserPrincipal.Current.EmailAddress;
         user = repository.GetByEmail(email);
         if (user == null)
         {
             // 3. User is not registered, but is authenticated
             user = repository.CreateFromWindowsIdentity(windowsIdentity);
         }
         else
         {
             // Associate registered user with this identity
             user.Username = windowsIdentity.Name;
             user.IsActivated = true;
         }
         repository.Save(user);
     }
     return user;
 }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:24,代码来源:Cohort.UserManagement.cs

示例5: ArrangeModelsForTest

        private void ArrangeModelsForTest()
        {
            userRepository = new FakeUserRepository();
            userProfileRepository = new FakeUserProfileRepository();
            userProfile.Email = EMAIL;
            userProfileRepository.Add(userProfile);
            userProfileRepository.Save();

            user = EntityHelpers.GetValidUser();
            user.Username = EMAIL;
            user.Password = GrassrootsMembershipService.HashPassword(PASSWORD, null);
            user.UserProfile = userProfile;
            userRepository.Add(user);
            userRepository.Save();
        }
开发者ID:JordanRift,项目名称:Grassroots,代码行数:15,代码来源:MembershipProviderTests.cs

示例6: Configure

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IUserRepository userRepository, InatorConstraint inatorConstraint)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // Configure the HTTP request pipeline.

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            app.UseCookieAuthentication(options => {
                options.AutomaticAuthentication = true;
                //options.AutomaticChallenge = true;
                options.LoginPath = new PathString("/login");
            });

            string githubClientId = this.Configuration["GitHubClientId"];
            string githubClientSecret = this.Configuration["GitHubClientSecret"];

            // Add GitHub Authentication
            // http://www.jerriepelser.com/blog/introduction-to-aspnet5-generic-oauth-provider
            // https://github.com/aspnet/Security/blob/dev/samples/SocialSample/Startup.cs
            app.UseOAuthAuthentication(new OAuthOptions {
                AuthenticationScheme = "GitHub",
                DisplayName = "Github",
                ClientId = githubClientId,
                ClientSecret = githubClientSecret,
                CallbackPath = new PathString("/signin-github"),
                AuthorizationEndpoint = "https://github.com/login/oauth/authorize",
                TokenEndpoint = "https://github.com/login/oauth/access_token",
                SaveTokensAsClaims = false,
                UserInformationEndpoint = "https://api.github.com/user",
                // Retrieving user information is unique to each provider.
                Events = new OAuthEvents {
                    OnCreatingTicket = async context => {
                        // Get the GitHub user

                        var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);
                        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);
                        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                        var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted);
                        response.EnsureSuccessStatusCode();

                        var githubUser = JObject.Parse(await response.Content.ReadAsStringAsync());

                        var id = githubUser.Value<int>("id");
                        if (id < 1) {
                            throw new ArgumentNullException("id");
                        }
                        var login = githubUser.Value<string>("login");
                        var name = githubUser.Value<string>("name");
                        var avitarUrl = githubUser.Value<string>("avatar_url");

                        User user = userRepository.GetByGitHubId(id) ?? new User { GitHubId = id };
                        user.Login = login;
                        user.Name = name;
                        user.AvitarUrl = avitarUrl;
                        userRepository.Save(user);

                        context.Identity.AddClaim(new Claim(
                            ClaimTypes.NameIdentifier, user.UserId.ToString()
                        ));

                        if (!string.IsNullOrEmpty(name)) {
                            context.Identity.AddClaim(new Claim(
                                "urn:github:name", name,
                                ClaimValueTypes.String, context.Options.ClaimsIssuer
                            ));
                        }
                        if (!string.IsNullOrEmpty(avitarUrl)) {
                            context.Identity.AddClaim(new Claim(
                                "urn:github:avitar", avitarUrl,
                                ClaimValueTypes.String, context.Options.ClaimsIssuer
                            ));
                        }

                        if (user.IsAdmin) {
                            context.Identity.AddClaim(new Claim(
                                ClaimTypes.Role, "admin"
                            ));
//.........这里部分代码省略.........
开发者ID:robrich,项目名称:api-inator,代码行数:101,代码来源:Startup.cs


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