Beispiel #1
0
 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'))))))));
Beispiel #2
0
 /// <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));
 }
Beispiel #3
0
 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')))))))))));