コード例 #1
0
        async private void GetBackPassword()
        {
            var username   = this.tb_username.Text.Trim();
            var password   = this.tb_pwd.Text.Trim();
            var confirmPwd = this.tb_repwd.Text.Trim();

            if (string.IsNullOrEmpty(username))
            {
                MessageBox.Show("用户名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(password))
            {
                MessageBox.Show("密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(confirmPwd))
            {
                MessageBox.Show("确认密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var dt = (await serviceClient.GetUserInfoAsync(username)).Tables[0];

            if (dt.Rows.Count < 1)
            {
                MessageBox.Show("用户名不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (password != confirmPwd)
            {
                MessageBox.Show("两次密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            var userID = await serviceClient.GetUserIDAsync(username);

            var res = await serviceClient.ModifyUserPasswordAsync(userID, username, confirmPwd);

            if (res == 1)
            {
                MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #2
0
        async private void CommitUserModify()
        {
            var username   = this.tb_user.Text.Trim();
            var oldPwd     = this.tb_oldPwd.Text.Trim();
            var newPwd     = this.tb_newPwd.Text.Trim();
            var confirmPwd = this.tb_confirmPwd.Text.Trim();

            if (string.IsNullOrEmpty(username))
            {
                MessageBox.Show("用户名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(oldPwd))
            {
                MessageBox.Show("旧密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(newPwd))
            {
                MessageBox.Show("新密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(confirmPwd))
            {
                MessageBox.Show("确认密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var dt = (await serviceClient.GetUserInfoAsync(username)).Tables[0];

            if (dt.Rows.Count > 0)
            {
                //用户已存在
                //用户不能是已经存在的其他用户名
                if (username != userName)
                {
                    MessageBox.Show("该用户名已存在,请重新输入用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            //验证旧密码
            MesService.LoginResult loginResult = await serviceClient.LoginAsync(userName, oldPwd);

            if (loginResult != MesService.LoginResult.SUCCESS)
            {
                MessageBox.Show("旧密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (newPwd != confirmPwd)
            {
                MessageBox.Show("新密码与确认密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var res = await serviceClient.ModifyUserPasswordAsync(userID, username, confirmPwd);

            if (res == 1)
            {
                MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }