public async Task <JObject> Login(UserSignDTO userSignDTO) { JObject responseJson = null; try { responseJson = await _authenticationService.AcquireAccessToken (_serverAddresses.Addresses.FirstOrDefault(), userSignDTO.Telephone, userSignDTO.Password); } catch (Exception ex) { this._logger.LogError("An exception occured,the exception message:" + ex.Message); } return(responseJson); }
public async Task <bool> Register(UserSignDTO userSignDTO) { TSysUsers users = new TSysUsers(); _mapper.Map(userSignDTO, users); users.UserId = Guid.NewGuid(); //TSysUsers sysUsers = new TSysUsers() //{ // UserId = Guid.NewGuid(), // CreateDate = DateTime.Now, // Telephone = userSignDTO.Telephone, // Password = userSignDTO.Password //}; await _context.TSysUsers.AddAsync(users); bool flag = _context.SaveChanges() > 0; return(flag); }
public async Task <IActionResult> Login(UserSignDTO userSignDTO) { if (ModelState.IsValid) { JObject datasJson = await _userServices.Login(userSignDTO); if (datasJson["error"] is null) { AuthorizationDTO authorization = JsonHelper.Deserialize <AuthorizationDTO>(datasJson.ToString()); UserClaimDTO userClaim = await _authenticationService.AcquireUserClaim(_serverAddresses.Addresses.FirstOrDefault(), authorization.access_token); if (authorization is null || userClaim is null) { return(StatusCode(500)); } var loginStatus = _mapper.Map <LoginStatusDTO>(userSignDTO); _mapper.Map(userClaim, loginStatus); _mapper.Map <AuthorizationDTO, LoginStatusDTO>(authorization, loginStatus); return(Ok(new ResponseCtrMsg <LoginStatusDTO>(CtrResult.Success) { ResultObj = loginStatus })); } else { this._logger.LogInformation("User:"******",Login Control failed"); return(BadRequest("账号密码错误")); } } else { this._logger.LogInformation("The passed in model is empty"); return(BadRequest(new ResponseCtrMsg <object>(CtrResult.Failure) { message = "传入的模型为空" })); } }
public async Task <IActionResult> Register(UserSignDTO userSignDTO) { if (ModelState.IsValid) { try { bool responseMsg = await _userServices.Register(userSignDTO); if (responseMsg) { return(Ok(new ResponseCtrMsg <object>(CtrResult.Success) { })); } return(BadRequest(null)); } catch (Exception ex) { this._logger.LogInformation("An exception has occurred,the exception message:" + ex.Message); return(BadRequest(new ResponseCtrMsg <object>(CtrResult.Exception) { ErrorObj = new Error() { ErrorMessage = ex.Message } })); } } else { return(BadRequest(new ResponseCtrMsg <object>(CtrResult.Failure) { message = "传入的模型为空" })); } }