Example #1
0
        public void SetAdminStatus(int userId, bool enabled)
        {
            if (userId == CurrentLoginUser.User.Id)
            {
                throw new KMBitException("不能禁用或启用自己的账户");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                Users user = (from u in db.Users where u.Id == userId select u).FirstOrDefault <Users>();

                if (user == null)
                {
                    throw new KMBitException("用户不存在");
                }

                Admin_Users au = (from u in db.Admin_Users where u.User_Id == user.Id select u).FirstOrDefault <Admin_Users>();
                if (au.IsSuperAdmin)
                {
                    if (!CurrentLoginUser.IsWebMaster)
                    {
                        throw new KMBitException("只有网站管理员才能禁用或启用超级管理员账户");
                    }
                }
                else
                {
                    if (!CurrentLoginUser.IsSuperAdmin)
                    {
                        throw new KMBitException("只有超级管理员才能禁用或启用普通管理员账户");
                    }
                }
                user.Enabled = enabled;
                db.SaveChanges();
            }
        }
Example #2
0
        public bool Add(string UserName, string UserPwd, string RoleIds, string RoleNames, int State)
        {
            Admin_Users admin = new Admin_Users();

            admin.Admin_UserName = UserName;
            admin.Admin_UserPwd  = Md5Helper.MD5Encoding(UserPwd, 123);
            admin.CreateDate     = DateTime.Now;
            admin.RoleIds        = RoleIds;
            admin.RoleNames      = RoleNames;
            admin.State          = State;
            var result = iAdmin_Users_BLL.Add(admin);

            return(result > 0);
        }
Example #3
0
        /// <summary>
        /// Gets single user permissions object
        /// </summary>
        /// <param name="userId">User Id of user</param>
        /// <returns>Instance of Permissions object</returns>
        public static Permissions GetUserPermissions(int userId)
        {
            Permissions permissions = new Permissions();

            PropertyInfo[] fields          = permissions.GetType().GetProperties();
            KMBit.DAL.chargebitEntities db = null;
            try
            {
                db = new chargebitEntities();
                Admin_Users au = (from u in db.Admin_Users where u.User_Id == userId select u).FirstOrDefault <Admin_Users>();
                if (au != null && au.IsSuperAdmin)
                {
                    foreach (PropertyInfo f in fields)
                    {
                        f.SetValue(permissions, true);
                    }
                    return(permissions);
                }
                List <Admin_Actions>       actions     = (from a in db.Admin_Actions select a).ToList <Admin_Actions>();
                List <Admin_Users_Actions> userActions = (from ua in db.Admin_Users_Actions where ua.User_Id == userId select ua).ToList <Admin_Users_Actions>();
                if (userActions != null && userActions.Count > 0)
                {
                    foreach (Admin_Users_Actions ua in userActions)
                    {
                        Admin_Actions action = (from a in actions where a.Id == ua.Action_Id select a).FirstOrDefault <Admin_Actions>();
                        if (action != null)
                        {
                            foreach (PropertyInfo f in fields)
                            {
                                if (f.Name == action.Name || au.IsSuperAdmin)
                                {
                                    f.SetValue(permissions, true);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return(permissions);
        }
Example #4
0
        public bool Update(int Id, string UserName, string UserPwd, string RoleIds, string RoleNames, DateTime CreateDate, int State)
        {
            Admin_Users admin = new Admin_Users();

            admin.Admin_UserId   = Id;
            admin.Admin_UserName = UserName;
            admin.Admin_UserPwd  = UserPwd;
            admin.CreateDate     = DateTime.Now;
            admin.RoleIds        = RoleIds;
            admin.RoleNames      = RoleNames;
            admin.State          = State;
            var result = iAdmin_Users_BLL.Update(admin);

            return(result > 0);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="actions"></param>
        /// <returns></returns>
        public bool GrantUserPermissions(int userId, List <Admin_Actions> actions)
        {
            if (!CurrentLoginUser.IsSuperAdmin && !CurrentLoginUser.IsWebMaster)
            {
                if (!CurrentLoginUser.Permission.UPDATE_USER_PERMISSION)
                {
                    throw new KMBitException("没有权限修改管理员权限");
                }
            }

            bool ret = false;

            using (chargebitEntities db = new chargebitEntities())
            {
                Admin_Users au = (from u in db.Admin_Users where u.User_Id == userId select u).FirstOrDefault <Admin_Users>();

                if (au.IsSuperAdmin && !CurrentLoginUser.IsWebMaster)
                {
                    throw new KMBitException("没有权限修改超级管理员权限,只有网站管理员才能修改");
                }

                if (actions != null && actions.Count > 0)
                {
                    db.Database.ExecuteSqlCommand("delete from Admin_Users_Actions where User_Id=" + userId.ToString());
                    foreach (Admin_Actions action in actions)
                    {
                        Admin_Users_Actions uaction = new Admin_Users_Actions()
                        {
                            Action_Id = action.Id, User_Id = userId
                        };
                        db.Admin_Users_Actions.Add(uaction);
                    }
                    db.SaveChanges();
                    ret = true;
                }
            }
            return(ret);
        }
Example #6
0
        public BUser GetUserInfo(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(null);
            }
            BUser user = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                user      = new BUser();
                user.User = (from u in db.Users where u.Email == email select u).FirstOrDefault <Users>();

                Admin_Users au = (from ausr in db.Admin_Users where ausr.User_Id == user.User.Id select ausr).FirstOrDefault <Admin_Users>();
                if (au != null)
                {
                    user.IsSuperAdmin = au.IsSuperAdmin;
                    user.IsWebMaster  = au.IsWebMaster;
                    user.IsAdmin      = true;
                }
                if (!user.IsSuperAdmin)
                {
                    user.Permission = PermissionManagement.GetUserPermissions(user.User.Id);
                }
                else
                {
                    user.Permission = new Permissions();
                    System.Reflection.FieldInfo[] fields = typeof(Permissions).GetFields();
                    foreach (System.Reflection.FieldInfo field in fields)
                    {
                        field.SetValue(user.Permission, 1);
                    }
                }
            }
            return(user);
        }
Example #7
0
        private async Task Messaging(MessageEvent ev)
        {
            if (!(ev.Message is TextEventMessage msg))
            {
                return;
            }

            if (msg.Text.Contains("ルール") && msg.Text.Contains("FAQ"))
            {
                var messages = new ISendMessage[]
                {
                    new FlexMessage("ルール", FlexMessageText.Flex_Rule(), null, sender_admin),
                    new FlexMessage("FAQ", FlexMessageText.Flex_Faq(), null, sender_admin)
                };
                await lineMessagingClient.ReplyMessageAsync(ev.ReplyToken, messages);
            }
            else if (msg.Text.Contains("ルール"))
            {
                var messages = new ISendMessage[]
                {
                    new FlexMessage("ルール", FlexMessageText.Flex_Rule(), null, sender_admin)
                };

                await lineMessagingClient.ReplyMessageAsync(ev.ReplyToken, messages);
            }
            else if (msg.Text.Contains("FAQ"))
            {
                var messages = new ISendMessage[]
                {
                    new FlexMessage("FAQ", FlexMessageText.Flex_Faq(), null, sender_admin)
                };

                await lineMessagingClient.ReplyMessageAsync(ev.ReplyToken, messages);
            }
            else if (msg.Text == "継続確認イベント" && Admin_Users.Contains(ev.Source.UserId))
            {
                var messages = new ISendMessage[]
                {
                    new FlexMessage("継続確認イベント", FlexMessageText.Flex_Check_Continue(), null, sender_admin)
                };
                await lineMessagingClient.ReplyMessageAsync(ev.ReplyToken, messages);
            }
            else if (msg.Text == "継続確認リセット" && Admin_Users.Contains(ev.Source.UserId))
            {
                await database.MemberCheckReset();

                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, "リセットしました", false, null, sender_admin);
            }
            else if (msg.Text == "継続希望メンバー" && Admin_Users.Contains(ev.Source.UserId))
            {
                var member_list = await database.GetMember("SELECT c.newername FROM c Where c.check != null and c.leavedDate = null ORDER BY c.joinedDate");

                string member = "希望済のメンバー";
                foreach (var item in member_list)
                {
                    member += "\n" + item.newername;
                }
                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, member, false, null, sender_admin);
            }
            else if (msg.Text == "継続希望旧メンバー" && Admin_Users.Contains(ev.Source.UserId))
            {
                var member_list = await database.GetMember("SELECT c.name FROM c Where c.check != null and c.leavedDate = null ORDER BY c.joinedDate");

                string member = "希望済のメンバー";
                foreach (var item in member_list)
                {
                    member += "\n" + item.name;
                }
                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, member, false, null, sender_admin);
            }
            else if (msg.Text == "継続未希望メンバー" && Admin_Users.Contains(ev.Source.UserId))
            {
                var member_list = await database.GetMember("SELECT c.newername FROM c Where c.check = null and c.leavedDate = null ORDER BY c.joinedDate");

                string member = "未希望のメンバー";
                foreach (var item in member_list)
                {
                    member += "\n" + item.newername;
                }
                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, member, false, null, sender_admin);
            }
            else if (msg.Text == "継続未希望旧メンバー" && Admin_Users.Contains(ev.Source.UserId))
            {
                var member_list = await database.GetMember("SELECT c.name FROM c Where c.check = null and c.leavedDate = null ORDER BY c.joinedDate");

                string member = "未希望のメンバー";
                foreach (var item in member_list)
                {
                    member += "\n" + item.name;
                }
                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, member, false, null, sender_admin);
            }
            else if (msg.Text.Contains("にゃ") || msg.Text.Contains("ニャ"))
            {
                var rand    = new Random();
                var catword = new string[] { "にゃฅ(。•ㅅ•。ฅ)", "(=゚-゚)ノニャーン♪", "(=´∇`=)にゃん", "ฅ(๑•̀ω•́๑)ฅニャンニャンガオー", "ミャー♪ヽ(∇⌒= )( =⌒∇)ノミャー♪", "=^∇^*= にゃお~ん♪" };
                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, catword[rand.Next(0, catword.Length)], false, null, sender_cat);
            }
            else if (msg.Text == "Google")
            {
                var action = new UriTemplateAction("google", "https://google.com");
                var qr     = new QuickReply()
                {
                    Items = new List <QuickReplyButtonObject>()
                    {
                        new QuickReplyButtonObject(action)
                    }
                };
                await lineMessagingClient.ReplyTextAsync(ev.ReplyToken, "hello", false, qr);
            }
        }
Example #8
0
        public async Task <Users> CreateAdministrator(Users dbUser)
        {
            if (dbUser == null)
            {
                throw new KMBitException("参数不正确");
            }
            if (string.IsNullOrEmpty(dbUser.Email))
            {
                throw new KMBitException("邮箱地址不能为空");
            }
            if (string.IsNullOrEmpty(dbUser.PasswordHash))
            {
                throw new KMBitException("用户密码不能为空");
            }
            if (!CurrentLoginUser.Permission.CREATE_USER)
            {
                throw new KMBitException("没有权限创建用户");
            }

            using (chargebitEntities db = new chargebitEntities())
            {
                Users u = (from usr in db.Users where usr.Email == dbUser.Email select usr).FirstOrDefault <Users>();
                if (u != null)
                {
                    throw new KMBitException("此邮箱已经注册过,不能重复注册");
                }
                ApplicationUserManager manager = new ApplicationUserManager(new ApplicationUserStore(new chargebitEntities()));
                ApplicationUser        appUser = new ApplicationUser();
                appUser.Address           = "";
                appUser.AccessFailedCount = 0;
                appUser.City_id           = 0;
                appUser.CreatedBy         = CurrentLoginUser.User.Id;
                appUser.Credit_amount     = 0;
                appUser.Description       = "";
                appUser.Email             = dbUser.Email;
                appUser.UserName          = dbUser.Email;
                appUser.Name         = dbUser.Name;
                appUser.PasswordHash = dbUser.PasswordHash;
                appUser.Pay_type     = 0;
                appUser.PhoneNumber  = dbUser.PhoneNumber;
                appUser.Province_id  = 0;
                appUser.Regtime      = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                appUser.Enabled      = dbUser.Enabled;
                appUser.Type         = 1;
                appUser.Update_time  = appUser.Regtime;
                appUser.AccessToken  = UrlSignUtil.GetMD5(Guid.NewGuid().ToString());
                var result = await manager.CreateAsync(appUser, dbUser.PasswordHash);

                if (result.Succeeded)
                {
                    u = (from usr in db.Users where usr.Email == dbUser.Email select usr).FirstOrDefault <Users>();

                    Admin_Users au = new Admin_Users()
                    {
                        Description = "管理员", IsSuperAdmin = false, IsWebMaster = false, User_Id = u.Id
                    };
                    db.Admin_Users.Add(au);
                    db.SaveChanges();
                }
                return(u);
            }
        }
Example #9
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>返回受影响行数</returns>
        public int Update(Admin_Users t)
        {
            var result = IAdmin_Users_DAL.Update(t);

            return(result);
        }
Example #10
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>返回受影响行数</returns>
        public int Add(Admin_Users t)
        {
            var result = IAdmin_Users_DAL.Add(t);

            return(result);
        }