예제 #1
0
        public ActionResult RegisterFacebookMember(string appKey, string facebookKey, string firstName, string lastName, string email, string deviceId, string mobilePhoneNumber = null, string phoneModel = "iPhone")
        {
            var apiAccessRepo = new ApiAccessRepository();
            var apiAccess = apiAccessRepo.GetMemberByPublicApiKey(appKey);
            var apiAuthResult = new ApiAuthResult();

            if (null != apiAccess)
            {

                try
                {
                    var memberRepo = new MemberRepository();
                    var now = DateTime.Now;

                    var member = memberRepo.GetByFacebookKey(facebookKey);

                    if (null == member)
                    {
                        member = new Member();
                        member.FirstName = firstName;
                        member.LastName = lastName;
                        member.Email = email;
                        member.FacebookId = facebookKey;
                        member.DateCreated = now;
                        member.MemberTypeId = 1;
                    }
                    member.DateUpdated = now;
                    member.DateLastAccessed = now;

                    memberRepo.Save(member);

                    //Now Get User Auth Token
                    var authService = new AuthenticationService();
                    var auth = authService.GetAuthenticatedMemberLoginToken(apiAccess, member);
                    apiAuthResult.Success = auth.Success;
                    apiAuthResult.Description = auth.Reason;
                    apiAuthResult.AuthKey = auth.AuthKey;
                }catch(Exception e)
                {
                    apiAuthResult.Success = false;
                    apiAuthResult.Description = "Failed to save member and/or generate auth token";
                    apiAuthResult.AuthKey = "";
                }

            }else
            {
                apiAuthResult.Success = false;
                apiAuthResult.Description = "Invalid AppKey";
                apiAuthResult.AuthKey = "";
            }

            return this.ToXml(apiAuthResult);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filterContext"></param>
        /// 
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            var encryptedToken = filterContext.HttpContext.Request[AUTH_TOKEN]; //Get Token from client app

            var authService = new AuthenticationService();
            var userAuthInfo = authService.GetUserAuthInfo(encryptedToken); //Decrypt token

            var validApiKey = this.repo.GetMemberByPublicApiKey(userAuthInfo.AppKey); //Get appkey and see if it's valid before proceeding

            filterContext.HttpContext.Items[AUTH_RESULT] = (null != validApiKey) ? userAuthInfo : null;
        }