Пример #1
0
        private bool Route(string file)
        {
            bool routed = false;

            switch (file)
            {
            case "/files/index.html":
                if (!this.User.IsLoggedIn)
                {
                    this.Redirect("/login/");
                    routed = true;
                }
                break;

            case "/files/logout.html":
                Cookie cookieUsername = new Cookie(User.COOKIE_USERNAME, "", "/");
                cookieUsername.Expired = true;
                cookieUsername.Expires = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
                Cookie cookiePassword = new Cookie(User.COOKIE_PASSWORD, "", "/");
                cookiePassword.Expired = true;
                cookiePassword.Expires = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
                this.Response.SetCookie(cookieUsername);
                this.Response.SetCookie(cookiePassword);
                this.Redirect("/");
                routed = true;
                break;

            case "/files/login.html":
                if (this.Request.HttpMethod == "POST")
                {
                    using (HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
                        if (postRequest.Parameters[User.COOKIE_USERNAME] != null && postRequest.Parameters[User.COOKIE_PASSWORD] != null)
                        {
                            User user = new User();
                            if (user.RefreshByUsernamePassword(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD]))
                            {
                                this.Response.SetCookie(new Cookie(User.COOKIE_USERNAME, user.Username, "/"));
                                this.Response.SetCookie(new Cookie(User.COOKIE_PASSWORD, user.Password, "/"));
                                this.Redirect("/");
                                routed = true;
                            }
                            else if (user.RefreshByEMailPassword(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD]))
                            {
                                this.Response.SetCookie(new Cookie(User.COOKIE_USERNAME, user.Username, "/"));
                                this.Response.SetCookie(new Cookie(User.COOKIE_PASSWORD, user.Password, "/"));
                                this.Redirect("/");
                                routed = true;
                            }
                            else
                            {
                                if (postRequest.Parameters[User.COOKIE_USERNAME] == this.DefaultAdminUserName && postRequest.Parameters[User.COOKIE_PASSWORD] == this.DefaultAdminUserPassword)
                                {
                                    user = new User(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD], UserAuthorization.Administrator, UserStatus.Active);
                                    this.Response.SetCookie(new Cookie(User.COOKIE_USERNAME, user.Username, "/"));
                                    this.Response.SetCookie(new Cookie(User.COOKIE_PASSWORD, user.Password, "/"));
                                    this.Redirect("/");
                                    routed = true;
                                }
                            }
                        }
                    }
                }
                break;

            case "/files/register.html":
                if (this.Request.HttpMethod == "POST")
                {
                    using (HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
                        if (postRequest.Parameters[User.COOKIE_USERNAME] != null && postRequest.Parameters[User.COOKIE_PASSWORD] != null && postRequest.Parameters["email_address"] != null)
                        {
                            if (!User.NameExists(postRequest.Parameters[User.COOKIE_USERNAME]))
                            {
                                if (!User.EMailExists(postRequest.Parameters["email_address"]))
                                {
                                    User newUser = new User(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD], postRequest.Parameters["email_address"]);
                                    newUser.Add();
                                }
                            }
                        }
                    }
                }
                break;
            }

            return(routed);
        }
		private bool Route(string file) {
			bool routed = false;

			switch(file) {
				case "/files/index.html":
					if (!this.User.IsLoggedIn) {
						this.Redirect("/login/");
						routed = true;
					}
					break;

				case "/files/logout.html":
					Cookie cookieUsername = new Cookie(User.COOKIE_USERNAME, "", "/");
					cookieUsername.Expired = true;
					cookieUsername.Expires = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
					Cookie cookiePassword = new Cookie(User.COOKIE_PASSWORD, "", "/");
					cookiePassword.Expired = true;
					cookiePassword.Expires = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
					this.Response.SetCookie(cookieUsername);
					this.Response.SetCookie(cookiePassword);
					this.Redirect("/");
					routed = true;
					break;
				
				case "/files/login.html":
					if (this.Request.HttpMethod == "POST") {
						using(HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
							if (postRequest.Parameters[User.COOKIE_USERNAME] != null && postRequest.Parameters[User.COOKIE_PASSWORD] != null) {
								User user = new User();
								if (user.RefreshByUsernamePassword(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD])) {
									this.Response.SetCookie(new Cookie(User.COOKIE_USERNAME, user.Username, "/"));
									this.Response.SetCookie(new Cookie(User.COOKIE_PASSWORD, user.Password, "/"));
									this.Redirect("/");
									routed = true;
								} else if (user.RefreshByEMailPassword(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD])) {
									this.Response.SetCookie(new Cookie(User.COOKIE_USERNAME, user.Username, "/"));
									this.Response.SetCookie(new Cookie(User.COOKIE_PASSWORD, user.Password, "/"));
									this.Redirect("/");
									routed = true;
								} else {
									if (postRequest.Parameters[User.COOKIE_USERNAME] == this.DefaultAdminUserName && postRequest.Parameters[User.COOKIE_PASSWORD] == this.DefaultAdminUserPassword) {
										user = new User(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD], UserAuthorization.Administrator, UserStatus.Active);
										this.Response.SetCookie(new Cookie(User.COOKIE_USERNAME, user.Username, "/"));
										this.Response.SetCookie(new Cookie(User.COOKIE_PASSWORD, user.Password, "/"));
										this.Redirect("/");
										routed = true;
									}
								}
							}
						}
					}
					break;
				
				case "/files/register.html":
					if (this.Request.HttpMethod == "POST") {
						using(HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
							if (postRequest.Parameters[User.COOKIE_USERNAME] != null && postRequest.Parameters[User.COOKIE_PASSWORD] != null && postRequest.Parameters["email_address"] != null) {
								if (!User.NameExists(postRequest.Parameters[User.COOKIE_USERNAME])) {
									if (!User.EMailExists(postRequest.Parameters["email_address"])) {
										User newUser = new User(postRequest.Parameters[User.COOKIE_USERNAME], postRequest.Parameters[User.COOKIE_PASSWORD], postRequest.Parameters["email_address"]);
										newUser.Add();
									}
								}
							}
						}
					}
					break;
			}

			return routed;
		}
Пример #3
0
        private void Mail(string rawUrl, NameValueCollection queryString)
        {
            if (!this.User.IsLoggedIn)
            {
                throw new UnauthorizedAccessException("access denied");
            }

            XmlNode    XmlRoot = this._doc.GetElementsByTagName(this._xmlRoot).Item(0);
            XmlElement XmlMail = this._doc.CreateElement("mail");

            rawUrl = Regex.Replace(rawUrl.Replace("/mail/", ""), "\\?.*", "", RegexOptions.Compiled);
            switch (rawUrl)
            {
            case "get":
                if (queryString["id"] != null && queryString["id"] != String.Empty)
                {
                    eMail mail = this.User.GetEMail(queryString["id"]);
                    if (mail != null)
                    {
                        XmlMail.SetAttribute("from", mail.MailFrom);
                        XmlMail.SetAttribute("to", mail.RecipientTo);
                        XmlMail.SetAttribute("subject", mail.Subject);

                        XmlElement XmlRecipients = this._doc.CreateElement("recipients");
                        XmlMail.AppendChild(XmlRecipients);

                        XmlElement XmlMessage = this._doc.CreateElement("message");
                        XmlMessage.InnerText = mail.Message;
                        XmlMail.AppendChild(XmlMessage);
                    }
                }
                break;

            case "write":
                if (this.Request.HttpMethod == "POST")
                {
                    using (HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
                        string toEMail = String.Empty;
                        string subject = String.Empty;
                        string message = String.Empty;

                        if (postRequest.Parameters["email"] != null)
                        {
                            toEMail = postRequest.Parameters["email"];
                        }
                        if (postRequest.Parameters["subject"] != null)
                        {
                            subject = postRequest.Parameters["subject"];
                        }
                        if (postRequest.Parameters["message"] != null)
                        {
                            message = postRequest.Parameters["message"];
                        }

                        eMail newEMail = new eMail();
                        newEMail.SetFrom(this.User.eMail);
                        newEMail.SetRecipient(toEMail);
                        newEMail.SetSubject(subject);
                        newEMail.SetMessage(message);

                        XmlMail.SetAttribute("from", newEMail.MailFrom);
                        XmlMail.SetAttribute("to", newEMail.RecipientTo);
                        XmlMail.SetAttribute("subject", newEMail.Subject);

                        XmlElement XmlRecipients = this._doc.CreateElement("recipients");

                        /*
                         * foreach(string recipient in newEMail.Recipients) {
                         *      XmlElement XmlRecipient = this._doc.CreateElement("recipient");
                         *      XmlRecipient.SetAttribute("email", recipient);
                         *      XmlRecipients.AppendChild(XmlRecipient);
                         * }
                         */
                        XmlMail.AppendChild(XmlRecipients);

                        XmlElement XmlMessage = this._doc.CreateElement("message");
                        XmlMessage.InnerText = newEMail.Message;
                        XmlMail.AppendChild(XmlMessage);

                        this.User.AddEMail(newEMail);
                        newEMail.Send();
                    }
                }
                break;
            }

            XmlRoot.AppendChild(XmlMail);
        }
		private void Mail(string rawUrl, NameValueCollection queryString) {
			if (!this.User.IsLoggedIn) {
				throw new UnauthorizedAccessException("access denied");
			}

			XmlNode XmlRoot = this._doc.GetElementsByTagName(this._xmlRoot).Item(0);
			XmlElement XmlMail = this._doc.CreateElement("mail");

			rawUrl = Regex.Replace(rawUrl.Replace("/mail/", ""), "\\?.*", "", RegexOptions.Compiled);
			switch(rawUrl) {
				case "get":
					if (queryString["id"] != null && queryString["id"] != String.Empty) {
						eMail mail = this.User.GetEMail(queryString["id"]);
						if (mail != null) {
							XmlMail.SetAttribute("from", mail.MailFrom);
							XmlMail.SetAttribute("to", mail.RecipientTo);
							XmlMail.SetAttribute("subject", mail.Subject);

							XmlElement XmlRecipients = this._doc.CreateElement("recipients");
							XmlMail.AppendChild(XmlRecipients);

							XmlElement XmlMessage = this._doc.CreateElement("message");
							XmlMessage.InnerText = mail.Message;
							XmlMail.AppendChild(XmlMessage);
						}
					}
					break;

				case "write":
					if (this.Request.HttpMethod == "POST") {
						using(HttpPostRequest.HttpPostRequest postRequest = new HttpPostRequest.HttpPostRequest(this.Request)) {
							string toEMail = String.Empty;
							string subject = String.Empty;
							string message = String.Empty;

							if (postRequest.Parameters["email"] != null) {
								toEMail = postRequest.Parameters["email"];
							}
							if (postRequest.Parameters["subject"] != null) {
								subject = postRequest.Parameters["subject"];
							}
							if (postRequest.Parameters["message"] != null) {
								message = postRequest.Parameters["message"];
							}

							eMail newEMail = new eMail();
							newEMail.SetFrom(this.User.eMail);
							newEMail.SetRecipient(toEMail);
							newEMail.SetSubject(subject);
							newEMail.SetMessage(message);

							XmlMail.SetAttribute("from", newEMail.MailFrom);
							XmlMail.SetAttribute("to", newEMail.RecipientTo);
							XmlMail.SetAttribute("subject", newEMail.Subject);

							XmlElement XmlRecipients = this._doc.CreateElement("recipients");
							/*
							foreach(string recipient in newEMail.Recipients) {
								XmlElement XmlRecipient = this._doc.CreateElement("recipient");
								XmlRecipient.SetAttribute("email", recipient);
								XmlRecipients.AppendChild(XmlRecipient);
							}
							*/
							XmlMail.AppendChild(XmlRecipients);

							XmlElement XmlMessage = this._doc.CreateElement("message");
							XmlMessage.InnerText = newEMail.Message;
							XmlMail.AppendChild(XmlMessage);

							this.User.AddEMail(newEMail);
							newEMail.Send();
						}
					}
					break;
			}

			XmlRoot.AppendChild(XmlMail);
		}