public async Task <UserLoginTokenModel> LoginWithOpenAuth([FromQuery] string auth, [FromQuery] string id)
        {
            UserProfile user;

            switch (auth)
            {
            case "google":
                var googleAccount = await _googleAccountService.GetByGoogleId(id);

                if (googleAccount == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.Accepted;
                    return(null);
                }

                Response.StatusCode = (int)HttpStatusCode.OK;
                user = await _userProfileService.GetById(googleAccount.UserProfileId);

                break;

            case "facebook":
                var facebookAccount = await _facebookAccountService.GetByFacebookId(id);

                if (facebookAccount == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.Accepted;
                    return(null);
                }

                Response.StatusCode = (int)HttpStatusCode.OK;
                user = await _userProfileService.GetById(facebookAccount.UserProfileId);

                break;

            default:
                Response.StatusCode = (int)HttpStatusCode.NoContent;
                return(null);
            }

            var token = BuildToken(user.UserProfileId, user.Email);

            Response.StatusCode = (int)HttpStatusCode.OK;
            return(new UserLoginTokenModel
            {
                UserId = user.UserProfileId.ToString(),
                Jwt = token
            });
        }
Exemple #2
0
        /// <summary>
        /// Creates the google profile.
        /// </summary>
        /// <param name="profileModel">The profile model.</param>
        /// <returns></returns>
        public async Task <bool> CreateGoogleProfile(OAuthCreateModel profileModel)
        {
            var googleAccount = await _googleAccountService.GetByGoogleId(profileModel.AccountId);

            if (googleAccount != null)
            {
                return(false);
            }
            var userProfile = new UserProfile
            {
                Email     = profileModel.Email,
                FirstName = profileModel.FirstName,
                LastName  = profileModel.LastName,
                PhotoUrl  = profileModel.PhotoUrl
            };
            var inserted = _userProfileRepository.Insert(userProfile).Entity;

            return(await _googleAccountService.CreateGoogleAccount(inserted.UserProfileId, profileModel.AccountId));
        }