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
            });
        }
Пример #2
0
        /// <summary>
        /// Creates the facebook profile.
        /// </summary>
        /// <param name="profileModel">The profile model.</param>
        /// <returns></returns>
        public async Task <bool> CreateFacebookProfile(OAuthCreateModel profileModel)
        {
            var facebookAccount = await _facebookAccountService.GetByFacebookId(profileModel.AccountId);

            if (facebookAccount != 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 _facebookAccountService.CreateFacebookAccount(inserted.UserProfileId, profileModel.AccountId));
        }