/// <summary> /// 确定地址合法性 /// </summary> private static bool CheckPathLegal(string path) { if (!File.Exists(path) || !SupportTypes.Exists(x => x == Path.GetExtension(path))) { return(false); } return(true); }
private SupportTypes GetPreferredSupportType() { var authData = CheckPoint.Instance.GetAuthenticatedData(); SupportTypes supportType = SupportTypes.DEFAULT; if (authData.ContainsKey(CheckPoint.AUTH_DATA_SUPPORT_METHOD) && !string.IsNullOrEmpty(authData[CheckPoint.AUTH_DATA_SUPPORT_METHOD])) { Enum.TryParse <SupportTypes>(authData[CheckPoint.AUTH_DATA_SUPPORT_METHOD], out supportType); } // If the user's account doesn't specify a support method, and Trifolia is configured with a default support method, use it if (supportType == SupportTypes.DEFAULT && !string.IsNullOrEmpty(AppSettings.DefaultSupportMethod)) { Enum.TryParse <SupportTypes>(AppSettings.DefaultSupportMethod, out supportType); } // If the user is configured with a specific support type, make sure it is supported by config // Otherwise, choose a default support type based on config if (supportType != SupportTypes.DEFAULT) { if (supportType == SupportTypes.JIRA && !AppSettings.EnableJiraSupport) { supportType = SupportTypes.EMAIL; } if (supportType == SupportTypes.EMAIL && string.IsNullOrEmpty(AppSettings.SupportEmailTo)) { supportType = SupportTypes.URL; } if (supportType == SupportTypes.URL && string.IsNullOrEmpty(AppSettings.RedirectURL)) { supportType = SupportTypes.DEFAULT; } } else { if (AppSettings.EnableJiraSupport) { supportType = SupportTypes.JIRA; } else if (!string.IsNullOrEmpty(AppSettings.SupportEmailTo)) { supportType = SupportTypes.EMAIL; } else if (!string.IsNullOrEmpty(AppSettings.RedirectURL)) { supportType = SupportTypes.URL; } } return(supportType); }
public dynamic SupportConfig() { SupportTypes supportType = GetPreferredSupportType(); string method = "NONE"; if (supportType == SupportTypes.JIRA || supportType == SupportTypes.EMAIL) { method = "POPUP"; } else if (supportType == SupportTypes.URL) { method = "URL"; } return(new { Method = method, RedirectUrl = supportType == SupportTypes.URL ? AppSettings.RedirectURL : string.Empty }); }
public async Task SupportInit(IDialogContext context, LuisResult result) { if (result.Entities.Count == 0) { await context.PostAsync("Sorry, I didn't get what your problem is about."); context.Call(new SupportDialog(), this.ResumeAfterDialog); } else { foreach (EntityRecommendation entity in result.Entities) { SupportTypes typeOfSupport = getSupportType(entity); if (typeOfSupport == SupportTypes.NotResolved) { await context.PostAsync("I understand you have a problem but unfortunately can't understand what you mean by '" + entity.Entity + "'."); context.Call(new SupportDialog(), this.ResumeAfterDialog); } else { string greeting = DateTime.Now.TimeOfDay > new TimeSpan(12, 0, 0) ? "Good afternoon" : "Good morning"; await context.PostAsync(greeting + " Andy. I see you are in the Tontine building today. "); if (typeOfSupport == SupportTypes.MachineRelated) { await context.PostAsync("I understand you're having issue with your computer. Please answer the following questions: "); context.Call(new MachineSupportDialog(), this.ResumeAfterDialog); } else if (typeOfSupport == SupportTypes.Printer) { context.Call(new PrinterSupportDialog(), this.ResumeAfterDialog); } } } } }
private ActionResult OAuthCallback() { if (!string.IsNullOrEmpty(this.Request.QueryString["session_state"])) { Log.For(this).Trace("Removing the session_state param from the auth request"); var uri = new Uri(this.Request.Url.ToString()); // this gets all the query string key value pairs as a collection var newQueryString = HttpUtility.ParseQueryString(uri.Query); // this removes the key if exists newQueryString.Remove("session_state"); // this gets the page path from root without QueryString string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); var newUrl = newQueryString.Count > 0 ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) : pagePathWithoutQueryString; Log.For(this).Trace("Redirecting the user back to this route without the session_state param"); return(Redirect(newUrl)); } Log.For(this).Trace("Processing user authorization: " + this.Request.RawUrl); var auth = this.authClient.ProcessUserAuthorization(this.Request); var userInfo = OAuth2UserInfo.GetUserInfo(auth.AccessToken); var foundUser = this.tdb.Users.SingleOrDefault(y => y.UserName == userInfo.user_id); // If the user has migration information (the account that they are moving from) in their // profile, update trifolia so that it has the same userName/user_id. if (foundUser == null && userInfo.app_metadata != null && userInfo.app_metadata.migrated_account != null) { Log.For(this).Info("Migrating user account " + userInfo.app_metadata.migrated_account); var migratingUser = this.tdb.Users.SingleOrDefault(y => y.Id == userInfo.app_metadata.migrated_account.internalId && y.UserName == userInfo.app_metadata.migrated_account.userName); if (migratingUser != null) { migratingUser.UserName = userInfo.user_id; foundUser = migratingUser; } this.tdb.SaveChanges(); } SupportTypes supportMethod = SupportTypes.DEFAULT; Enum.TryParse <SupportTypes>(userInfo.app_metadata != null ? userInfo.app_metadata.support_method : "", out supportMethod); string userData = string.Format("{0}={1};{2}={3}", CheckPoint.AUTH_DATA_OAUTH2_TOKEN, auth.AccessToken, CheckPoint.AUTH_DATA_SUPPORT_METHOD, supportMethod); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 2, userInfo.user_id, DateTime.Now, DateTime.Now.AddDays(20), true, userData); string encAuthTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encAuthTicket); if (auth.AccessTokenExpirationUtc != null) { faCookie.Expires = auth.AccessTokenExpirationUtc.Value; } Response.Cookies.Set(faCookie); if (foundUser == null) { return(NewProfile("/", userInfo.given_name, userInfo.family_name, userInfo.email, userInfo.phone)); } // If the user was trying to go somewhere specific, redirect the user there instead var returnUrlCookie = this.Request.Cookies[AUTH_RETURN_URL_COOKIE_NAME]; if (returnUrlCookie != null && !string.IsNullOrEmpty(returnUrlCookie.Value)) { // Set the auth return url cookie to expire immediately (24 hours ago, technically) so that the browser deletes the cookie HttpCookie removeCookie = new HttpCookie(AUTH_RETURN_URL_COOKIE_NAME); removeCookie.Expires = DateTime.Now.AddDays(-1d); Response.Cookies.Add(removeCookie); string[] returnUrls = returnUrlCookie.Value.Split(','); if (returnUrls.Length > 0) { return(Redirect(returnUrls[0])); } } return(Redirect("/")); }