CreateOrUpdate() public method

public CreateOrUpdate ( RavenOverflow.Core.Entities.OAuthData oAuthData, string userName, string fullName, string email ) : RavenOverflow.Core.Entities.User
oAuthData RavenOverflow.Core.Entities.OAuthData
userName string
fullName string
email string
return RavenOverflow.Core.Entities.User
示例#1
0
        private Core.Entities.User AcceptFacebookOAuthToken(FacebookOAuthResult facebookOAuthResult)
        {
            Condition.Requires(facebookOAuthResult).IsNotNull();

            // Grab the code.
            string code = facebookOAuthResult.Code;

            // Grab the access token.
            FacebookOAuthClient facebookOAuthClient = FacebookOAuthClient;
            dynamic result = facebookOAuthClient.ExchangeCodeForAccessToken(code);

            var oauthData = new OAuthData
            {
                OAuthProvider = OAuthProvider.Facebook,
                AccessToken = result.access_token,
                ExpiresOn = DateTime.UtcNow.AddSeconds(result.expires)
            };

            // Now grab their info.
            var facebookWebClient = new FacebookWebClient(oauthData.AccessToken);
            dynamic facebookUser = facebookWebClient.Get("me");
            oauthData.Id = facebookUser.id;

            // Not sure how to Inject an IUserService because it requires a Session .. which I don't have.
            var userService = new UserService(DocumentSession);

            // Now associate this facebook user to an existing user OR create a new one.
            return userService.CreateOrUpdate(oauthData, facebookUser.username, facebookUser.name, facebookUser.email);
        }
        private ActionResult AcceptFacebookOAuthToken(FacebookOAuthResult facebookOAuthResult)
        {
            Condition.Requires(facebookOAuthResult).IsNotNull();

            // Grab the code.
            var code = facebookOAuthResult.Code;

            // Grab the access token.
            var facebookOAuthClient = FacebookOAuthClient;
            dynamic result = facebookOAuthClient.ExchangeCodeForAccessToken(code);

            OAuthData oauthData = new OAuthData
                                         {
                                             OAuthProvider = OAuthProvider.Facebook,
                                             AccessToken = result.access_token,
                                             ExpiresOn = DateTime.UtcNow.AddSeconds(result.expires)
                                         };

            // Now grab their info.
            var facebookWebClient = new FacebookWebClient(oauthData.AccessToken);
            dynamic facebookUser = facebookWebClient.Get("me");
            oauthData.Id = facebookUser.id;

            // Now associate this facebook user to an existing user OR create a new one.
            UserService userService = new UserService(DocumentSession);
            var user = userService.CreateOrUpdate(oauthData, facebookUser.username, facebookUser.name, facebookUser.email);

            return Json(user, JsonRequestBehavior.AllowGet);
        }