예제 #1
0
        public void SaveHistory(string query, string chart, string ctProper)
        {
            if (User.Identity.IsAuthenticated && chart != "table")
            {
                Models.User n = new Models.User();
                n.ID = n.GetUserId(User.Identity.Name);
                History h = new History();
                h.UserID          = Convert.ToInt32(n.ID);
                h.Query           = query;
                h.CreateDate      = DateTime.Now;
                h.ChartType       = chart;
                h.ChartTypeProper = ctProper;

                History.SaveHistory(h);
            }
        }
예제 #2
0
        public ActionResult Register(Models.User user)
        {
            if (ModelState.IsValid)
            {
                //Is the email address valid?
                if (ValidEmail(user.email))
                {
                    //If so, does the email exist already?
                    if (user.EmailExists(user.email))
                    {
                        ModelState.AddModelError("Email", "Email address already in use");
                    }
                }

                else
                {
                    ModelState.AddModelError("Email", "Email address is invalid");
                }

                if (user.password.Length < 5 || user.password.Length > 30)
                {
                    ModelState.AddModelError("Password", "Password must be between 5 and 30 characters");
                }
            }

            if (ModelState.IsValid)
            {
                if (user.Register(user.email, user.password))
                {
                    //Get the ID of the user
                    int userId = user.GetUserId(user.email);
                    int admin  = user.GetUserRole(user.email);
                    FormsAuthentication.SetAuthCookie(userId.ToString(), true);
                    Session["userID"] = userId;
                    Session["email"]  = user.email;
                    Session["admin"]  = admin;
                    return(RedirectToAction("Index", "Home"));
                }

                else
                {
                    ModelState.AddModelError("", "Registration failed");
                }
            }
            return(View(user));
        }
예제 #3
0
 public ActionResult Login(Models.User user)
 {
     if (ModelState.IsValid)
     {
         if (user.CheckLogon(user.email, user.password))
         {
             FormsAuthentication.SetAuthCookie(user.email, true);
             //Get the ID of the user
             int userId = user.GetUserId(user.email);
             int admin  = user.GetUserRole(user.email);
             FormsAuthentication.SetAuthCookie(userId.ToString(), true);
             Session["userID"] = userId;
             Session["email"]  = user.email;
             Session["admin"]  = admin;
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             ModelState.AddModelError("", "Login details were incorrect");
         }
     }
     return(View(user));
 }