public async Task <ActionResult> CreateItemAsync([FromBody] UserInfoDTO userInfo, CancellationToken cancellationToken) { var newItem = _mapper.Map <UserInfo>(userInfo); newItem = await _userInfoService.AddAsync(newItem, cancellationToken); if (newItem == null) { AssignToModelState(_userInfoService.Errors); return(ValidationProblem()); } return(CreatedAtAction(nameof(ItemByIdAsync), new { id = newItem.UserName }, null)); }
public ActionResult Register(string Email, string Password, string SiteName) { if (ModelState.IsValid) { service.AddAsync(new UserInfo() { Email = Email, Password = Password, SiteName = SiteName }); return(Content("ok")); } else { throw new Exception("发生异常"); } }
public async Task <ResultMessage> AddAsync(User_Info userInfo) { //var user = await busines.GetUser(model.Account, model.Password); var user = await business.GetUser(userInfo.Account); if (null != user) { return(new ResultMessage() { Status = "0", Message = "用户名已存在" }); } userInfo.Password = SecretHelper.Md532(userInfo.Password); return(new ResultMessage() { Status = await business.AddAsync(userInfo) ? "1" : "0" }); }
public async Task <ActionResult <ApiResult <UserInfo> > > Login([FromQuery] string code, [FromServices] IUserInfoService service) { var res = await WeixinHelper.GetLoginInfoAsync(code); var json = JObject.Parse(res); var result = new ApiResult <UserInfo>(); var openId = json["openid"].Value <string>(); var user = await service.GetUserByOpenIdAsync(openId); if (user == null) { // 用户第一次登陆 user = new UserInfo { OpenId = openId }; await service.AddAsync(user); } result.Result = user; result.Message = "requst:ok"; return(result); }