/// <summary>Returns the full and complete URL as a single string.</summary> public static string ToFull(this IHttpUrl url) { var sb = new StringBuilder(256); sb.Append(url.Https ? "https://" : "http://"); sb.Append(url.Domain); if (url.ParentDomains != null) { for (int i = url.ParentDomains.Length - 1; i >= 0; i--) { sb.Append(url.ParentDomains[i]); } } if ((!url.Https && url.Port != 80) || (url.Https && url.Port != 443)) { sb.Append(':'); sb.Append(url.Port); } if (url.ParentPaths != null) { for (int i = 0; i < url.ParentPaths.Length; i++) { sb.Append(url.ParentPaths[i]); } } sb.Append(url.Path); url.AppendQueryString(sb, first: true); return(sb.ToString()); }
private HttpResponse register(HttpRequest req, IHttpUrl redirectTo) => withSession(req, (session, db) => { var username = req.Post["username"].Value; if (string.IsNullOrWhiteSpace(username)) { return(loginPage(req, redirectTo, registerErrorMessage: "Your username cannot be empty.")); } var email = req.Post["email"].Value; if (!string.IsNullOrWhiteSpace(email) && db.Users.Any(u => u.Username == username || u.EmailAddress == username || u.Username == email || u.EmailAddress == email)) { return(loginPage(req, redirectTo, registerErrorMessage: "I’m afraid that username oder email address is already taken! Maybe you can just reset your password and re-use that account?")); } var password = req.Post["password1"].Value; if (req.Post["password2"].Value != password) { return(loginPage(req, redirectTo, registerErrorMessage: "The two passwords don’t match. Please try again.")); } var newUser = db.Users.Add(new User { Username = username, EmailAddress = string.IsNullOrWhiteSpace(req.Post["email"].Value) ? null : req.Post["email"].Value, PasswordHash = createPasswordHash(password), ShowErrors = true, SemitransparentXs = false }); db.SaveChanges(); session.User = newUser; //if (!string.IsNullOrWhiteSpace(email) && email.Contains('@')) // sendMail($"Kyudosudoku registration", // $"<p style='font-weight: bold'>Thank you for registering for Kyudosudoku!</p>" + // $"<p>Your username is {username}.</p>" + // $"<p>You can <a href='{redirectTo.ToFull()}'>log in</a> at any time.", // new MailAddress(email, username)); return(HttpResponse.Redirect(redirectTo)); });
private HttpResponse logout(HttpRequest req, IHttpUrl redirectTo) => withSession(req, (session, db) => { if (session != null) { session.Action = SessionAction.Delete; } return(HttpResponse.Redirect(redirectTo)); });
public UrlWithoutQueryMultiple(IHttpUrl source, HashSet <string> names) : base(source) { if (names == null) { throw new ArgumentNullException("names"); } _names = names; }
private HttpResponse loginPage(HttpRequest req, IHttpUrl url, string loginErrorMessage = null, string registerErrorMessage = null) => RenderPage( "Log in", null, null, new DIV { class_ = "main" }._( new H1("Log in"), loginErrorMessage.NullOr(error => new DIV { class_ = "error" }._(error)), new FORM { action = url.WithPath("/login").ToHref(), method = method.post }._( new TABLE( new TR(new TD(new LABEL { for_ = "login-username", accesskey = "u" }._("Username: "******"login-username", name = "username", type = itype.text, value = req?.Post["username"].Value })), new TR(new TD(new LABEL { for_ = "login-password", accesskey = "p" }._("Password: "******"login-password", name = "password", type = itype.password, value = req?.Post["password"].Value })), new TR(new TD(new BUTTON { type = btype.submit, accesskey = "l" }._("Log in".Accel('L')))))), new H1("Register a new user"), registerErrorMessage.NullOr(error => new DIV { class_ = "error" }._(error)), new FORM { action = url.WithPath("/register").ToHref(), method = method.post }._( new TABLE( new TR(new TD(new LABEL { for_ = "register-username", accesskey = "s" }._("Username: "******"register-username", name = "username", type = itype.text, value = req?.Post["username"].Value })), new TR(new TD(new LABEL { for_ = "register-password-1", accesskey = "a" }._("Password: "******"register-password-1", name = "password1", type = itype.password, value = req?.Post["password1"].Value })), new TR(new TD(new LABEL { for_ = "register-password-2", accesskey = "o" }._("Confirm password: "******"register-password-2", name = "password2", type = itype.password, value = req?.Post["password2"].Value })), new TR(new TD(new LABEL { for_ = "register-email", accesskey = "e" }._("Email address: ".Accel('E'))), new TD(new INPUT { id = "register-email", name = "email", type = itype.text, value = req?.Post["email"].Value }, " (this is not used for anything right now, no emails are sent to this)")), new TR(new TD(new BUTTON { type = btype.submit, accesskey = "r" }._("Register".Accel('R'))))))));
public UrlWithQueryWhereValues(IHttpUrl source, Func <string, string, bool> nameValueFilter) : base(source) { if (nameValueFilter == null) { throw new ArgumentException(); } _nameValueFilter = nameValueFilter; }
private HttpResponse updateUser(HttpRequest req, IHttpUrl redirectTo) => withSession(req, (session, db) => { if (session.User == null) { return(HttpResponse.Redirect(redirectTo)); } if (req.Post["user"].Value != session.User.UserID.ToString()) { return(userPage(req, redirectTo, session.User, db, updateUserError: "It appears that you logged out and back in as someone else. Please try again.")); } var changingPassword = !string.IsNullOrWhiteSpace(req.Post["password1"].Value); if (changingPassword) { if (!verifyPasswordHash(req.Post["oldpassword"].Value, session.User.PasswordHash)) { return(userPage(req, redirectTo, session.User, db, updateUserError: "The specified old password was not correct.")); } if (req.Post["password1"].Value != req.Post["password2"].Value) { return(userPage(req, redirectTo, session.User, db, updateUserError: "The two new passwords do not match.")); } } var messages = new List <string>(); var newUsername = req.Post["username"].Value; if (!string.IsNullOrWhiteSpace(newUsername) && newUsername != session.User.Username) { if (db.Users.Any(u => u.UserID != session.User.UserID && (u.Username == newUsername || u.EmailAddress == newUsername))) { return(userPage(req, redirectTo, session.User, db, updateUserError: "I’m afraid that username is already taken!")); } session.User.Username = newUsername; messages.Add("Username updated."); } var newEmail = req.Post["email"].Value; if (!string.IsNullOrWhiteSpace(newEmail) && newEmail != session.User.EmailAddress) { if (db.Users.Any(u => u.UserID != session.User.UserID && (u.Username == newEmail || u.EmailAddress == newEmail))) { return(userPage(req, redirectTo, session.User, db, updateUserError: "I’m afraid that email address is already taken!")); } session.User.EmailAddress = newEmail; messages.Add("Email address updated."); } if (changingPassword) { session.User.PasswordHash = createPasswordHash(req.Post["password1"].Value); messages.Add("Password updated."); } var changingGameOptions = false; foreach (var(curVal, setter, key) in Ut.NewArray <(bool curVal, Action <bool> setter, string key)>(
public UrlWithQueryMultiple(IHttpUrl source, string name, IEnumerable <string> values) : base(source) { if (name == null) { throw new ArgumentException(); } _name = name; _values = values ?? Enumerable.Empty <string>(); }
public UrlWithQuerySingle(IHttpUrl source, string name, string value) : base(source) { if (name == null) { throw new ArgumentException(); } _name = name; _value = value; }
/// <summary> /// Returns the full path and query string of the specified URL (the part that follows the domain).</summary> /// <remarks> /// This is intended to be used as <c>href</c> attribute values in <c><a></c> tags as it works well for an /// absolute path within the same domain.</remarks> public static string ToHref(this IHttpUrl url) { var sb = new StringBuilder(128); for (int i = 0; i < url.ParentPaths.Length; i++) { sb.Append(url.ParentPaths[i]); } sb.Append(url.Path); url.AppendQueryString(sb, first: true); return(sb.ToString()); }
public UrlWithPathParent(IHttpUrl source) : base(source) { if (source.ParentPaths.Length == 0) { throw new ArgumentException(); } if (source.ParentPaths.Length == 1) { _parentPaths = HttpHelper.EmptyStrings; } }
private UrlMapping[] getApplicableMappings(IHttpUrl url) { lock (Locker) { return(_mappings .Where(mp => ((mp.Hook.Protocols.HasFlag(Protocols.Http) && !url.Https) || (mp.Hook.Protocols.HasFlag(Protocols.Https) && url.Https)) && (mp.Hook.Port == null || mp.Hook.Port.Value == url.Port) && (mp.Hook.Domain == null || mp.Hook.Domain == url.Domain || (!mp.Hook.SpecificDomain && url.Domain.EndsWith("." + mp.Hook.Domain))) && (mp.Hook.Path == null || mp.Hook.Path == url.Path || (mp.Hook.Path == "" && url.Path == "/") || (!mp.Hook.SpecificPath && url.Path.StartsWith(mp.Hook.Path + "/")))) .ToArray()); } }
public UrlWithPathOnly(IHttpUrl source, string path) : base(source) { if (path == null) { throw new ArgumentNullException("path"); } if (path != "" && !path.StartsWith("/")) { throw new ArgumentException("The specified path must either be empty or begin with a slash ('/') character.", "path"); } _path = path; }
/// <summary> /// Returns the full domain name (the part that comes before the first slash) regardless of any URL resolvers in /// use. The protocol and the port number is not included.</summary> public static string GetFullDomain(this IHttpUrl url) { var sb = new StringBuilder(); sb.Append(url.Domain); if (url.ParentDomains != null) { for (int i = url.ParentDomains.Length - 1; i >= 0; i--) { sb.Append(url.ParentDomains[i]); } } return(sb.ToString()); }
/// <summary> /// Returns the full path (the part that comes after the domain) regardless of any URL resolvers in use. The query /// string is not included.</summary> public static string GetFullPath(this IHttpUrl url) { var sb = new StringBuilder(); if (url.ParentPaths != null) { for (int i = 0; i < url.ParentPaths.Length; i++) { sb.Append(url.ParentPaths[i]); } } sb.Append(url.Path); return(sb.ToString()); }
private HttpResponse login(HttpRequest req, IHttpUrl redirectTo) => withSession(req, (session, db) => { var username = req.Post["username"].Value; var user = db.Users.FirstOrDefault(u => u.Username == username) ?? db.Users.FirstOrDefault(u => u.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase) || u.EmailAddress.Equals(username, StringComparison.InvariantCultureIgnoreCase)); if (user == null) { return(loginPage(req, req.Url.WithPathParent(), "The specified username does not exist.")); } if (!verifyPasswordHash(req.Post["password"].Value, user.PasswordHash)) { return(loginPage(req, req.Url.WithPathParent(), "The specified password is not correct.")); } session.User = user; return(HttpResponse.Redirect(redirectTo)); });
/// <summary> /// Changes a URL’s subpath or subdomain relative to the specified number of URL resolvers.</summary> /// <param name="url"> /// The URL to modify.</param> /// <param name="levels"> /// The number of URL resolvers to rewind.</param> /// <param name="pathOrSubdomain"> /// The new subpath or subdomain, without any slashes or dots.</param> /// <param name="useSubdomain"> /// If <c>true</c>, the subdomain is changed; if <c>false</c> (default), the path is changed.</param> /// <param name="retainQueryParams"> /// If <c>true</c>, the query parameters are retained; if <c>false</c> (default), they are removed.</param> /// <returns> /// The new URL.</returns> public static IHttpUrl WithParents(this IHttpUrl url, int levels, string pathOrSubdomain, bool useSubdomain = false, bool retainQueryParams = false) { pathOrSubdomain = pathOrSubdomain.Length == 0 ? "" : useSubdomain ? pathOrSubdomain + "." : "/" + pathOrSubdomain; for (int i = 0; i < levels; i++) { url = useSubdomain ? url.WithDomainParent() : url.WithPathParent(); } return (useSubdomain ? retainQueryParams ? url.WithDomain(pathOrSubdomain) : url.WithDomain(pathOrSubdomain).WithoutQuery() : retainQueryParams ? url.WithPath(pathOrSubdomain) : url.WithPathOnly(pathOrSubdomain)); }
/// <summary> /// Creates a new instance based on the specified other URL.</summary> /// <param name="source"> /// URL to copy information from.</param> public HttpUrl(IHttpUrl source) { if (source == null) { throw new ArgumentNullException("source"); } Https = source.Https; Port = source.Port; ParentDomains = source.ParentDomains; Domain = source.Domain; ParentPaths = source.ParentPaths; Path = source.Path; _hasQuery = source.HasQuery; _query = source.Query; _queryString = null; }
public UrlWithDomain(IHttpUrl source, string domain) : base(source) { if (domain == null) { throw new ArgumentNullException("domain"); } if (ParentDomains.Length == 0 && (domain == "" || domain.EndsWith("."))) { throw new ArgumentException("At the TLD level the domain name must not be empty and must not end with a dot (.)."); } if (ParentDomains.Length > 0 && domain != "" && !domain.EndsWith(".")) { throw new ArgumentException("The domain name must be empty or end with a dot."); } _domain = domain; }
public UrlWithPath(IHttpUrl source, string path) : base(source) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Contains('?')) { throw new ArgumentException("The Path must not contain a question mark. Did you forget to escape the URL?"); } if (path != "" && path[0] != '/') { throw new ArgumentException("The Path must start with a forward slash."); } _path = path; }
private static IEnumerable <string> generateDirectoryXml(string localPath, IHttpUrl url, string urlPath) { List <DirectoryInfo> dirs = new List <DirectoryInfo>(); List <FileInfo> files = new List <FileInfo>(); DirectoryInfo dirInfo = new DirectoryInfo(localPath); foreach (var d in dirInfo.GetDirectories()) { dirs.Add(d); } foreach (var f in dirInfo.GetFiles()) { files.Add(f); } dirs.Sort((a, b) => a.Name.CompareTo(b.Name)); files.Sort((a, b) => a.Name.CompareTo(b.Name)); yield return("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); yield return("<?xml-stylesheet href=\"{0}\" type=\"text/xsl\" ?>\n".Fmt(url.WithPathOnly("/$/directory-listing/xsl").ToHref().HtmlEscape())); yield return("<directory url=\"{0}\" unescapedurl=\"{1}\" img=\"{2}\" numdirs=\"{3}\" numfiles=\"{4}\">\n" .Fmt(url.ToHref().HtmlEscape(), url.ToHref().UrlUnescape().HtmlEscape(), url.WithPathOnly("/$/directory-listing/icons/folderbig").ToHref().HtmlEscape(), dirs.Count, files.Count)); foreach (var d in dirs) { yield return(" <dir link=\"{0}/\" img=\"{2}\">{1}</dir>\n".Fmt(d.Name.UrlEscape(), d.Name.HtmlEscape(), url.WithPathOnly("/$/directory-listing/icons/folder").ToHref().HtmlEscape())); } foreach (var f in files) { string extension = f.Name.Contains('.') ? f.Name.Substring(f.Name.LastIndexOf('.') + 1) : ""; yield return(" <file link=\"{0}\" size=\"{1}\" nicesize=\"{2}\" img=\"{3}\">{4}</file>\n" .Fmt(f.Name.UrlEscape(), f.Length, Ut.SizeToString(f.Length), url.WithPathOnly("/$/directory-listing/icons/" + GetDirectoryListingIconStr(extension)).ToHref().HtmlEscape(), f.Name.HtmlEscape())); } yield return("</directory>\n"); }
public UrlWithoutQueryMultiple(IHttpUrl source, IEnumerable<string> names) : this(source, names.ToHashSet()) { }
public UrlWithQueryWhereValues(IHttpUrl source, Func<string, string, bool> nameValueFilter) : base(source) { if (nameValueFilter == null) throw new ArgumentException(); _nameValueFilter = nameValueFilter; }
public UrlWithQueryRemovals(IHttpUrl source) : base(source) { }
public UrlWithoutQueryMultiple(IHttpUrl source, HashSet<string> names) : base(source) { if (names == null) throw new ArgumentNullException("names"); _names = names; }
public UrlWithoutQueryAll(IHttpUrl source) : base(source) { }
/// <summary> /// Redirects the client to a new URL, using the HTTP status code 302 Found and making the response uncacheable.</summary> /// <param name="newUrl"> /// URL to redirect the client to.</param> public static HttpResponseContent Redirect(IHttpUrl newUrl) { return Redirect(newUrl.ToFull()); }
public UrlWithQueryMultiple(IHttpUrl source, string name, IEnumerable<string> values) : base(source) { if (name == null) throw new ArgumentException(); _name = name; _values = values ?? Enumerable.Empty<string>(); }
public UrlWithHttps(IHttpUrl source, bool https) : base(source) { _https = https; }
public UrlWithDomain(IHttpUrl source, string domain) : base(source) { if (domain == null) throw new ArgumentNullException("domain"); if (ParentDomains.Length == 0 && (domain == "" || domain.EndsWith("."))) throw new ArgumentException("At the TLD level the domain name must not be empty and must not end with a dot (.)."); if (ParentDomains.Length > 0 && domain != "" && !domain.EndsWith(".")) throw new ArgumentException("The domain name must be empty or end with a dot."); _domain = domain; }
private HttpResponse loginForm(string returnto, bool failed, string username, string password, IHttpUrl formSubmitUrl) { return HttpResponse.Html( new HTML( new HEAD( new TITLE("Log in"), new STYLELiteral(_formCss) ), new BODY( new FORM { method = method.post, action = formSubmitUrl.ToHref() }._( new DIV( returnto == null ? null : new INPUT { type = itype.hidden, name = "returnto", value = returnto }, new P("Please log in to access ", _appName, "."), failed ? new P("The specified username and/or password has not been recognised.") { class_ = "error" } : null, HtmlTag.HtmlTable(null, new object[] { "Username:"******"username", type = itype.text, size = 60, value = username } }, new object[] { "Password:"******"password", type = itype.password, size = 60, value = password } }, new[] { null, new INPUT { value = "Log in", type = itype.submit } } ) ) ) ) ) ); }
/// <summary> /// Redirects the client to a new URL, using the HTTP status code 302 Found and making the response uncacheable.</summary> /// <param name="newUrl"> /// URL to redirect the client to.</param> public static HttpResponseContent Redirect(IHttpUrl newUrl) { return(Redirect(newUrl.ToFull())); }
private HttpResponse userPage(HttpRequest req, IHttpUrl url, User user, Db db, string updateUserError = null, IEnumerable <string> updateUserSuccess = null, string teamError = null) => RenderPage( user.Username, user, null, new DIV { class_ = "main" }._( new H1("Welcome, ", new BDI(user.Username), "!"), new FORM { action = url.WithPath("/logout").ToHref(), method = method.post, class_ = "logout" }._( new BUTTON { type = btype.submit, accesskey = "o" }._("Log out".Accel('o'))), new H2("Options"), updateUserError.NullOr(msg => new DIV { class_ = "error" }._(msg)), updateUserSuccess.NullOr(msgs => new DIV { class_ = "success" }._(msgs.Count() == 1 ? (object)msgs.First() : new UL(msgs.Select(msg => new LI(msg))))), new FORM { action = url.WithPath("/update-user").ToHref(), method = method.post }._( new INPUT { type = itype.hidden, name = "user", value = user.UserID.ToString() }, new TABLE { class_ = "options" }._( new TR( new TH { rowspan = 2 }._("Game options"), new TD(new INPUT { type = itype.checkbox, name = "opt-show-errors", value = "1", checked_ = user.ShowErrors, id = "opt-show-errors", accesskey = "s" }, new LABEL { for_ = "opt-show-errors" }._(" Show a red glow around grids with errors".Accel('S')))), new TR(new TD(new INPUT { type = itype.checkbox, name = "opt-semitransparent-xs", value = "1", checked_ = user.SemitransparentXs, id = "opt-semitransparent-xs", accesskey = "x" }, new LABEL { for_ = "opt-semitransparent-xs" }._(" Show semitransparent X’s so you can still see the digits underneath".Accel('X')))), new TR( new TH("Personal info"), new TD( new TABLE( new TR(new TD { class_ = "label" }._(new LABEL { for_ = "changeusername", accesskey = "n" }._("Username: "******"changeusername", name = "username", type = itype.text, value = req?.Post["username"].Value ?? user.Username })), new TR(new TD { class_ = "label" }._(new LABEL { for_ = "changeemail", accesskey = "e" }._("Email address: ".Accel('E'))), new TD(new INPUT { id = "changeemail", name = "email", type = itype.email, value = req?.Post["email"].Value ?? user.EmailAddress })), new TR(new TD { class_ = "label" }._(new LABEL { for_ = "changepassword-old", accesskey = "p" }._("Old password: "******"changepassword-old", name = "oldpassword", type = itype.password, value = req?.Post["oldpassword"].Value })), new TR(new TD { class_ = "label" }._(new LABEL { for_ = "changepassword-new-1", accesskey = "1" }._("New password 1: ".Accel('1'))), new TD(new INPUT { id = "changepassword-new-1", name = "password1", type = itype.password, value = req?.Post["password1"].Value })), new TR(new TD { class_ = "label" }._(new LABEL { for_ = "changepassword-new-2", accesskey = "2" }._("New password 2: ".Accel('2'))), new TD(new INPUT { id = "changepassword-new-2", name = "password2", type = itype.password, value = req?.Post["password2"].Value })), new TR(new TD { class_ = "label" }._(new BUTTON { type = btype.submit, accesskey = "u" }._("Update".Accel('U')))))))))));
public UrlWithQueryChanges(IHttpUrl source) : base(source) { }
private HttpResponse createUserForm(string returnTo, bool userAlreadyExists, bool passwordsDiffer, string username, string newpassword1, string newpassword2, IHttpUrl formSubmitUrl) { return(HttpResponse.Html( new HTML( new HEAD( new TITLE("Create user"), new STYLELiteral(_formCss) ), new BODY( new FORM { method = method.post, action = formSubmitUrl.ToHref() }._( new DIV( returnTo == null ? null : new INPUT { type = itype.hidden, name = "returnto", value = returnTo }, new P("To create a new user, type the desired username and the new password twice."), userAlreadyExists ? new P("The specified username is already in use.") { class_ = "error" } : null, passwordsDiffer ? new P("The specified new passwords do not match. You have to type the same new password twice.") { class_ = "error" } : null, HtmlTag.HtmlTable(null, new object[] { "Username:"******"username", type = itype.text, size = 60, value = username } }, new object[] { "New password (1):", new INPUT { name = "newpassword1", type = itype.password, size = 60, value = newpassword1 } }, new object[] { "New password (2):", new INPUT { name = "newpassword2", type = itype.password, size = 60, value = newpassword2 } }, new[] { null, new INPUT { value = "Create user", type = itype.submit } } ) ) ) ) ) )); }
public UrlWithQuerySingle(IHttpUrl source, string name, string value) : base(source) { if (name == null) throw new ArgumentException(); _name = name; _value = value; }
private HttpResponse changePasswordForm(string loggedInUser, string returnTo, bool loginFailed, bool passwordsDiffer, string oldpassword, string newpassword1, string newpassword2, IHttpUrl formSubmitUrl) { return HttpResponse.Html( new HTML( new HEAD( new TITLE("Change Password"), new STYLELiteral(_formCss) ), new BODY( new FORM { method = method.post, action = formSubmitUrl.ToHref() }._( new DIV( returnTo == null ? null : new INPUT { type = itype.hidden, name = "returnto", value = returnTo }, new P("To change your password, type your old password, and then the new password twice."), loginFailed ? new P("The specified old password is wrong.") { class_ = "error" } : null, passwordsDiffer ? new P("The specified new passwords do not match. You have to type the same new password twice.") { class_ = "error" } : null, HtmlTag.HtmlTable(null, new object[] { "Username:"******"Old password:"******"password", type = itype.password, size = 60, value = oldpassword } }, new object[] { "New password (1):", new INPUT { name = "newpassword1", type = itype.password, size = 60, value = newpassword1 } }, new object[] { "New password (2):", new INPUT { name = "newpassword2", type = itype.password, size = 60, value = newpassword2 } }, new[] { null, new INPUT { value = "Change password", type = itype.submit } } ) ) ) ) ) ); }
public UrlWithPath(IHttpUrl source, string path) : base(source) { if (path == null) throw new ArgumentNullException("path"); if (path.Contains('?')) throw new ArgumentException("The Path must not contain a question mark. Did you forget to escape the URL?"); if (path != "" && path[0] != '/') throw new ArgumentException("The Path must start with a forward slash."); _path = path; }
public UrlWithoutQueryMultiple(IHttpUrl source, IEnumerable <string> names) : this(source, names.ToHashSet()) { }
private HttpResponse loginForm(string returnto, bool failed, string username, string password, IHttpUrl formSubmitUrl) { return(HttpResponse.Html( new HTML( new HEAD( new TITLE("Log in"), new STYLELiteral(_formCss) ), new BODY( new FORM { method = method.post, action = formSubmitUrl.ToHref() }._( new DIV( returnto == null ? null : new INPUT { type = itype.hidden, name = "returnto", value = returnto }, new P("Please log in to access ", _appName, "."), failed ? new P("The specified username and/or password has not been recognised.") { class_ = "error" } : null, HtmlTag.HtmlTable(null, new object[] { "Username:"******"username", type = itype.text, size = 60, value = username } }, new object[] { "Password:"******"password", type = itype.password, size = 60, value = password } }, new[] { null, new INPUT { value = "Log in", type = itype.submit } } ) ) ) ) ) )); }
private HttpResponse createUserForm(string returnTo, bool userAlreadyExists, bool passwordsDiffer, string username, string newpassword1, string newpassword2, IHttpUrl formSubmitUrl) { return HttpResponse.Html( new HTML( new HEAD( new TITLE("Create user"), new STYLELiteral(_formCss) ), new BODY( new FORM { method = method.post, action = formSubmitUrl.ToHref() }._( new DIV( returnTo == null ? null : new INPUT { type = itype.hidden, name = "returnto", value = returnTo }, new P("To create a new user, type the desired username and the new password twice."), userAlreadyExists ? new P("The specified username is already in use.") { class_ = "error" } : null, passwordsDiffer ? new P("The specified new passwords do not match. You have to type the same new password twice.") { class_ = "error" } : null, HtmlTag.HtmlTable(null, new object[] { "Username:"******"username", type = itype.text, size = 60, value = username } }, new object[] { "New password (1):", new INPUT { name = "newpassword1", type = itype.password, size = 60, value = newpassword1 } }, new object[] { "New password (2):", new INPUT { name = "newpassword2", type = itype.password, size = 60, value = newpassword2 } }, new[] { null, new INPUT { value = "Create user", type = itype.submit } } ) ) ) ) ) ); }
private HttpResponse changePasswordForm(string loggedInUser, string returnTo, bool loginFailed, bool passwordsDiffer, string oldpassword, string newpassword1, string newpassword2, IHttpUrl formSubmitUrl) { return(HttpResponse.Html( new HTML( new HEAD( new TITLE("Change Password"), new STYLELiteral(_formCss) ), new BODY( new FORM { method = method.post, action = formSubmitUrl.ToHref() }._( new DIV( returnTo == null ? null : new INPUT { type = itype.hidden, name = "returnto", value = returnTo }, new P("To change your password, type your old password, and then the new password twice."), loginFailed ? new P("The specified old password is wrong.") { class_ = "error" } : null, passwordsDiffer ? new P("The specified new passwords do not match. You have to type the same new password twice.") { class_ = "error" } : null, HtmlTag.HtmlTable(null, new object[] { "Username:"******"Old password:"******"password", type = itype.password, size = 60, value = oldpassword } }, new object[] { "New password (1):", new INPUT { name = "newpassword1", type = itype.password, size = 60, value = newpassword1 } }, new object[] { "New password (2):", new INPUT { name = "newpassword2", type = itype.password, size = 60, value = newpassword2 } }, new[] { null, new INPUT { value = "Change password", type = itype.submit } } ) ) ) ) ) )); }
public UrlWithPathOnly(IHttpUrl source, string path) : base(source) { if (path == null) throw new ArgumentNullException("path"); if (path != "" && !path.StartsWith("/")) throw new ArgumentException("The specified path must either be empty or begin with a slash ('/') character.", "path"); _path = path; }
/// <summary> /// Creates a new instance based on the specified other URL.</summary> /// <param name="source"> /// URL to copy information from.</param> public HttpUrl(IHttpUrl source) { if (source == null) throw new ArgumentNullException("source"); Https = source.Https; Port = source.Port; ParentDomains = source.ParentDomains; Domain = source.Domain; ParentPaths = source.ParentPaths; Path = source.Path; _hasQuery = source.HasQuery; _query = source.Query; _queryString = null; }
public UrlWithPathParent(IHttpUrl source) : base(source) { if (source.ParentPaths.Length == 0) throw new ArgumentException(); if (source.ParentPaths.Length == 1) _parentPaths = HttpHelper.EmptyStrings; }
private static IEnumerable<string> generateDirectoryXml(string localPath, IHttpUrl url, string urlPath) { List<DirectoryInfo> dirs = new List<DirectoryInfo>(); List<FileInfo> files = new List<FileInfo>(); DirectoryInfo dirInfo = new DirectoryInfo(localPath); foreach (var d in dirInfo.GetDirectories()) dirs.Add(d); foreach (var f in dirInfo.GetFiles()) files.Add(f); dirs.Sort((a, b) => a.Name.CompareTo(b.Name)); files.Sort((a, b) => a.Name.CompareTo(b.Name)); yield return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; yield return "<?xml-stylesheet href=\"{0}\" type=\"text/xsl\" ?>\n".Fmt(url.WithPathOnly("/$/directory-listing/xsl").ToHref().HtmlEscape()); yield return "<directory url=\"{0}\" unescapedurl=\"{1}\" img=\"{2}\" numdirs=\"{3}\" numfiles=\"{4}\">\n" .Fmt(url.ToHref().HtmlEscape(), url.ToHref().UrlUnescape().HtmlEscape(), url.WithPathOnly("/$/directory-listing/icons/folderbig").ToHref().HtmlEscape(), dirs.Count, files.Count); foreach (var d in dirs) yield return " <dir link=\"{0}/\" img=\"{2}\">{1}</dir>\n".Fmt(d.Name.UrlEscape(), d.Name.HtmlEscape(), url.WithPathOnly("/$/directory-listing/icons/folder").ToHref().HtmlEscape()); foreach (var f in files) { string extension = f.Name.Contains('.') ? f.Name.Substring(f.Name.LastIndexOf('.') + 1) : ""; yield return " <file link=\"{0}\" size=\"{1}\" nicesize=\"{2}\" img=\"{3}\">{4}</file>\n" .Fmt(f.Name.UrlEscape(), f.Length, Ut.SizeToString(f.Length), url.WithPathOnly("/$/directory-listing/icons/" + GetDirectoryListingIconStr(extension)).ToHref().HtmlEscape(), f.Name.HtmlEscape()); } yield return "</directory>\n"; }
public UrlWithNoChanges(IHttpUrl source) { _source = source; }