Exemple #1
0
        public AntdUsersModule()
        {
            Get["/users"] = _ => {
                var userConfiguration = new UserConfiguration();
                var list         = userConfiguration.Get();
                var manageMaster = new ManageMaster();
                list.Add(new User {
                    Name     = manageMaster.Name,
                    Password = manageMaster.Password
                });
                return(JsonConvert.SerializeObject(list));
            };

            Get["/users/list"] = x => {
                var master     = new ManageMaster().Name;
                var systemUser = new SystemUser();
                var users      = systemUser.GetAll()
                                 .Select(_ => new User {
                    Name = _, Password = ""
                });
                var model = new PageUsersModel {
                    Master = master,
                    Users  = users
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/users"] = x => {
                string user       = Request.Form.User;
                string password   = Request.Form.Password;
                var    systemUser = new SystemUser();
                var    hpwd       = systemUser.HashPasswd(password);
                var    mo         = new User {
                    Name     = user,
                    Password = hpwd
                };
                var userConfiguration = new UserConfiguration();
                userConfiguration.AddUser(mo);
                return(HttpStatusCode.OK);
            };

            Post["/users/master/password"] = x => {
                string password      = Request.Form.Password;
                var    masterManager = new ManageMaster();
                masterManager.ChangePassword(password);
                return(HttpStatusCode.OK);
            };
        }