예제 #1
0
        public bool UpdateUser(User user)
        {
            var db = new Soway.Model.SqlServer.ObjectContext <User>(this.Con, this.ConFac);

            db.Save(user);
            return(true);
        }
예제 #2
0
        protected override void ImplementBusinessLogic()
        {
            var info = Info;


            Data.Token = this.PostData.Token;
            Data.Items = new List <AuthItem>();
            Data.Token = this.PostData.Token;


            var user = new Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.User>(new bean.ConHelper().GetSysCon(), this).GetDetail(info.User.UserId);

            if (user != null)
            {
                var authuser = new SOWAY.ORM.AUTH.AuthoriezedFactory(new Model.App.Application()
                {
                    SysCon = info.AppSqlCon
                }, this).GetAuthrizedUser(user);
                List <SOWAY.ORM.AUTH.MenuItem> auths = new List <SOWAY.ORM.AUTH.MenuItem>();
                if (String.IsNullOrEmpty(this.Option.ParentAuthCode))
                {
                    auths = new SOWAY.ORM.AUTH.MenuItemFactory(info.CurrentSqlCon, this).GetTopMenus(authuser);
                }
                else
                {
                    auths = new SOWAY.ORM.AUTH.MenuItemFactory(info.CurrentSqlCon, this).GetMenus(authuser, System.Convert.ToInt64(this.Option.ParentAuthCode));
                }
                foreach (var menu in auths.OrderBy(p => p.Index))
                {
                    var item = new Login.V2.AuthItem()
                    {
                        Text     = menu.Text,
                        AuthType = AuthType.ListView,
                        ImageUrl = menu.Image,
                        Note     = menu.Text,
                        ViewId   = menu.ViewID,
                        ViewType = Soway.Service.Login.V1.ViewType.List,
                        Index    = menu.Index,

                        AuthNo = menu.ID.ToString()
                    };
                    Data.Items.Add(item);
                }
            }
            else
            {
                this.Result.Error = new ErrorInfo()
                {
                    Code    = ErrorDescription.TOKEN_INVALIDAT,
                    Message = ErrorDescription.TOKEN_INVALIDAT_MSG
                }
                ;
            }
        }
예제 #3
0
        protected override void ImplementBusinessLogic()
        {
            var info = new CacheStore().Get(this.PostData.Token);

            if (info != null && info.User != null)
            {
                var user = new Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.User>(new bean.ConHelper().GetSysCon(), this).GetDetail(info.User.UserId);
                if (user != null)
                {
                    var authuser = new SOWAY.ORM.AUTH.AuthoriezedFactory(new Model.App.Application()
                    {
                        SysCon = info.AppSqlCon
                    }, this).GetAuthrizedUser(user);
                    List <SOWAY.ORM.AUTH.MenuItem> auths = new List <SOWAY.ORM.AUTH.MenuItem>();

                    auths = new SOWAY.ORM.AUTH.MenuItemFactory(info.CurrentSqlCon, this).GetTopMenus(authuser);
                    foreach (var menu in auths)
                    {
                        var item = new Login.V2.AuthItem()
                        {
                            Text     = menu.Text,
                            AuthType = AuthType.ListView,
                            ImageUrl = menu.Image,
                            Note     = menu.Text,
                            ViewId   = menu.ViewID,
                            ViewType = Login.V1.ViewType.List,
                            Index    = 0,

                            AuthNo = menu.ID.ToString()
                        };
                        Data.Items.Add(item);
                    }
                    //Data.UserID = user.ID;
                    //Data.UserShowName = user.Name;
                    //Data.UserAvtar = user.Str5;
                    //Data.IsLogin = true;


                    info.User.UserId       = user.UserID;
                    info.User.UserName     = user.FirstName + user.LastName;
                    info.User.UserAvtarUrl = user.Avtar;
                }
                else
                {
                    //Data.IsLogin = false;
                    Data.Error = new ErrorInfo(ErrorDescription.CODE_AUTHENTICATE_FAIL,
                                               ErrorDescription.MESSAGE_AUTHENTICATE_FAIL);
                }
            }
        }
예제 #4
0
        public User Login(String UserName, String Pwd)
        {
            var db   = new Soway.Model.SqlServer.ObjectContext <User>(this.Con, this.ConFac);
            var user = db.GetDetail(UserName);

            if (user.PassWord == ToMD5(Pwd))
            {
                user.PassWord = Pwd;
                return(user);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public bool ChangePassWord(String userName, string oldPwd, String newPwd)
        {
            var db   = new Soway.Model.SqlServer.ObjectContext <User>(this.Con, this.ConFac);
            var user = db.GetDetail(userName);

            if (user.PassWord == ToMD5(oldPwd))
            {
                user.PassWord = newPwd;
                db.Save(user);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
        protected override void ImplementBusinessLogic()
        {
            var info = this.Info;

            result.User    = info.User;
            result.Token   = this.PostData.Token;
            result.App     = info.App;
            result.TopMenu = new List <Login.V2.AuthItem>();


            var user = new Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.User>(new bean.ConHelper().GetSysCon(), this).GetDetail(info.User.UserId);

            if (user != null)
            {
                var authuser = new SOWAY.ORM.AUTH.AuthoriezedFactory(new Model.App.Application()
                {
                    SysCon = info.AppSqlCon
                }, this).GetAuthrizedUser(user);
                List <SOWAY.ORM.AUTH.MenuItem> auths = new SOWAY.ORM.AUTH.MenuItemFactory(info.CurrentSqlCon, this).GetTopMenus(authuser);
                foreach (var menu in auths)
                {
                    var item = new Login.V2.AuthItem()
                    {
                        Text     = menu.Text,
                        AuthType = AuthType.ListView,
                        ImageUrl = menu.Image,
                        Note     = menu.Text,
                        ViewId   = menu.ViewID,
                        ViewType = Soway.Service.Login.V1.ViewType.List,
                        Index    = 1,
                        AuthNo   = menu.ID.ToString()
                    };
                    result.TopMenu.Add(item);
                }
            }
        }
예제 #7
0
        public void RegUser(User user)
        {
            var db = new Soway.Model.SqlServer.ObjectContext <User>(this.Con, this.ConFac);

            db.Create(user);
        }
예제 #8
0
        public Soway.Model.App.Application CreatApp(Soway.Model.App.Application App)
        {
            var dbContext = new Soway.Model.SqlServer.ObjectContext <Soway.Model.App.Application>
                                (this.Con, this.ConFac);
            //1 创建应用

            var newApp = dbContext.Create(App);

            //2 创建应用系统库

            new Soway.Model.Manage.SqlServerModuleInstaller(this.ConFac).InstallModules
                (new Soway.Model.AssemblyModuleSource(
                    new Model.AssemblyModelFactory(typeof(Soway.Model.App
                                                          .Application))), App.SysCon, App.SysCon);


            new Soway.Model.Manage.SqlServerModuleInstaller(this.ConFac).InstallModules
                (new Soway.Model.AssemblyModuleSource(
                    new Model.AssemblyModelFactory(typeof(SOWAY.ORM.AUTH.AuthorizedUser))), App.SysCon, App.SysCon);
            //3 连接应用用户

            SOWAY.ORM.AUTH.AuthorizedUser user = new SOWAY.ORM.AUTH.AuthorizedUser();
            user.User = App.Creator;
            new Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.AuthorizedUser>(App.SysCon, this.ConFac).Create(user);
            var itemsStrs = new String[]
            {
                "Model列表", "Module列表", "SqlCon列表", "View列表", "MenuItem列表"
            };


            Dictionary <String, String> subItem = new Dictionary <string, string>();

            subItem.Add("Module列表", "业务包管理");
            subItem.Add("Model列表", "模型管理");
            subItem.Add("SqlCon列表", "连接管理");
            subItem.Add("View列表", "界面管理");
            subItem.Add("MenuItem列表", "菜单项管理");

            Dictionary <String, String> AuthItem = new Dictionary <string, string>();

            AuthItem.Add("AuthorizedUser列表", "授权用户管理");
            AuthItem.Add("Department列表", "部门管理");
            AuthItem.Add("Role列表", "角色管理");

            foreach (var db in App.DataBase)
            {   //4 创建应用数据库
                new Soway.Model.Manage.SqlServerModuleInstaller(this.ConFac).InstallModules
                    (new Soway.Model.AssemblyModuleSource(
                        new Model.AssemblyModelFactory(typeof(SOWAY.ORM.AUTH.User
                                                              ))), App.SysCon, db.Conection);
                //5 创建菜单
                SOWAY.ORM.AUTH.MenuItem item = new SOWAY.ORM.AUTH.MenuItem()
                {
                    Text = "系统管理", SubItems = new List <SOWAY.ORM.AUTH.MenuItem>()
                };
                foreach (var str in subItem.Keys)
                {
                    var view = new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).GetView(str);
                    view.ConnectionType = Model.ConnectionType.AppSys;

                    item.SubItems.Add(new SOWAY.ORM.AUTH.MenuItem()
                    {
                        Text   = subItem[str],
                        ViewID = (int)view.ID
                    });

                    new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).SaveView(view);
                }
                ;
                SOWAY.ORM.AUTH.MenuItem AuthMenu = new SOWAY.ORM.AUTH.MenuItem()
                {
                    Text     = "人员及权限",
                    SubItems = new List <SOWAY.ORM.AUTH.MenuItem>()
                };
                foreach (var str in AuthItem.Keys)
                {
                    var view = new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).GetView(str);
                    view.ConnectionType = Model.ConnectionType.AppSys;

                    AuthMenu.SubItems.Add(new SOWAY.ORM.AUTH.MenuItem()
                    {
                        Text   = AuthItem[str],
                        ViewID = (int)view.ID
                    });

                    new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).SaveView(view);
                }
                ;
                new
                Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.MenuItem>(App.SysCon, this.ConFac).Create(item);
                new
                Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.MenuItem>(App.SysCon, this.ConFac).Create(AuthMenu);
                //6 创建角色
                SOWAY.ORM.AUTH.Role role = new SOWAY.ORM.AUTH.Role()
                {
                    RoleName = "应用管理员"
                };
                role.Items = new List <SOWAY.ORM.AUTH.MenuItem>();
                role.Items.Add(item);
                foreach (var sub in item.SubItems)
                {
                    role.Items.Add(sub);
                }
                role.Items.Add(AuthMenu);
                role.Items.AddRange(AuthMenu.SubItems.ToArray());
                role.AuthUsers = new List <SOWAY.ORM.AUTH.AuthorizedUser>();
                role.AuthUsers.Add(user);

                new
                Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.Role>(App.SysCon, this.ConFac).Create(role);

                //7 给用户加入角色
            }
            return(newApp);
        }