Beispiel #1
0
        public async Task <OAuthUser> RegisterViaGithub(GithubRegistrationData data, GithubUserInfo githubUserInfo)
        {
            var githubUser = new OAuthUser();

            if (!oAuthService.IsGithubUserRegistered(githubUserInfo.Id))
            {
                var user = dbContext.Users.FirstOrDefault(u => u.Email == githubUserInfo.Email);
                if (user == null)
                {
                    user = dbContext.Users.Add(new User
                    {
                        UserName        = githubUserInfo.Login,
                        Email           = githubUserInfo.Email,
                        IsActive        = true,
                        ActivationToken = null
                    }).Entity;
                }
                githubUser = new OAuthUser
                {
                    User    = user,
                    OAuthId = githubUserInfo.Id,
                    Email   = githubUserInfo.Email,
                    Login   = githubUserInfo.Login
                };
                dbContext.OAuthUsers.Add(githubUser);

                await dbContext.SaveChangesAsync();
            }

            return(githubUser);
        }