Пример #1
0
        public void CreateUser(UserCreateInput input)
        {
            Logger.Info(" 新建用户,新建内容: " + input);
            var user = input.MapTo <User>();

            _userRepository.Insert(user);
        }
Пример #2
0
        public static bool UserCreate(string username, string pass, ref int userid)
        {
            var input = new UserCreateInput()
            {
                UserName = username,
                UserPass = pass,
            };
            var json = JsonConvert.SerializeObject(input);

            string output = null;

            try
            {
                output = HttpReader.HttpPost(ApiDef.UserCreate, json);
            }
            catch (AggregateException)
            {
                return(false);
            }

            var result    = JsonConvert.DeserializeObject <UserCreateOutput>(output);
            var issuccess = ResultStatus.IsSuccess(result.ResultStatus);

            if (issuccess)
            {
                userid = result.UserId;
            }
            return(issuccess);
        }
Пример #3
0
        public ResultMessage <UserCreateOutput> Create(UserCreateInput input)
        {
            var result = _accountAppService.Create(input);

            if (result.IsSuccess)
            {
                return(ResponseUtils.DataResult(result));
            }
            return(ResponseUtils.ErrorResult <UserCreateOutput>(result.Msg));
        }
Пример #4
0
        public ActionResult Create(UserCreateInput userCreateInput)
        {
            if (ModelState.IsValid)
            {
                _userService.CreateUser(userCreateInput);
                ViewBag.Success = string.Empty;
            }
            ViewBag.DepartmentId = new SelectList(_departmentService.GetAll(), "Id", "DepartmentName");

            return(View());
        }
Пример #5
0
        public static int CreateUser(string username, string pass)
        {
            var usercreateinput = new UserCreateInput()
            {
                UserName = username,
                UserPass = pass,
            };
            var output           = usermodule.OnUserCreate(JsonConvert.SerializeObject(usercreateinput));
            var usercreateoutput = JsonConvert.DeserializeObject <UserCreateOutput>(output);

            return(usercreateoutput.UserId);
        }
Пример #6
0
        public async Task <IActionResult> Register(UserCreateInput userCreateInput)
        {
            var commandResult = await _mediator.Send(new EditUserRegisterCommand { UserCreateInput = userCreateInput });

            if (!commandResult.Success)
            {
                return(BadRequest(commandResult.Message));
            }

            var user = await _mediator.Send(new UserDetailsQuery { Id = commandResult.ObjectId });

            return(CreatedAtRoute("GetUser", new { controller = "Users", id = user.Id }, user));
        }
Пример #7
0
        public async Task <IActionResult> CreateUser([FromBody] UserCreateInput input)
        {
            if (dbContext.Users.Count(u => u.Name == input.Name) > 0)
            {
                return(BadRequest(Json(new { Error = "用户名已存在" })));
            }
            if (await dbContext.Orgnazitions.CountAsync(o => o.Id == input.OrganazitionId) == 0)
            {
                return(BadRequest(Json(new { Error = "不存在该部门" })));
            }
            if (await dbContext.Roles.CountAsync(r => r.Id == input.RoleId) == 0)
            {
                return(BadRequest(Json(new { Error = "不存在该角色" })));
            }

            var user = mapper.Map <User>(input);

            dbContext.Users.Add(user);
            await dbContext.SaveChangesAsync();

            return(CreatedAtRoute("GetUser", new { id = user.Id }, mapper.Map <UserOutput>(user)));
        }
Пример #8
0
        public UserCreateOutput Create(UserCreateInput input)
        {
            #region 入参确认

            if (string.IsNullOrEmpty(input.AccountName))
            {
                return(new UserCreateOutput()
                {
                    IsSuccess = false,
                    Msg = "账号不能为空",
                });
            }
            if (string.IsNullOrEmpty(input.Password))
            {
                return(new UserCreateOutput()
                {
                    IsSuccess = false,
                    Msg = "密码不能为空"
                });
            }
            if (!input.Password.Equals(input.RepeatPassword))
            {
                return(new UserCreateOutput()
                {
                    IsSuccess = false,
                    Msg = "密码不一致,请确认您的密码"
                });
            }

            #endregion

            var regiserType = AppUtils.UserAccountType(input.AccountName);

            User user = null;
            switch (regiserType)
            {
            case UserRegistType.UserName:
                user = new User()
                {
                    UserName       = input.AccountName,
                    UserRegistType = regiserType,
                };
                break;

            case UserRegistType.Phone:
                user = new User()
                {
                    Phone          = input.AccountName,
                    UserRegistType = regiserType,
                };
                break;

            case UserRegistType.Email:
                user = new User()
                {
                    Email          = input.AccountName,
                    UserRegistType = regiserType
                };
                break;

            default:
                return(new UserCreateOutput()
                {
                    IsSuccess = false,
                    Msg = "您输入的账号不合法,请输入正确的用户名(以'字母'或'_'开头,3~16位字母与数字组合)|手机|Email",
                });
            }
            user.Password = AppUtils.EncryptPassword(input.AccountName, input.Password, regiserType);
            try
            {
                var result = _accountService.Add(user);
                if (result.IsValid)
                {
                    return(new UserCreateOutput()
                    {
                        IsSuccess = true,
                        Msg = "注册成功",
                        AccountName = input.AccountName
                    });
                }
                return(new UserCreateOutput()
                {
                    IsSuccess = false,
                    Msg = "注册失败,原因:" + result.Errors.Select(p => p.Message),
                    AccountName = input.AccountName
                });
            }
            catch (Exception ex)
            {
                return(new UserCreateOutput()
                {
                    IsSuccess = false,
                    Msg = "注册失败,原因:" + ex.Message,
                });
            }
        }