Esempio n. 1
0
 private static void Test_User()
 {
     var model = new User
     {
         Username          = "******",
         IsFirstTimeLogin  = true,
         AccessFailedCount = 1,
         CreationDate      = DateTime.Now,
         IsActive          = true
     };
     var userDao    = new UserDao();
     var isOkDelete = userDao.DeleteById(2);
     var userId     = userDao.Add(model);
     var isOkUpdate = userDao.UpdateById(new User()
     {
         Username = "******"
     }, userId);
     var model01 = userDao.FindById(userId);
     var model02 = userDao.FindList(new User()
     {
         UserId = userId
     }, " userId=@userid", 1);
     var model03 = userDao.FindListByPage(new User()
     {
         UserId = userId
     }, " userId=@userid", " userId", 0, 10);
     var count = userDao.Count(new User()
     {
         Username = "******"
     }, " Username=@Username");
 }
Esempio n. 2
0
        //Тут сама разберись, чо да как, откуда ты берешь строку пароля
        // Guid password = EncoderGuid.PasswordToGuid.Get(model.Password);

        public void AddUser(string nickname, string password, string email)
        {
            //переводим строку в байт-массим
            byte[] bytes = Encoding.Unicode.GetBytes(password);

            //создаем объект для получения средст шифрования
            MD5CryptoServiceProvider CSP =
                new MD5CryptoServiceProvider();

            //вычисляем хеш-представление в байтах
            byte[] byteHash = CSP.ComputeHash(bytes);

            string hash = string.Empty;

            //формируем одну цельную строку из массива
            foreach (byte b in byteHash)
            {
                hash += string.Format("{0:x2}", b);
            }

            Guid pass = new Guid(hash);

            User user = new User()
            {
                Nickname = nickname,
                Password = pass,
                Email    = email,
                RegDate  = DateTime.Now
            };

            udao.Add(user);
        }
Esempio n. 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!validateInput())
            {
                return;
            }

            btnSaveEnbaled(false);

            if (opration == OP_ADD)
            {
                HRUser vo = InputToVo(null);

                int ret = dao.Add(vo);
                if (ret > 0)
                {
                    listSource.Add(vo);
                }
            }
            else if (opration == OP_UPDATE)
            {
                HRUser vo = list[grid.CurrentRow.Index];
                vo = InputToVo(vo);
                dao.Update(vo);
                grid.Refresh();
            }

            CleanData();
        }
Esempio n. 4
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
            TextInfo    textInfo    = cultureInfo.TextInfo;

            try
            {
                var user = new utilisteur
                {
                    nom      = txtNom.Text.ToUpper(),
                    prenom   = textInfo.ToTitleCase(txtPrenom.Text),
                    tel      = txtTel.Text,
                    password = txtPw.Text,
                    role     = comboRole.Text,
                };

                userDao.Add(user);
                toast.ShowNotification(toastID[4]);
                GetAll();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, ex.Message);
            }
        }
Esempio n. 5
0
        public ActionResult Register(Register model)
        {
            if (ModelState.IsValid)
            {
                var dao      = new UserDao();
                var UserName = dao.GetByUserName(model.UserName);
                var Email    = dao.GetByEmail(model.Email);

                if (UserName != null)
                {
                    ModelState.AddModelError("", "Tài khoản đã được sử dụng");
                }
                else if (Email != null)
                {
                    ModelState.AddModelError("", "Email đã được sử dụng");
                }
                else
                {
                    var user = new User();
                    user.Username   = model.UserName;
                    user.Password   = Encryption.MD5Hash(model.PassWord);
                    user.SDT        = model.Phone;
                    user.Email      = model.Email;
                    user.Fullname   = model.Name;
                    user.Datetime   = DateTime.Now;
                    user.Permission = false;
                    user.Status     = true;
                    dao.Add(user);

                    return(RedirectToAction("Index", "Login"));
                }
            }
            return(View("Index"));
        }
Esempio n. 6
0
        public ActionResult Add(Register model)
        {
            if (ModelState.IsValid)
            {
                var dao      = new UserDao();
                var UserName = dao.GetByUserName(model.UserName);
                var Email    = dao.GetByEmail(model.Email);

                if (UserName != null)
                {
                    return(Json(new { isok = false, message = "Tài khoản đã được sử dụng" }));
                }
                else if (Email != null)
                {
                    return(Json(new { isok = false, message = "Email đã được sử dụng" }));
                }
                else
                {
                    var user = new User();
                    user.Username   = model.UserName;
                    user.Password   = Encryption.MD5Hash(model.PassWord);
                    user.SDT        = model.Phone;
                    user.Email      = model.Email;
                    user.Fullname   = model.Name;
                    user.Datetime   = DateTime.Now;
                    user.Permission = false;
                    user.Status     = true;
                    dao.Add(user);

                    return(Json(new { isok = true, message = "Thêm thành công!" }));
                }
            }
            return(Json(new { isok = false, message = "Thêm thất bại !" }));;
        }
Esempio n. 7
0
        public string Add(FullUserInfo user)
        {
            var     mapper      = Common.GetMapper();
            UserDao userDao     = new UserDao(mapper);
            var     repeateUser = userDao.Query(new UserQueryForm {
                Name = user.Name
            }).FirstOrDefault();

            if (repeateUser != null)
            {
                throw new XinLuClubException(402, "用户名已存在");
            }
            var result = userDao.Add(user);

            if (user.Boards != null)
            {
                User_BoardGroupDao ubdao = new User_BoardGroupDao(mapper);
                user.Boards.ForEach(t =>
                {
                    User_BoardGroup ub = new User_BoardGroup
                    {
                        UserID       = result.ID,
                        BoardGroupID = t.ID,
                    };
                    ubdao.Add(ub);
                });
            }

            return(result.ID);
        }
Esempio n. 8
0
        private void AddOrUpdateUser(User user, bool isUpdate = false, bool generatePassword = true)
        {
            string messagePart = "";

            if (generatePassword)
            {
                user.PasswordHash = GenerateRandomNumber();
                messagePart       = string.Format("Kullanıcı Kodunuz: {0}\nŞifreniz: {1}\n\n", user.UserName, user.PasswordHash);
                HashPassword(user, user.PasswordHash);
            }

            if (isUpdate)
            {
                UserDao.Update(user);
            }
            else
            {
                UserDao.Add(user);
            }

            if (generatePassword)
            {
                //send an e-mail to the user to inform a new password generated and available to enter to the system
                try
                {
                    EmailLogic.MessageTemplate = string.Format(ConfigurationManager.AppSettings.Get("PasswordNotificationTemplate").ToString(), DateTime.Now, "{0}");
                    EmailLogic.SendNewPasswordNotification(user.Email, messagePart);
                }
                catch (Exception ex)
                {
                    mLogger.Error(ex.ToString());
                }
            }
        }
Esempio n. 9
0
 public void Add(ref User user)
 {
     //using (var scope = new TransactionScope())
     //{
     UserDao.Add(ref user);
     //    scope.Complete();
     //}
 }
Esempio n. 10
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Add(User user)
        {
            //添加用户时也做加密处理
            user.Pwd = EncryptHelper.MD5Encrypt(user.Pwd);
            int res = UserDao.Add(user);

            return(res > 0);
        }
Esempio n. 11
0
        public IActionResult Post(User user)
        {
            var dao = new UserDao(Context);

            dao.Add(user);
            Context.SaveChanges();
            return(Ok());
        }
Esempio n. 12
0
 public bool Add([FromBody] User user)
 {
     try
     {
         return(_userDao.Add(user));
     }
     catch (Exception ex)
     {
         nlog.Error(ex, "添加用户失败!", user.ToJSON());
         return(false);
     }
 }
Esempio n. 13
0
        public void AddUser()
        {
            var user = new User()
            {
                Name     = "test",
                Password = "******",
                Email    = "*****@*****.**"
            };

            var result = UserDao.Add(user);

            Assert.AreEqual(1, result);
        }
Esempio n. 14
0
        public void AddTest()
        {
            var obj  = new UserDao();
            var user = new User()
            {
                Id        = 2,
                Account   = "yogi",
                Name      = "yogi",
                Propesion = "Programmer",
                Phone     = "081299038999",
                Email     = "*****@*****.**"
            };

            var res = obj.Add(user);

            Assert.AreEqual(true, res);
        }
Esempio n. 15
0
        public void Init()
        {
            string id = Guid.NewGuid().ToString().Replace("-", "");

            dao.Delete(new UserQueryForm {
                ID = id
            });
            initU = new User
            {
                ID         = id,
                Name       = "unittestuser",
                Password   = "******",
                CreateTime = DateTime.Now,
                Enabled    = 1,
            };
            dao.Add(initU);
        }
Esempio n. 16
0
 public ActionResult Index(Admin_Model model)
 {
     if (ModelState.IsValid)
     {
         var  dao   = new UserDao();
         bool check = dao.Check_exist(model.user_name, model.password);
         if (check) // Account is exist
         {
             return(RedirectToAction("Error", "Admin_"));
         }
         else
         {
             dao.Add(model.user_name, model.password);
             SetAlert("Số di động hoặc email bạn nhập không khớp với bất kì tài khoản nào", "danger");
             //ModelState.AddModelError("", "Số di động hoặc email bạn nhập không khớp với bất kì tài khoản nào ");
         }
     }
     return(View("Index"));
 }
Esempio n. 17
0
        public string Add(User user, UserInfo ui, List<Role> roles)
        {
            ISqlMapper mapper = MapperHelper.GetMapper();
            UserDao dao = new UserDao(mapper);
            UserInfoDao uidao = new UserInfoDao(mapper);
            User_RoleDao urdao = new User_RoleDao(mapper);

            string id = dao.Add(user);
            if (ui != null)
            {
                ui.ID = id;
                uidao.Add(ui);
            }
            if (roles != null)
            {
                foreach (var role in roles)
                {
                    urdao.Add(new User_Role { UserID = id, RoleID = role.ID });
                }
            }
            return id;
        }
Esempio n. 18
0
        public ValidationResult Add(UserViewModel model)
        {
            DAL.Models.User user = new DAL.Models.User();
            user = new DAL.Models.User
            {
                Username = model.Username,
                Email    = model.Email,
                Password = model.Password,
                UserType = (DAL.Enums.UserType)model.UserType
            };
            model.UserId = user.Id;

            var validation = ValidateUser(user);

            if (validation == ValidationResult.Success)
            {
                if (!userDao.Add(user))
                {
                    return(new ValidationResult("Não foi possível inserir o usuário. Contate o administrador."));
                }
            }

            return(validation);
        }
Esempio n. 19
0
 internal void Add(User user)
 {
     _userDao.Add(user);
 }
Esempio n. 20
0
 public void add(User user)
 {
     _userDao.Add(user);
 }
Esempio n. 21
0
 public bool SaveUser(User user, ref string msg)
 {
     return(UserDao.Add(user, ref msg));
 }
Esempio n. 22
0
        public string Add(Model.User user, UserInfo ui, List <string> roleidlist)
        {
            #region risk user
            ISqlMapper mapper = Common.GetMapperFromSession();
            if (user == null)
            {
                throw new Exception("user不能为null!");
            }
            UserDao dao   = new UserDao(mapper);
            var     exist = dao.Query(new UserQueryForm {
                Name = user.Name
            });
            if (exist.Count > 0)
            {
                throw new Exception("已存在用户名:" + user.Name);
            }
            if (string.IsNullOrEmpty(ui.WX) && string.IsNullOrEmpty(ui.Mobile))
            {
                throw new Exception("微信号或者手机不能为空");
            }
            string id = dao.Add(user);
            if (ui == null)
            {
                ui = new UserInfo();
            }
            UserInfoDao infodao = new UserInfoDao(mapper);
            ui.ID = id;
            infodao.Add(ui);
            if (roleidlist == null)
            {
                return(id);
            }
            User_RoleDao urdao = new User_RoleDao(mapper);
            foreach (var role in roleidlist)
            {
                User_Role ur = new User_Role {
                    RoleID = role, UserID = user.ID
                };
                urdao.Add(ur);
            }
            #endregion

            #region weixin user
            RoleDao roledao = new RoleDao(mapper);
            var     roles   = roledao.Query(new RoleQueryForm {
                IDs = roleidlist
            });
            var weixinids = (from r in roles
                             where !string.IsNullOrEmpty(r.WeiXinID)
                             select Convert.ToInt32(r.WeiXinID)).ToArray();
            try
            {
                SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User
                {
                    department = weixinids,
                    enable     = 1,
                    mobile     = ui.Mobile,
                    name       = ui.CnName,
                    weixinid   = ui.WX,
                    userid     = user.Name,
                });
            }
            catch (SOAFramework.Library.WeiXin.WeiXinException ex)
            {
                switch (ex.Code)
                {
                case "60004":
                case "60003":
                    foreach (var role in roles)
                    {
                        //部门不存在就新建部门
                        Role parentrole = null;
                        if (!string.IsNullOrEmpty(role.ParentID))
                        {
                            roledao.Query(new RoleQueryForm {
                                ID = role.ParentID
                            }).FirstOrDefault();
                        }
                        var department = new SOAFramework.Library.WeiXin.Department
                        {
                            name = role.Name,
                        };
                        if (parentrole != null)
                        {
                            department.parentid = parentrole.WeiXinID;
                        }
                        var response = SOAFramework.Library.WeiXin.WeiXinApi.Department.Create(department);
                        roledao.Update(new RoleUpdateForm
                        {
                            Entity = new Role {
                                WeiXinID = response.id
                            },
                            RoleQueryForm = new RoleQueryForm {
                                ID = role.ID
                            },
                        });
                    }
                    SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User
                    {
                        department = weixinids,
                        enable     = 1,
                        mobile     = ui.Mobile,
                        name       = ui.CnName,
                        weixinid   = ui.WX,
                        userid     = user.Name,
                    });
                    break;

                case "60102":    //用户已存在
                    SOAFramework.Library.WeiXin.WeiXinApi.User.Update(new SOAFramework.Library.WeiXin.User
                    {
                        department = weixinids,
                        mobile     = ui.Mobile,
                        name       = ui.CnName,
                        weixinid   = ui.WX,
                        userid     = user.Name,
                    });
                    break;

                default:
                    throw ex;
                }
            }
            #endregion
            return(id);
        }
Esempio n. 23
0
        public string Add(Model.User user, UserInfo ui, List<string> roleidlist)
        {
            #region risk user
            ISqlMapper mapper = Common.GetMapperFromSession();
            if (user == null)
            {
                throw new Exception("user不能为null!");
            }
            UserDao dao = new UserDao(mapper);
            var exist = dao.Query(new UserQueryForm { Name = user.Name });
            if (exist.Count > 0) throw new Exception("已存在用户名:" + user.Name);
            if (string.IsNullOrEmpty(ui.WX) && string.IsNullOrEmpty(ui.Mobile)) throw new Exception("微信号或者手机不能为空");
            string id = dao.Add(user);
            if (ui == null)
            {
                ui = new UserInfo();
            }
            UserInfoDao infodao = new UserInfoDao(mapper);
            ui.ID = id;
            infodao.Add(ui);
            if (roleidlist == null) return id;
            User_RoleDao urdao = new User_RoleDao(mapper);
            foreach (var role in roleidlist)
            {
                User_Role ur = new User_Role { RoleID = role, UserID = user.ID };
                urdao.Add(ur);
            }
            #endregion

            #region weixin user
            RoleDao roledao = new RoleDao(mapper);
            var roles = roledao.Query(new RoleQueryForm { IDs = roleidlist });
            var weixinids = (from r in roles
                             where !string.IsNullOrEmpty(r.WeiXinID)
                             select Convert.ToInt32(r.WeiXinID)).ToArray();
            try
            {
                SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User
                {
                    department = weixinids,
                    enable = 1,
                    mobile = ui.Mobile,
                    name = ui.CnName,
                    weixinid = ui.WX,
                    userid = user.Name,
                });
            }
            catch (SOAFramework.Library.WeiXin.WeiXinException ex)
            {
                switch (ex.Code)
                {
                    case "60004":
                    case "60003":
                        foreach (var role in roles)
                        {
                            //部门不存在就新建部门
                            Role parentrole = null;
                            if (!string.IsNullOrEmpty(role.ParentID)) roledao.Query(new RoleQueryForm { ID = role.ParentID }).FirstOrDefault();
                            var department = new SOAFramework.Library.WeiXin.Department
                            {
                                name = role.Name,
                            };
                            if (parentrole != null) department.parentid = parentrole.WeiXinID;
                            var response = SOAFramework.Library.WeiXin.WeiXinApi.Department.Create(department);
                            roledao.Update(new RoleUpdateForm
                            {
                                Entity = new Role { WeiXinID = response.id },
                                RoleQueryForm = new RoleQueryForm { ID = role.ID },
                            });
                        }
                        SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User
                        {
                            department = weixinids,
                            enable = 1,
                            mobile = ui.Mobile,
                            name = ui.CnName,
                            weixinid = ui.WX,
                            userid = user.Name,
                        });
                        break;
                    case "60102"://用户已存在
                        SOAFramework.Library.WeiXin.WeiXinApi.User.Update(new SOAFramework.Library.WeiXin.User
                        {
                            department = weixinids,
                            mobile = ui.Mobile,
                            name = ui.CnName,
                            weixinid = ui.WX,
                            userid = user.Name,
                        });
                        break;
                    default:
                        throw ex;
                }
            }
            #endregion
            return id;
        }