Ejemplo n.º 1
0
        public void IntegrationTest_ExpectedParameters_Ok()
        {
            UserDataAccess    userDA = new UserDataAccess();
            UserBusinessLogic userBL = new UserBusinessLogic(userDA);
            User user1 = Utils.CreateUserForTest();
            User user2 = Utils.CreateUserForTest();

            userBL.AddUser(user1);
            userBL.AddUser(user2);

            user2.Name = "Other name";
            userBL.ModifyUser(user2);

            userBL.DeleteUser(user1.Username);

            User         user2Obtained = userBL.GetUser(user2.Username);
            IList <User> usersObtained = userBL.GetUsers();

            Assert.IsTrue(!usersObtained.Contains(user1) && usersObtained.Contains(user2Obtained));
        }
 public IHttpActionResult Post([FromBody] UserModel userModel)
 {
     try
     {
         Utils.IsAValidToken(Request, AuthorizationBusinessLogic);
         Utils.HasAdminPermissions(Request, AuthorizationBusinessLogic);
         UserBusinessLogic.AddUser(userModel.ToEntity());
         return(Ok("User added"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Users user = new Users();

            user.UserID   = Guid.NewGuid().ToString();
            user.UserName = txbUserName.Text.Trim();
            byte[] password = Encoding.Default.GetBytes(this.txbpassword.Text.Trim());
            MD5    md5      = new MD5CryptoServiceProvider();

            byte[] output = md5.ComputeHash(password);
            user.Password = BitConverter.ToString(output).Replace("-", "");
            user.RealName = txbRealName.Text.Trim();
            user.Sex      = cbxSex.SelectedItem.ToString();
            //DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
            //dtFormat.ShortDatePattern = "yyyy/MM/dd";
            //user.Birthday = Convert.ToDateTime(dtpBirthday.Text,dtFormat);
            user.Birthday  = Convert.ToDateTime(dtpBirthday.Text);
            user.Mobile    = txbMobile.Text.Trim();
            user.Remark    = txbMemo.Text.Trim();
            user.InputDate = DateTime.Now;
            UserBusinessLogic userBusinessLogic = new UserBusinessLogic();

            try
            {
                if (userBusinessLogic.AddUser(user))
                {
                    MessageBox.Show("添加成功!");
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("添加失败!");
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 4
0
        public ActionResult Register(UserRegisterModel userRegister)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            List <string> msgList    = new List <string>();
            string        verifyCode = Session["ValidateCode"] as string;

            if (userRegister.VerifyCode != verifyCode)
            {
                msgList.Add("验证码输入错误");
            }

            if (!Utility.IsEmail(userRegister.Email))
            {
                msgList.Add("Email输入错误");
            }

            var userinfo = userBusinessLogic.GetUserInfoByUserName(userRegister.UserName);

            if (userinfo != null)
            {
                msgList.Add("用户名已存在");
            }

            userinfo = userBusinessLogic.GetUserInfoByEmail(userRegister.Email);
            if (userinfo != null)
            {
                msgList.Add("Email已存在");
            }

            if (msgList.Count > 0)
            {
                ViewBag.MsgList = msgList;
                return(View());
            }
            T_User userDomain = new T_User()
            {
                UserName     = Sanitizer.GetSafeHtmlFragment(userRegister.UserName),
                Email        = Sanitizer.GetSafeHtmlFragment(userRegister.Email),
                LastLogin    = DateTime.Now,
                NikeName     = "",
                Password     = Md5.GetMd5(userRegister.Password),
                Photo        = "",
                RegisterDate = DateTime.Now,
                IsAdmin      = 0,
                State        = 1
            };
            int userId = userBusinessLogic.AddUser(userDomain);

            if (userId > 0)
            {
                // 发送注册成功提醒邮件
                NoticeMail.SendWelcomeMail(userDomain.UserName, userDomain.Email);
                msgList.Add("注册成功!");
                ViewBag.MsgList = msgList;
                //return RedirectToAction("Profile", "User", null);
            }
            //Response.Write("<script>alert('注册成功,请登录!');</script>");

            return(View());
        }