public ActionResult Get() { var users = _userService.Get(); if (users.Count == 0) { return(HttpNotFound("No users were found.")); } return(new JsonResult(users)); }
public async Task <IActionResult> Users(UserSearchViewModel data) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var users = await _domainService.Get(data.UserName, data.DisplayName, data.StartDate, data.EndDate, data.Email, data.OrderBy, data.OrderType); var query = from user in users select new UserSearchResultViewModel { UserId = user.UserId, UserName = user.UserName, DisplayName = user.DisplayName, Email = user.Email, CreationDate = user.CreationDate }; return(new OkObjectResult(query.ToList())); } catch { return(BadRequest("Unable to perform the search.")); } }
public UserDTO GetUser(Guid id) { var user = _userDomainService.Get(id); var dto = user.MapTo <UserDTO>(); return(dto); }
public async Task <UserEntity> GetUser(int playerId) { var player = await _playerDomainService.Get(playerId); if (player == null) { return(null); } return(await _userDomainService.Get(player.UserId)); }
public async Task <IActionResult> SignIn([FromBody] SignInViewModel value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var success = await _domainService.Get(value.UserName, value.Password); if (success && config != null) { // retrieve Auth0 api token var client = new RestClient(config.Value.TokenAuthAddress); var request = new RestRequest(Method.POST); var headerContent = $"{{\"client_id\":\"{config.Value.ClientId}\",\"client_secret\":\"{config.Value.ClientSecret}\",\"audience\":\"{config.Value.ApiIdentifier}\",\"grant_type\":\"client_credentials\"}}"; request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", headerContent, ParameterType.RequestBody); IRestResponse response = client.Execute(request); var responseDictionary = new RestSharp.Deserializers.JsonDeserializer().Deserialize <Dictionary <string, string> >(response); return(Ok($"Bearer {responseDictionary["access_token"]}")); } else if (success && config == null) { // a sample token used to allow unit testing in this ActionResult without Auth0 instance return(Ok($"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlJUZEZOekkwTmpORVFUbEJNakk1T")); } else { return(NotFound("Authentication failed!")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
/// <summary> /// 获取当前用户信息 /// </summary> /// <returns></returns> public async Task <CurrentUserOutput> Get() { var user = await _userDomainService.Get(_currentUser.Id.Value); return(user.Adapt <CurrentUserOutput>()); }
public async Task <Unit> Handle(RegCommand command, CancellationToken cancellationToken) { var email = command.Email.Trim().ToLower(); var password = command.Password; var code = command.Code; var user = await _userDomainService.Get(p => p.Email == email && p.HasVerifiedEmail); if (user != null) { await _bus.RaiseEvent(new DomainNotification("邮箱已被注册,请更改!")); return(Unit.Value); } string key = string.Format(RedisKey.RegEmail, email);// $"regemail_{email}"; long ttl = await _redisDb.KeyTimeToLive(key); if (ttl < 0) { await _bus.RaiseEvent(new DomainNotification($"注册验证码已超时,请重试")); return(Unit.Value); } string emailCode = await _redisDb.StringGet <string>(key); if (string.Compare(emailCode, code, true) != 0) { await _bus.RaiseEvent(new DomainNotification($"注册验证码已失效,请重试")); return(Unit.Value); } string ip = _httpAccessor.HttpContext.GetUserIp(); user = new UserEntity { Email = email, LastDate = DateTime.Now, Password = password.ToMd5(), Status = UserStatusEnum.正常, RegDate = DateTime.Now, UserName = "", RegIp = ip, LastIp = ip, HasVerifiedEmail = true }; await _userDomainService.Add(user); var jwtAccount = new JwtAccount { UserId = user.Id, Email = user.Email }; await _httpAccessor.HttpContext.SignIn("user", jwtAccount); await _redisDb.KeyDelete(key); if (await Commit()) { await _bus.RaiseEvent(new SignUpEvent(user)).ConfigureAwait(false); } return(Unit.Value); }
public async Task <UserEntity> Get(int id) { return(await _userDomainService.Get(id)); }
/// <summary> /// 获取用户 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <UserDetailOutput> Get(long id) { var user = await _userDomainService.Get(id); return(user.Adapt <UserDetailOutput>()); }