public async Task<ActionResult> ValidateAsync(string googleCredentialsJson, string googleCalendarId, CancellationToken cancellationToken) { var calendar = new Calendar { GoogleCredentialsJson = googleCredentialsJson, GoogleCalendarId = googleCalendarId, UseGoogleCalendarByUser = true }; await calendar.AuthorizeAsync(this, cancellationToken); if (calendar.NeedRedirectToGoogle) return new RedirectResult(calendar.RedirectUri); if (calendar.Authorized) return RedirectToAction("ValidateAsync", "UserProfile"); ViewBag.Message = ValidationResource.UserProfile_GoogleCredentialsJsonValidationFailed_ErrorMessage; ViewBag.IsError = true; ViewBag.ShowForm = false; return View("Validate", "_PopupLayout"); }
private async Task<ModelStateDictionary> ValidateGoogleCredentialsJson(Controller controller, CancellationToken cancellationToken) { var modelStateDictionary = new ModelStateDictionary(); if (String.IsNullOrEmpty(GoogleCredentialsJson)) return modelStateDictionary; var calendar = new Calendar { GoogleCredentialsJson = GoogleCredentialsJson, GoogleCalendarId = GoogleCalendarId, UseGoogleCalendarByUser = true }; await calendar.AuthorizeAsync(controller, cancellationToken); if (!calendar.UseGoogleCalendar || calendar.Authorized) return modelStateDictionary; modelStateDictionary.AddModelError(BaseCache.GoogleCredentialsJsonField, ValidationResource.GoogleAPI_CannotAuthentizedUser_ErrorMessage); return modelStateDictionary; }
public static async Task<Calendar> GetCalendar(DefaultContext db, int registrarId, Controller controller, CancellationToken cancellationToken) { UserProfile userProfile = GetDetail(db, registrarId); var calendar = new Calendar { GoogleCredentialsJson = userProfile.GoogleCredentialsJson, GoogleCalendarId = userProfile.GoogleCalendarId, UseGoogleCalendarByUser = userProfile.UseGoogleCalendar, UseMail = userProfile.UseMail, EmailTo = userProfile.Email1, ReminderTime = userProfile.ReminderTime, IsEventsPrivate = userProfile.IsEventsPrivate }; await calendar.AuthorizeAsync(controller, cancellationToken); return calendar; }