示例#1
0
        public ActionResult Index(string xmlFileName)
        {
            if (String.IsNullOrEmpty(xmlFileName))
            {
                ViewData["Error"] = "You have to provide file name!";
                return(View());
            }
            if (!(xmlFileName.EndsWith(".xml", true, null)))
            {
                xmlFileName += ".xml";
            }

            AspDatabase db   = new AspDatabase();
            Root        root = db.LoadDataFromXmlDatabase();

            if (root != null)
            {
                XmlGenerator generator = new XmlGenerator();

                string path = Server.MapPath("~/App_Data/" + xmlFileName).ToString();

                generator.Generate(path, root);

                ViewData["Message"] = "Download succesful! Xml saved to " + path;
            }
            else
            {
                ViewData["Error"] = "Download failed!";
            }
            return(View());
        }
示例#2
0
        public ActionResult LogOn(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                if (ValidateUser(model.UserName, model.Password))
                {
                    AspDatabase db = new AspDatabase();

                    int logonResult = db.LogOnUser(model);

                    if (logonResult == 1)
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, false);

                        var    authTicket      = new FormsAuthenticationTicket(model.UserName, false, 1);
                        string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                        var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                        HttpContext.Response.Cookies.Add(authCookie);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else if (logonResult == 0)
                    {
                        ModelState.AddModelError("", "The user \"" + model.UserName + "\" doesn't exsist.");
                    }
                    else if (logonResult == -1)
                    {
                        ModelState.AddModelError("", "The password provided is incorrect.");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Something went wrong with database connection.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
            else
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            return(View(model));
        }
示例#3
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (ValidateUser(model.UserName, model.Password, model.ConfirmPassword))
                {
                    if (model.Password.Equals(model.ConfirmPassword))
                    {
                        AspDatabase db = new AspDatabase();

                        int registerResult = db.RegisterUser(model);

                        if (registerResult == 1)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        else if (registerResult == 0)
                        {
                            ModelState.AddModelError("", "The user name provided is already used.");
                        }
                        else if (registerResult == -1)
                        {
                            ModelState.AddModelError("", "The password provided doesn't match the pattern.");
                        }
                        else if (registerResult == -3)
                        {
                            ModelState.AddModelError("", "Something went wrong with regular expressions. Received " + model.SelectedRegex);
                        }
                        else
                        {
                            ModelState.AddModelError("", "Something went wrong with database connection.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Password and confirmation password doesn't match.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "User name or password provided is incorrect.");
                }
            }
            return(View(model));
        }
示例#4
0
        public ActionResult CreateRegex(RegexModel model)
        {
            if (ModelState.IsValid)
            {
                if (ValidateRule(model.Name))
                {
                    string createdRegex = RegexModel.CreateRegexString(model.MinLength, model.ChMinLength, model.MaxLength, model.ChMaxLength, model.MinUpperCase, model.ChUpperCase, model.MinLowerCase, model.ChLowerCase, model.MinSpecialSigns, model.ChSpecialSigns, model.MinDigits, model.ChDigits);

                    AspDatabase db = new AspDatabase();

                    int insertResult = db.InsertRegexIntoDatabase(model, createdRegex);

                    if (insertResult == 1)
                    {
                        return(RedirectToAction("CollectRule", "Regex", new { regex = model.Name + ": " + createdRegex }));
                    }
                    else if (insertResult == 0)
                    {
                        ModelState.AddModelError("", "The rule name provided is already used.");
                    }
                    else if (insertResult == -1)
                    {
                        ModelState.AddModelError("", "The rule with given parameters already exsists.");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Something went wrong with database connection.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The rule name provided is incorrect.");
                }
            }
            return(View(model));
        }