Пример #1
0
        async Task <bool> PopulateGoogleAuthentication(string TilerUserID, string AccessToken, string RefreshToken, string GoogleEmail, DateTimeOffset ExpirationDate)
        {
            //ApplicationDbContext db = new ApplicationDbContext();
            TilerUser AppUser  = UserManager.FindById(TilerUserID);
            bool      RetValue = false;

            try
            {
                ThirdPartyCalendarAuthenticationModel NewAccountCalendarImportation = new ThirdPartyCalendarAuthenticationModel();
                string AuthenticationID = Guid.NewGuid().ToString();
                NewAccountCalendarImportation.TilerID      = TilerUserID;
                NewAccountCalendarImportation.ID           = AuthenticationID;
                NewAccountCalendarImportation.Token        = AccessToken;
                NewAccountCalendarImportation.RefreshToken = RefreshToken;
                NewAccountCalendarImportation.isLongLived  = false;
                NewAccountCalendarImportation.Email        = GoogleEmail;
                NewAccountCalendarImportation.Deadline     = ExpirationDate;
                NewAccountCalendarImportation.ProviderID   = ThirdPartyControl.CalendarTool.google.ToString();


                //await NewAccountCalendarImportation.refreshAuthenticationToken().ConfigureAwait(false);

                HttpContext myContext = System.Web.HttpContext.Current;
                ThirdPartyCalendarAuthenticationModelsController thirdPartyController = new ThirdPartyCalendarAuthenticationModelsController();
                await thirdPartyController.CreateGoogle(NewAccountCalendarImportation);

                RetValue = true;
            }
            catch
            {
                RetValue = false;
            }

            return(RetValue);
        }
Пример #2
0
        public async Task <ActionResult> CreateGoogle([Bind(Include = "ID,isLongLived,Email,Token,RefreshToken,ProviderID,Deadline")] ThirdPartyCalendarAuthenticationModel thirdPartyCalendarAuthentication, bool deletGoogleCalendarFromLog = false)
        {
            if (ModelState.IsValid)
            {
                bool makeAdditionCall = false;
                if (!deletGoogleCalendarFromLog)
                {
                    ThirdPartyCalendarAuthenticationModelsController thirdPartyController = new ThirdPartyCalendarAuthenticationModelsController();
                    if (System.Web.HttpContext.Current != null)// this helps save the reurn uri for notification
                    {
                        thirdPartyController.initializeCurrentURI(System.Web.HttpContext.Current.Request.Url.Authority);
                    }
                    bool successInCreation = await thirdPartyController.CreateGoogle(thirdPartyCalendarAuthentication).ConfigureAwait(false);

                    if (successInCreation)
                    {
                        ;
                    }
                    else
                    {
                        ;
                    }
                    return(RedirectToAction("ImportCalendar"));
                }
                else
                {
                    Object[] Param = { thirdPartyCalendarAuthentication.TilerID, thirdPartyCalendarAuthentication.Email, thirdPartyCalendarAuthentication.ProviderID };
                    ThirdPartyCalendarAuthenticationModel checkingThirdPartyCalendarAuthentication = await dbContext.ThirdPartyAuthentication.FindAsync(Param);

                    if (checkingThirdPartyCalendarAuthentication != null)
                    {
                        await deleteGoogleAccount(thirdPartyCalendarAuthentication.getThirdPartyOut()).ConfigureAwait(false);
                    }
                }
                return(RedirectToAction("ImportCalendar"));
            }

            return(View("ImportCalendar"));
        }