Exemplo n.º 1
0
 private void SelectUser()
 {
     if (Session["username"] != null && !Session["gs_name"].ToString().Equals(string.Empty))
     {
         List <userTable> list = can.selectUser().FindAll(f => f.gongsi.Equals(Session["gs_name"].ToString()));
         //YongHutable = list;
         YongHutable = new List <userTable>();
         foreach (userTable ut in list)
         {
             userTable addut = new userTable();
             addut._id        = ut._id;
             addut.Btype      = ut.Btype;
             addut.Createdate = ut.Createdate;
             addut._openid    = ut._openid;
             addut.gongsi     = ut.gongsi;
             addut.jigoudaima = ut.jigoudaima;
             addut.name       = ut.name;
             addut.password   = ut.password;
             addut.mi_bao     = ut.mi_bao;
             if (ut.AdminIS != null && ut.AdminIS.Equals("true"))
             {
                 addut.AdminIS = "管理员";
             }
             else
             {
                 addut.AdminIS = "普通用户";
             }
             YongHutable.Add(addut);
         }
         UserFor.DataSource = YongHutable;
         UserFor.DataBind();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request["type"] != null)
         {
             type = Request["type"].ToString();
             if (type == "update")
             {
                 id     = Request["id"].ToString();
                 gongsi = Request["gs"].ToString();
                 can    = new clsAllnew();
                 userTable ut = can.selectUser().Find(f => f.name.Equals(id) && f.gongsi.Equals(gongsi));
                 Name.Text  = ut.name;
                 Pwd.Text   = ut.password;
                 Qrpwd.Text = ut.password;
                 if (ut.AdminIS.Equals("true"))
                 {
                     quanxian.Items[0].Selected = true;
                 }
                 else
                 {
                     quanxian.Items[1].Selected = true;
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public ActionResult verifyUser(userTable verify)
        {
            ac.Entry(verify).State = EntityState.Modified;
            ac.SaveChanges();

            return(RedirectToAction("invalidUserList"));
        }
Exemplo n.º 4
0
        public ActionResult editProfile(userTable editPRO)
        {
            ac.Entry(editPRO).State = EntityState.Modified;
            ac.SaveChanges();

            return(RedirectToAction("LoggedIn"));
        }
Exemplo n.º 5
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;

                        using (userEntities entities = new userEntities())
                        {
                            userTable user = entities.userTables.SingleOrDefault(u => u.userName == username);

                            roles = user.userRole;
                        }
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Exemplo n.º 6
0
        public ActionResult Create(userTable u)
        {
            using (ac)
            {
                ac.userTables.Add(u);
                ac.SaveChanges();

                return(RedirectToAction("Login"));
            }
        }
Exemplo n.º 7
0
        public ActionResult Delete(deleteViewModel pModel)
        {
            userTable userToDelete = (from records in db.userTables
                                      where records.userID == pModel.selectedUserId
                                      select records).FirstOrDefault();

            ViewBag.user = userToDelete.userName;
            db.userTables.Remove(userToDelete);
            db.SaveChanges();

            return(RedirectToAction("DeleteConfirmed", "Admin", new { userName = userToDelete.userName }));
        }
Exemplo n.º 8
0
        public ActionResult LogOn(userTable model, string returnUrl)
        {
            var user = (from records in db.userTables
                        where records.userName == model.userName
                        select new { userName = records.userName, userPassword = records.userPassword });

            if (user.Count() == 0)
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            if (string.IsNullOrEmpty(model.userName))
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect");
            }

            if (string.IsNullOrEmpty(model.userPassword))
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect");
            }

            if (ModelState.IsValid)
            {
                bool valid = security.validatePassword(model.userPassword, user.First().userPassword);

                if (valid)
                {
                    FormsAuthentication.SetAuthCookie(model.userName, true);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public ActionResult Login(userTable u)
        {
            using (ac)
            {
                var usr = ac.userTables.SingleOrDefault(us => us.userName == u.userName && us.passWord == u.passWord);
                if (usr != null)
                {
                    Session["userID"]     = usr.userID.ToString();
                    Session["userName"]   = usr.userName.ToString();
                    Session["userStatus"] = usr.userStatus.ToString();
                    Session["role"]       = usr.role.ToString();
                    return(RedirectToAction("LoggedIn"));
                }

                else
                {
                    ModelState.AddModelError("", "User Name or Password is Wrong");
                }
            }

            return(View());
        }
        protected void queren_Click(object sender, EventArgs e)
        {
            try
            {
                string type = "";
                if (Request["type"] != null)
                {
                    type = Request["type"].ToString();
                }
                if (!type.Equals(string.Empty) && type.Equals("insert"))
                {
                    if (Pwd.Text.Equals(Qrpwd.Text))
                    {
                        can = new clsAllnew();
                        userTable ut = new userTable();
                        ut.name     = Name.Text;
                        ut.password = Pwd.Text;
                        ut._id      = Name.Text;
                        if (Session["gs_name"] != null)
                        {
                            ut.gongsi = Session["gs_name"].ToString();
                        }
                        if (quanxian.Items[quanxian.SelectedIndex].Text.Equals("管理员"))
                        {
                            ut.AdminIS = "true";
                        }
                        else
                        {
                            ut.AdminIS = "false";
                        }

                        int pd = can.add_User(ut);
                        if (pd > 0)
                        {
                            Response.Write("<script>alert('添加成功!');layer.close(layer.index);</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('两次密码输入不一致')</script>");
                    }
                }
                else
                {
                    if (Pwd.Text.Equals(Qrpwd.Text))
                    {
                        can = new clsAllnew();
                        userTable ut = new userTable();
                        ut._id      = id;
                        ut.name     = Name.Text;
                        ut.password = Pwd.Text;
                        ut._id      = Name.Text;
                        if (Session["gs_name"] != null)
                        {
                            ut.gongsi = Session["gs_name"].ToString();
                        }
                        if (quanxian.Items[quanxian.SelectedIndex].Text.Equals("管理员"))
                        {
                            ut.AdminIS = "true";
                        }
                        else
                        {
                            ut.AdminIS = "false";
                        }
                        int pd = can.up_User(ut);
                        if (pd > 0)
                        {
                            Response.Write("<script>alert('修改成功!');layer.close(layer.index);</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('两次密码输入不一致')</script>");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 11
0
        public ActionResult Add(adminViewModel pModel)
        {
            //super hackish but will work until roles table gets built in database
            List <role> roles = new List <role>();

            roles.Add(new role(1, "user"));
            roles.Add(new role(2, "admin"));
            pModel.roles = roles;
            string    passHash;
            userTable newUser = new userTable();

            //Validation
            var existingUser = (from records in db.userTables
                                where records.userName == pModel.userName
                                select new { uName = records.userName });

            if (existingUser.Count() != 0)
            {
                ModelState.AddModelError("userName", "User Name already exists, pick another User Name");
            }



            if (!string.IsNullOrEmpty(pModel.userName))
            {
                string regex = "([a-zA-Z0-9]){5,10}";
                Regex  re    = new Regex(regex);
                if (!re.IsMatch(pModel.userName))
                {
                    ModelState.AddModelError("userName", "Invalid User Name: User Name must be 5-10 characters and may only contain alphanumeric characters.");
                }
            }
            else
            {
                ModelState.AddModelError("userName", "User Name is Empty.");
            }

            if (!string.IsNullOrEmpty(pModel.userPasswordFirst))
            {
                string regex = @"(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}";
                Regex  re    = new Regex(regex);
                if (!re.IsMatch(pModel.userPasswordFirst))
                {
                    ModelState.AddModelError("userPasswordFirst", "Invalid password. Password must be at least 8 characters with at least one lowercase, one uppercase letter, and one digit.");
                }
            }
            else
            {
                ModelState.AddModelError("userPasswordFirst", "Password is Empty");
            }


            if (pModel.userPasswordFirst != pModel.userPasswordSecond)
            {
                ModelState.AddModelError("userPasswordSecond", "Passwords do not match");
            }
            else if (string.IsNullOrEmpty(pModel.userPasswordSecond))
            {
                ModelState.AddModelError("userPasswordSecond", "Password is Empty");
            }

            //add data

            if (ModelState.IsValid)
            {
                passHash         = security.createHash(pModel.userPasswordFirst);
                newUser.userName = pModel.userName;
                if (pModel.selectedRoleID == 1)
                {
                    newUser.userRole = "user";
                }
                else
                {
                    newUser.userRole = "admin";
                }
                newUser.userPassword = passHash;
                db.userTables.Add(newUser);
                db.SaveChanges();

                return(RedirectToAction("AddConfirmed", "Admin", new { userName = pModel.userName }));
            }

            else
            {
                return(View(pModel));
            }
        }
Exemplo n.º 12
0
        public ActionResult Update(changePassAdminViewModel pModel)
        {
            string userName = (from records in db.userTables
                               where records.userID == pModel.selectedUserId
                               select records.userName).FirstOrDefault();

            bool      valid = false;
            userTable user  = new userTable();

            //validate old password
            if (string.IsNullOrEmpty(pModel.oldPassInput))
            {
                ModelState.AddModelError("oldPassInput", "Password is Empty");
            }

            if (ModelState.IsValid)
            {
                var getUser = (from records in db.userTables
                               where records.userName == userName
                               select records);
                user  = getUser.FirstOrDefault();
                valid = security.validatePassword(pModel.oldPassInput, user.userPassword);
            }

            if (!valid)
            {
                ModelState.AddModelError("oldPassInput", "Invalid Password");
            }

            if (pModel.newPassInput != pModel.newPassInput2)
            {
                ModelState.AddModelError("newPassInput", "Passwords must match.");
            }
            else if (string.IsNullOrEmpty(pModel.newPassInput2))
            {
                ModelState.AddModelError("newPassInput2", "Password is Empty");
            }

            if (!string.IsNullOrEmpty(pModel.newPassInput))
            {
                string regex = @"(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}";
                Regex  re    = new Regex(regex);
                if (!re.IsMatch(pModel.newPassInput))
                {
                    ModelState.AddModelError("newPassInput", "Invalid password. Password must be at least 8 characters with at least one lowercase, one uppercase letter, and one digit.");
                }
            }
            else
            {
                ModelState.AddModelError("userPasswordFirst", "Password is Empty");
            }

            if (ModelState.IsValid)
            {
                string passHash = security.createHash(pModel.newPassInput2);
                user.userPassword = passHash;
                db.SaveChanges();
                return(RedirectToAction("passwordChanged", "Accounts"));
            }


            changePassAdminViewModel model = new changePassAdminViewModel(db.userTables.ToList());

            return(View(model));
        }